diff --git a/mrp_production_split_finished_product_by_serials/models/mrp_production.py b/mrp_production_split_finished_product_by_serials/models/mrp_production.py
index b3964aa18..54fe69dcc 100644
--- a/mrp_production_split_finished_product_by_serials/models/mrp_production.py
+++ b/mrp_production_split_finished_product_by_serials/models/mrp_production.py
@@ -20,6 +20,10 @@ class MrpProduction(models.Model):
copy=False,
)
+ has_finished_move_lines = fields.Boolean(
+ compute="_compute_has_finished_move_lines", store=False
+ )
+
@api.onchange("lot_producing_id")
def _onchange_lot_producing(self):
res = super()._onchange_lot_producing()
@@ -77,6 +81,7 @@ def _get_lot_name(self, number=1):
self.product_tracking == "serial"
and self.state not in ("done", "cancel")
and not self.serial_lot_name
+ and not self.has_finished_move_lines
):
if "from_product_lot_sequence" not in self.env.context or (
"from_product_lot_sequence" in self.env.context
@@ -95,6 +100,12 @@ def _get_lot_name(self, number=1):
return new_lot_name
def action_generate_serial(self):
+ if self.has_finished_move_lines:
+ self.serial_lot_name = False
+ return super(
+ MrpProduction,
+ self.with_context(qty_twith_serial=self.qty_producing),
+ ).action_generate_serial()
if (
"from_product_lot_sequence" in self.env.context
and "from_button_mark_done" in self.env.context
@@ -137,6 +148,9 @@ def _set_qty_producing(self):
def button_mark_done(self):
if self.product_tracking == "serial":
+ if self.has_finished_move_lines:
+ self.serial_lot_name = False
+ return super().button_mark_done()
if not self.lot_producing_id:
if (
"from_product_lot_sequence" not in self.env.context
@@ -171,6 +185,8 @@ def _post_inventory(self, cancel_backorder=False):
def create_lot_for_tracking_serial(self):
self.ensure_one()
+ if self.has_finished_move_lines:
+ return
moves = self.move_finished_ids.filtered(
lambda x: x.product_id == self.product_id
)
@@ -254,3 +270,10 @@ def _prepare_stock_lot_values(self):
"company_id": self.company_id.id,
}
return super()._prepare_stock_lot_values()
+
+ @api.depends("move_finished_ids.move_line_ids")
+ def _compute_has_finished_move_lines(self):
+ for production in self:
+ production.has_finished_move_lines = any(
+ production.move_finished_ids.mapped("move_line_ids")
+ )
diff --git a/mrp_production_split_finished_product_by_serials/views/mrp_production_views.xml b/mrp_production_split_finished_product_by_serials/views/mrp_production_views.xml
index 11ac2d598..eca31a797 100644
--- a/mrp_production_split_finished_product_by_serials/views/mrp_production_views.xml
+++ b/mrp_production_split_finished_product_by_serials/views/mrp_production_views.xml
@@ -23,9 +23,10 @@
+