From 92049fc16535912bedf19b37df260fb484b3d5f7 Mon Sep 17 00:00:00 2001 From: JF Aubert Date: Tue, 12 Oct 2021 08:03:58 +0000 Subject: [PATCH] [FIX] mrp,mrp_workorder: Fix (+) generate serial number button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The generate serial number button uses the stock.lot.serial sequence by default (default value for name of stock.production.lot) Serial Mass Produce (and other parts) allow to generate serial numbers starting from a user supplied initial value. This fix makes the button generate the next serial number according to the last generated. task 2647238 closes odoo/odoo#78258 X-original-commit: b80259dff3aaafb9d11af9d936f5106bdf5ed781 Related: odoo/enterprise#21641 Signed-off-by: William Henrotin Signed-off-by: Jean-François Aubert --- addons/mrp/models/mrp_production.py | 5 +++-- addons/stock/models/stock_move.py | 2 +- addons/stock/models/stock_production_lot.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 281e90047ee..9a6c17c136e 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -1134,7 +1134,8 @@ class MrpProduction(models.Model): self.ensure_one() self.lot_producing_id = self.env['stock.production.lot'].create({ 'product_id': self.product_id.id, - 'company_id': self.company_id.id + 'company_id': self.company_id.id, + 'name': self.env['stock.production.lot']._get_next_serial(self.company_id, self.product_id) or self.env['ir.sequence'].next_by_code('stock.lot.serial'), }) if self.move_finished_ids.filtered(lambda m: m.product_id == self.product_id).move_line_ids: self.move_finished_ids.filtered(lambda m: m.product_id == self.product_id).move_line_ids.lot_id = self.lot_producing_id @@ -1747,7 +1748,7 @@ class MrpProduction(models.Model): message += "\n".join(component.name for component in multiple_lot_components) if message: raise UserError(message) - next_serial = self.env['stock.production.lot'].get_next_serial(self.company_id, self.product_id) + next_serial = self.env['stock.production.lot']._get_next_serial(self.company_id, self.product_id) action = self.env["ir.actions.actions"]._for_xml_id("mrp.act_assign_serial_numbers_production") action['context'] = { 'default_production_id': self.id, diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 7741fe7e8e9..1bb5fe23c1c 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -649,7 +649,7 @@ class StockMove(models.Model): view = self.env.ref('stock.view_stock_move_nosuggest_operations') if self.product_id.tracking == "serial" and self.state == "assigned": - self.next_serial = self.env['stock.production.lot'].get_next_serial(self.company_id, self.product_id) + self.next_serial = self.env['stock.production.lot']._get_next_serial(self.company_id, self.product_id) return { 'name': _('Detailed Operations'), diff --git a/addons/stock/models/stock_production_lot.py b/addons/stock/models/stock_production_lot.py index 7e5e748b76d..f6364de6592 100644 --- a/addons/stock/models/stock_production_lot.py +++ b/addons/stock/models/stock_production_lot.py @@ -61,7 +61,7 @@ class ProductionLot(models.Model): return lot_names @api.model - def get_next_serial(self, company, product): + def _get_next_serial(self, company, product): """Return the next serial number to be attributed to the product.""" if product.tracking == "serial": last_serial = self.env['stock.production.lot'].search(