From bbb8a53f47707d4b534d990354d939b81280ca69 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Thu, 1 Jun 2023 18:02:24 +0000 Subject: [PATCH] [REF] mrp: Extract preparation of lot values on mrp.production This allows to customize the values used to created lots and avoids repeated code in enterprise module. closes odoo/odoo#124543 X-original-commit: 0820a69a3fec90717ea10bf4c56a5609d6b376e2 Related: odoo/enterprise#42300 Signed-off-by: William Henrotin (whe) --- addons/mrp/models/mrp_production.py | 36 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index c56a4368f94..c59d0057626 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -1238,22 +1238,7 @@ class MrpProduction(models.Model): def _set_lot_producing(self): self.ensure_one() - if self.product_id.tracking == 'lot': - name = self.env['ir.sequence'].next_by_code('stock.lot.serial') - exist_lot = self.env['stock.lot'].search([ - ('product_id', '=', self.product_id.id), - ('company_id', '=', self.company_id.id), - ('name', '=', name), - ], limit=1) - if exist_lot: - name = self.env['stock.lot']._get_next_serial(self.company_id, self.product_id) - else: - name = self.env['stock.lot']._get_next_serial(self.company_id, self.product_id) or self.env['ir.sequence'].next_by_code('stock.lot.serial') - self.lot_producing_id = self.env['stock.lot'].create({ - 'product_id': self.product_id.id, - 'company_id': self.company_id.id, - 'name': name, - }) + self.lot_producing_id = self.env['stock.lot'].create(self._prepare_stock_lot_values()) def action_view_mrp_production_childs(self): self.ensure_one() @@ -1305,6 +1290,25 @@ class MrpProduction(models.Model): 'view_mode': 'tree,form', } + def _prepare_stock_lot_values(self): + self.ensure_one() + if self.product_id.tracking == 'lot': + name = self.env['ir.sequence'].next_by_code('stock.lot.serial') + exist_lot = self.env['stock.lot'].search([ + ('product_id', '=', self.product_id.id), + ('company_id', '=', self.company_id.id), + ('name', '=', name), + ], limit=1) + if exist_lot: + name = self.env['stock.lot']._get_next_serial(self.company_id, self.product_id) + else: + name = self.env['stock.lot']._get_next_serial(self.company_id, self.product_id) or self.env['ir.sequence'].next_by_code('stock.lot.serial') + return { + 'product_id': self.product_id.id, + 'company_id': self.company_id.id, + 'name': name, + } + def action_generate_serial(self): self.ensure_one() self._set_lot_producing()