[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) <whe@odoo.com>
This commit is contained in:
committed by
William Henrotin
parent
ccbb749cfb
commit
bbb8a53f47
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user