[FIX] mrp,mrp_workorder: Fix (+) generate serial number button

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 <Whenrow@users.noreply.github.com>
Signed-off-by: Jean-François Aubert <ajf-odoo@users.noreply.github.com>
This commit is contained in:
JF Aubert
2021-10-13 06:03:37 +00:00
parent 2e2b49931f
commit 92049fc165
3 changed files with 5 additions and 4 deletions
+3 -2
View File
@@ -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,
+1 -1
View File
@@ -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'),
+1 -1
View File
@@ -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(