mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] add posibility to move only not reserved quantity
This commit is contained in:
@@ -6,10 +6,7 @@
|
||||
{
|
||||
"name": "Move Stock Location",
|
||||
"version": "14.0.1.0.1",
|
||||
"author": "Julius Network Solutions, "
|
||||
"BCIM,"
|
||||
"Camptocamp,"
|
||||
"Odoo Community Association (OCA)",
|
||||
"author": "Julius Network Solutions, BCIM, Camptocamp, Odoo Community Association (OCA)",
|
||||
"summary": "This module allows to move all stock "
|
||||
"in a stock location to an other one.",
|
||||
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
# Copyright 2019 Sergio Teruel - Tecnativa <sergio.teruel@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||
|
||||
from itertools import groupby
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.fields import first
|
||||
|
||||
@@ -82,26 +84,60 @@ class StockMoveLocationWizard(models.TransientModel):
|
||||
quants = self.env["stock.quant"].browse(
|
||||
self.env.context.get("active_ids", False)
|
||||
)
|
||||
res["stock_move_location_line_ids"] = [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"product_id": quant.product_id.id,
|
||||
"move_quantity": quant.quantity,
|
||||
"max_quantity": quant.quantity,
|
||||
"reserved_quantity": quant.reserved_quantity,
|
||||
"origin_location_id": quant.location_id.id,
|
||||
"lot_id": quant.lot_id.id,
|
||||
"product_uom_id": quant.product_uom_id.id,
|
||||
"custom": False,
|
||||
},
|
||||
)
|
||||
for quant in quants
|
||||
]
|
||||
res["stock_move_location_line_ids"] = self._prepare_wizard_move_lines(quants)
|
||||
res["origin_location_id"] = first(quants).location_id.id
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def _prepare_wizard_move_lines(self, quants):
|
||||
res = []
|
||||
exclude_reserved_qty = self.env.context.get("only_reserved_qty", False)
|
||||
if not exclude_reserved_qty:
|
||||
res = [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"product_id": quant.product_id.id,
|
||||
"move_quantity": quant.quantity,
|
||||
"max_quantity": quant.quantity,
|
||||
"reserved_quantity": quant.reserved_quantity,
|
||||
"origin_location_id": quant.location_id.id,
|
||||
"lot_id": quant.lot_id.id,
|
||||
"product_uom_id": quant.product_uom_id.id,
|
||||
"custom": False,
|
||||
},
|
||||
)
|
||||
for quant in quants
|
||||
]
|
||||
else:
|
||||
# if need move only available qty per product on location
|
||||
for _product, quant in groupby(quants, lambda r: r.product_id):
|
||||
# we need only one quant per product
|
||||
quant = list(quant)[0]
|
||||
qty = quant._get_available_quantity(
|
||||
quant.product_id,
|
||||
quant.location_id,
|
||||
)
|
||||
if qty:
|
||||
res.append(
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"product_id": quant.product_id.id,
|
||||
"move_quantity": qty,
|
||||
"max_quantity": qty,
|
||||
"reserved_quantity": quant.reserved_quantity,
|
||||
"origin_location_id": quant.location_id.id,
|
||||
"lot_id": quant.lot_id.id,
|
||||
"product_uom_id": quant.product_uom_id.id,
|
||||
"custom": False,
|
||||
},
|
||||
)
|
||||
)
|
||||
return res
|
||||
|
||||
@api.onchange("origin_location_id")
|
||||
def _onchange_origin_location_id(self):
|
||||
if not self.env.context.get("origin_location_disable", False):
|
||||
|
||||
Reference in New Issue
Block a user