From a1ddbe73b5f5450fcd868020190233104d4768fa Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Tue, 27 Jul 2021 10:38:51 +0200 Subject: [PATCH] [IMP] stock_quant_manual_assign: add prepare lines method --- .../wizard/assign_manual_quants.py | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/stock_quant_manual_assign/wizard/assign_manual_quants.py b/stock_quant_manual_assign/wizard/assign_manual_quants.py index 6aeaafcd3..9e600a446 100644 --- a/stock_quant_manual_assign/wizard/assign_manual_quants.py +++ b/stock_quant_manual_assign/wizard/assign_manual_quants.py @@ -79,32 +79,37 @@ class AssignManualQuants(models.TransientModel): ) quants_lines = [] for quant in available_quants: - line = { - "quant_id": quant.id, - "on_hand": quant.quantity, - "location_id": quant.location_id.id, - "lot_id": quant.lot_id.id, - "package_id": quant.package_id.id, - "owner_id": quant.owner_id.id, - "selected": False, - } - move_lines = move.move_line_ids.filtered( - lambda ml: ( - ml.location_id == quant.location_id - and ml.lot_id == quant.lot_id - and ml.owner_id == quant.owner_id - and ml.package_id == quant.package_id - ) - ) - line["qty"] = sum(move_lines.mapped("product_uom_qty")) - line["selected"] = bool(line["qty"]) - line["reserved"] = quant.reserved_quantity - line["qty"] + line = self._prepare_wizard_line(move, quant) quants_lines.append(line) res.update( {"quants_lines": [(0, 0, x) for x in quants_lines], "move_id": move.id} ) return res + @api.model + def _prepare_wizard_line(self, move, quant): + line = { + "quant_id": quant.id, + "on_hand": quant.quantity, + "location_id": quant.location_id.id, + "lot_id": quant.lot_id.id, + "package_id": quant.package_id.id, + "owner_id": quant.owner_id.id, + "selected": False, + } + move_lines = move.move_line_ids.filtered( + lambda ml: ( + ml.location_id == quant.location_id + and ml.lot_id == quant.lot_id + and ml.owner_id == quant.owner_id + and ml.package_id == quant.package_id + ) + ) + line["qty"] = sum(move_lines.mapped("product_uom_qty")) + line["selected"] = bool(line["qty"]) + line["reserved"] = quant.reserved_quantity - line["qty"] + return line + class AssignManualQuantsLines(models.TransientModel): _name = "assign.manual.quants.lines"