[IMP] add posibility to move only not reserved quantity

This commit is contained in:
Iryna Vushnevska
2020-04-23 16:10:14 +03:00
committed by sonhd
parent a2d52d0bbd
commit ec1cbb0e76
2 changed files with 54 additions and 21 deletions

View File

@@ -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",

View File

@@ -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):