[FIX] mrp_workorder: suggest total quantity by lot
Use case: Plan a production of 10 units on 2 workorders. Produce 4 units of lot1. Record the production and produce the 6 next ones with the same lot1. On the second workorder, the suggested quantity is 4 and not 10. This issue is due to the fact that we fill the next workorder quantity only at the first production batch and we don't check that the same lot can be used again. This commit call the mathod to update the quantity on the next workorder if the first lot is produced again. closes odoo/odoo#41189 Opw: 2127665 X-original-commit: e15fc6ac994edabc8907c13295c883cff9320d10 Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
This commit is contained in:
@@ -434,7 +434,7 @@ class MrpWorkorder(models.Model):
|
||||
self.qty_produced += self.qty_producing
|
||||
|
||||
# Suggest a finished lot on the next workorder
|
||||
if self.next_work_order_id and self.production_id.product_id.tracking != 'none' and not self.next_work_order_id.finished_lot_id:
|
||||
if self.next_work_order_id and self.product_tracking != 'none' and (not self.next_work_order_id.finished_lot_id or self.next_work_order_id.finished_lot_id == self.finished_lot_id):
|
||||
self.next_work_order_id._defaults_from_finished_workorder_line(self.finished_workorder_line_ids)
|
||||
# As we may have changed the quantity to produce on the next workorder,
|
||||
# make sure to update its wokorder lines
|
||||
|
||||
@@ -1619,3 +1619,33 @@ class TestRoutingAndKits(SavepointCase):
|
||||
self.assertEqual(len(mo.workorder_ids), 2)
|
||||
self.assertEqual(set(mo.workorder_ids[0].raw_workorder_line_ids.product_id.ids), set([self.compfinished1.id, self.compkit1.id]))
|
||||
self.assertFalse(mo.workorder_ids[1].raw_workorder_line_ids.product_id.id)
|
||||
|
||||
def test_merge_lot(self):
|
||||
""" Produce 10 units of product tracked by lot on two workorder. On the
|
||||
first one, produce 4 onto lot1 then 6 onto lot1 as well. The second
|
||||
workorder should be prefilled with 10 units and lot1"""
|
||||
self.finished1.tracking = 'lot'
|
||||
lot1 = self.env['stock.production.lot'].create({
|
||||
'product_id': self.finished1.id,
|
||||
'company_id': self.env.company.id,
|
||||
})
|
||||
mo_form = Form(self.env['mrp.production'])
|
||||
mo_form.product_id = self.finished1
|
||||
mo_form.bom_id = self.bom_finished1
|
||||
mo_form.product_qty = 10.0
|
||||
mo = mo_form.save()
|
||||
|
||||
mo.action_confirm()
|
||||
mo.button_plan()
|
||||
wo1 = mo.workorder_ids.filtered(lambda wo: wo.state == 'ready')[0]
|
||||
wo1.button_start()
|
||||
wo1.qty_producing = 4
|
||||
wo1.finished_lot_id = lot1
|
||||
wo1.record_production()
|
||||
wo1.qty_producing = 6
|
||||
wo1.finished_lot_id = lot1
|
||||
wo1.record_production()
|
||||
wo2 = mo.workorder_ids.filtered(lambda wo: wo.state == 'ready')[0]
|
||||
wo2.button_start()
|
||||
self.assertEqual(wo2.qty_producing, 10)
|
||||
self.assertEqual(wo2.finished_lot_id, lot1)
|
||||
|
||||
Reference in New Issue
Block a user