summaryrefslogtreecommitdiff
path: root/addons/mrp/tests/test_traceability.py
diff options
context:
space:
mode:
Diffstat (limited to 'addons/mrp/tests/test_traceability.py')
-rw-r--r--addons/mrp/tests/test_traceability.py139
1 files changed, 139 insertions, 0 deletions
diff --git a/addons/mrp/tests/test_traceability.py b/addons/mrp/tests/test_traceability.py
index 7f94f17ba8c..045ae8ef244 100644
--- a/addons/mrp/tests/test_traceability.py
+++ b/addons/mrp/tests/test_traceability.py
@@ -113,3 +113,142 @@ class TestTraceability(TestMrpCommon):
unfoldable,
'Parts with tracking type "%s", should have be unfoldable : %s' % (tracking, unfoldable)
)
+
+ def test_tracking_on_byproducts(self):
+ product_final = self.env['product.product'].create({
+ 'name': 'Finished Product',
+ 'type': 'product',
+ 'tracking': 'serial',
+ })
+ product_1 = self.env['product.product'].create({
+ 'name': 'Raw 1',
+ 'type': 'product',
+ 'tracking': 'serial',
+ })
+ product_2 = self.env['product.product'].create({
+ 'name': 'Raw 2',
+ 'type': 'product',
+ 'tracking': 'serial',
+ })
+ byproduct_1 = self.env['product.product'].create({
+ 'name': 'Byproduct 1',
+ 'type': 'product',
+ 'tracking': 'serial',
+ })
+ byproduct_2 = self.env['product.product'].create({
+ 'name': 'Byproduct 2',
+ 'type': 'product',
+ 'tracking': 'serial',
+ })
+ bom_1 = self.env['mrp.bom'].create({
+ 'product_id': product_final.id,
+ 'product_tmpl_id': product_final.product_tmpl_id.id,
+ 'product_uom_id': self.uom_unit.id,
+ 'product_qty': 1.0,
+ 'type': 'normal',
+ 'bom_line_ids': [
+ (0, 0, {'product_id': product_1.id, 'product_qty': 1}),
+ (0, 0, {'product_id': product_2.id, 'product_qty': 1})
+ ],
+ 'byproduct_ids': [
+ (0, 0, {'product_id': byproduct_1.id, 'product_qty': 1, 'product_uom_id': byproduct_1.uom_id.id}),
+ (0, 0, {'product_id': byproduct_2.id, 'product_qty': 1, 'product_uom_id': byproduct_2.uom_id.id})
+ ]})
+ mo_form = Form(self.env['mrp.production'])
+ mo_form.product_id = product_final
+ mo_form.bom_id = bom_1
+ mo_form.product_qty = 2
+ mo = mo_form.save()
+ mo.action_confirm()
+
+ produce_form = Form(self.env['mrp.product.produce'].with_context({
+ 'active_id': mo.id,
+ 'active_ids': [mo.id],
+ }))
+ produce_form.final_lot_id = self.env['stock.production.lot'].create({
+ 'product_id': product_final.id,
+ 'name': 'Final_lot_1'
+ })
+ with produce_form.raw_workorder_line_ids.edit(0) as line:
+ line.lot_id = self.env['stock.production.lot'].create({
+ 'product_id': product_1.id,
+ 'name': 'Raw_1_lot_1'
+ })
+ with produce_form.raw_workorder_line_ids.edit(1) as line:
+ line.lot_id = self.env['stock.production.lot'].create({
+ 'product_id': product_2.id,
+ 'name': 'Raw_2_lot_1'
+ })
+ with produce_form.finished_workorder_line_ids.edit(0) as line:
+ line.lot_id = self.env['stock.production.lot'].create({
+ 'product_id': byproduct_1.id,
+ 'name': 'Byproduct_1_lot_1'
+ })
+ with produce_form.finished_workorder_line_ids.edit(1) as line:
+ line.lot_id = self.env['stock.production.lot'].create({
+ 'product_id': byproduct_2.id,
+ 'name': 'Byproduct_2_lot_1'
+ })
+ produce_wizard = produce_form.save()
+ produce_wizard.continue_production()
+
+ produce_form = Form(self.env['mrp.product.produce'].with_context({
+ 'active_id': mo.id,
+ 'active_ids': [mo.id],
+ }))
+ produce_form.final_lot_id = self.env['stock.production.lot'].create({
+ 'product_id': product_final.id,
+ 'name': 'Final_lot_2'
+ })
+ with produce_form.raw_workorder_line_ids.edit(0) as line:
+ line.lot_id = self.env['stock.production.lot'].create({
+ 'product_id': product_1.id,
+ 'name': 'Raw_1_lot_2'
+ })
+ with produce_form.raw_workorder_line_ids.edit(1) as line:
+ line.lot_id = self.env['stock.production.lot'].create({
+ 'product_id': product_2.id,
+ 'name': 'Raw_2_lot_2'
+ })
+ with produce_form.finished_workorder_line_ids.edit(0) as line:
+ line.lot_id = self.env['stock.production.lot'].create({
+ 'product_id': byproduct_1.id,
+ 'name': 'Byproduct_1_lot_2'
+ })
+ with produce_form.finished_workorder_line_ids.edit(1) as line:
+ line.lot_id = self.env['stock.production.lot'].create({
+ 'product_id': byproduct_2.id,
+ 'name': 'Byproduct_2_lot_2'
+ })
+ produce_wizard = produce_form.save()
+ produce_wizard.do_produce()
+ mo.button_mark_done()
+
+ self.assertEqual(len(mo.move_raw_ids.mapped('move_line_ids')), 4)
+ self.assertEqual(len(mo.move_finished_ids.mapped('move_line_ids')), 6)
+
+ raw_move_lines = mo.move_raw_ids.mapped('move_line_ids')
+ raw_line_raw_1_lot_1 = raw_move_lines.filtered(lambda ml: ml.lot_id.name == 'Raw_1_lot_1')
+ self.assertEqual(raw_line_raw_1_lot_1.lot_produced_ids.mapped('name'), ['Final_lot_1', 'Byproduct_1_lot_1', 'Byproduct_2_lot_1'])
+ raw_line_raw_1_lot_2 = raw_move_lines.filtered(lambda ml: ml.lot_id.name == 'Raw_1_lot_2')
+ self.assertEqual(raw_line_raw_1_lot_2.lot_produced_ids.mapped('name'), ['Final_lot_2', 'Byproduct_1_lot_2', 'Byproduct_2_lot_2'])
+ raw_line_raw_2_lot_1 = raw_move_lines.filtered(lambda ml: ml.lot_id.name == 'Raw_2_lot_1')
+ self.assertEqual(raw_line_raw_2_lot_1.lot_produced_ids.mapped('name'), ['Final_lot_1', 'Byproduct_1_lot_1', 'Byproduct_2_lot_1'])
+ raw_line_raw_2_lot_2 = raw_move_lines.filtered(lambda ml: ml.lot_id.name == 'Raw_2_lot_2')
+ self.assertEqual(raw_line_raw_2_lot_2.lot_produced_ids.mapped('name'), ['Final_lot_2', 'Byproduct_1_lot_2', 'Byproduct_2_lot_2'])
+
+ finished_move_lines = mo.move_finished_ids.mapped('move_line_ids')
+ finished_move_line_lot_1 = finished_move_lines.filtered(lambda ml: ml.lot_id.name == 'Final_lot_1')
+ self.assertEqual(finished_move_line_lot_1.consume_line_ids, raw_line_raw_1_lot_1 | raw_line_raw_2_lot_1)
+ finished_move_line_lot_2 = finished_move_lines.filtered(lambda ml: ml.lot_id.name == 'Final_lot_2')
+ self.assertEqual(finished_move_line_lot_2.consume_line_ids, raw_line_raw_1_lot_2 | raw_line_raw_2_lot_2)
+
+ byproduct_move_line_1_lot_1 = finished_move_lines.filtered(lambda ml: ml.lot_id.name == 'Byproduct_1_lot_1')
+ self.assertEqual(byproduct_move_line_1_lot_1.consume_line_ids, raw_line_raw_1_lot_1 | raw_line_raw_2_lot_1)
+ byproduct_move_line_1_lot_2 = finished_move_lines.filtered(lambda ml: ml.lot_id.name == 'Byproduct_1_lot_2')
+ self.assertEqual(byproduct_move_line_1_lot_2.consume_line_ids, raw_line_raw_1_lot_2 | raw_line_raw_2_lot_2)
+
+ byproduct_move_line_2_lot_1 = finished_move_lines.filtered(lambda ml: ml.lot_id.name == 'Byproduct_2_lot_1')
+ self.assertEqual(byproduct_move_line_2_lot_1.consume_line_ids, raw_line_raw_1_lot_1 | raw_line_raw_2_lot_1)
+ byproduct_move_line_2_lot_2 = finished_move_lines.filtered(lambda ml: ml.lot_id.name == 'Byproduct_2_lot_2')
+ self.assertEqual(byproduct_move_line_2_lot_2.consume_line_ids, raw_line_raw_1_lot_2 | raw_line_raw_2_lot_2)