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"