From 760bed34f27dfca958dee8f24e25a0e986a63527 Mon Sep 17 00:00:00 2001 From: luciaavanzosc Date: Mon, 26 Jan 2026 14:11:34 +0100 Subject: [PATCH] [16.0][IMP] mrp_show_finished_moves: Improve multiple serial productions. --- .../models/mrp_production.py | 77 ++++++++++++------- mrp_show_finished_moves/models/stock_move.py | 22 ++++++ 2 files changed, 71 insertions(+), 28 deletions(-) diff --git a/mrp_show_finished_moves/models/mrp_production.py b/mrp_show_finished_moves/models/mrp_production.py index 4c638e9f1..72696cbe0 100644 --- a/mrp_show_finished_moves/models/mrp_production.py +++ b/mrp_show_finished_moves/models/mrp_production.py @@ -44,24 +44,34 @@ def _increment_serial_number(self, serial): ) return new_serial - def _update_move_next_serial(self): + def _update_move_next_serial(self, qty): for production in self: + production._compute_last_manufactured_lot() if production.last_manufactured_lot: - next_serial = self._increment_serial_number( + next_serial = production._increment_serial_number( production.last_manufactured_lot ) if next_serial: moves_to_update = production.move_finished_ids.filtered( - lambda m: m.product_id == production.product_id - ) - moves_to_update.write( - { - "next_serial": next_serial, - "next_serial_count": production.product_qty, - } + lambda m: ( + m.product_id == production.product_id + and m.state not in ("done", "cancel") + ) ) - moves_to_update.action_clear_lines_show_details() - moves_to_update.action_assign_serial_show_details() + for move in moves_to_update: + if ( + qty != move.next_serial_count + or next_serial != move.next_serial + ): + move.write( + { + "next_serial": next_serial, + "next_serial_count": qty, + } + ) + move.action_clear_lines_show_details() + move.action_assign_serial_show_details() + production.qty_producing = move.quantity_done def action_show_finished_move_lines(self): self.ensure_one() @@ -179,7 +189,24 @@ def button_mark_done(self): yes_label=_("Yes, adjust quantities and proceed"), no_label=_("No, review data first"), ) - return super().button_mark_done() + res = super().button_mark_done() + + for production in self: + partials = self.env["mrp.production"].search( + [ + ("procurement_group_id", "=", production.procurement_group_id.id), + ("id", "!=", production.id), + ("state", "!=", "done"), + ] + ) + for partial in partials: + partial._compute_last_manufactured_lot() + if ( + partial.last_manufactured_lot + and partial.product_id.tracking == "serial" + ): + partial._update_move_next_serial(partial.product_qty) + return res def _launch_qty_warning(self, production, message, yes_label, no_label): """Launches the generic quantity warning wizard with context-specific text.""" @@ -210,20 +237,17 @@ def update_quantity_done(self): wo.qty_producing = quantity_done wo.qty_produced = quantity_done - @api.model - def create(self, vals): - production = super().create(vals) - if ( - production.last_manufactured_lot - and production.product_id.tracking == "serial" - ): - production._update_move_next_serial() - return production + def action_confirm(self): + res = super().action_confirm() + for production in self: + if production.product_id.tracking == "serial": + production._update_move_next_serial(production.product_qty) + return res def write(self, vals): res = super().write(vals) - if "lot_producing_id" in vals: - for production in self: + for production in self: + if "lot_producing_id" in vals: new_name = ( production.lot_producing_id.name if production.lot_producing_id @@ -252,11 +276,8 @@ def write(self, vals): ) ) move.move_line_ids = ml_cmds - if ( - "last_manufactured_lot" in vals - and production.product_id.tracking == "serial" - ): - production._update_move_next_serial() + if "qty_producing" in vals and production.product_id.tracking == "serial": + production._update_move_next_serial(production.qty_producing) return res diff --git a/mrp_show_finished_moves/models/stock_move.py b/mrp_show_finished_moves/models/stock_move.py index ca663940a..b838675ed 100644 --- a/mrp_show_finished_moves/models/stock_move.py +++ b/mrp_show_finished_moves/models/stock_move.py @@ -55,3 +55,25 @@ def action_show_move_lines_packages(self): "res_model": "stock.quant.package", "domain": [("id", "in", all_packages.ids)], } + + def write(self, vals): + res = super().write(vals) + for move in self: + if ( + move.product_id.tracking == "serial" + and "next_serial_count" in vals + and move.product_id == move.production_id.product_id + and move.state not in ["done", "cancel"] + ): + production = move.production_id + production._compute_last_manufactured_lot() + if production.last_manufactured_lot: + next_serial = production._increment_serial_number( + production.last_manufactured_lot + ) + move.next_serial = next_serial + move.action_clear_lines_show_details() + move.action_assign_serial_show_details() + if production.qty_producing != move.quantity_done: + production.qty_producing = move.quantity_done + return res