summaryrefslogtreecommitdiff
path: root/addons/mrp/tests/test_order.py
diff options
context:
space:
mode:
authorWilliam Henrotin <whe@odoo.com>2020-04-27 11:56:02 +0200
committerSimon Lejeune <sle@openerp.com>2020-06-15 16:59:41 +0200
commit0e2765f5fd0ca0079f1f024ec3a1448b6d2ea3db (patch)
tree90ea03d1aca1bf87a080775e7db07977b645c5cc /addons/mrp/tests/test_order.py
parent1b6421285c6bc4c61be3242cea30c2813251cbc7 (diff)
[REF] mrp: no more produce wizard
Use a view similar as the pickings one. task-2241471
Diffstat (limited to 'addons/mrp/tests/test_order.py')
-rw-r--r--addons/mrp/tests/test_order.py680
1 files changed, 198 insertions, 482 deletions
diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py
index 8e7467b5354..3cca0512e0b 100644
--- a/addons/mrp/tests/test_order.py
+++ b/addons/mrp/tests/test_order.py
@@ -8,7 +8,6 @@ from odoo.fields import Datetime as Dt
from odoo.exceptions import UserError
from odoo.addons.mrp.tests.common import TestMrpCommon
-
class TestMrpOrder(TestMrpCommon):
def test_access_rights_manager(self):
@@ -95,13 +94,9 @@ class TestMrpOrder(TestMrpCommon):
self.assertEqual(first_move.product_qty, test_quantity / self.bom_1.product_qty * self.product_4.uom_id.factor_inv * 4)
# produce product
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': man_order.id,
- 'active_ids': [man_order.id],
- }))
- produce_form.qty_producing = 1.0
- produce_wizard = produce_form.save()
- produce_wizard.do_produce()
+ mo_form = Form(man_order)
+ mo_form.qty_producing = 1.0
+ man_order = mo_form.save()
action = man_order.button_mark_done()
self.assertEqual(man_order.state, 'progress', "Production order should be open a backorder wizard, then not done yet.")
@@ -160,15 +155,12 @@ class TestMrpOrder(TestMrpCommon):
mo, bom, p_final, p1, p2 = self.generate_mo(qty_base_1=10, qty_final=1, qty_base_2=1)
bom.consumption = 'flexible'
mo.action_assign()
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- for i in range(len(produce_form.raw_workorder_line_ids)):
- with produce_form.raw_workorder_line_ids.edit(i) as line:
- line.qty_done += 1
- product_produce = produce_form.save()
- product_produce.do_produce()
+ mo_form = Form(mo)
+ mo_form.qty_producing = 1
+ for i in range(len(mo_form.move_raw_ids)):
+ with mo_form.move_raw_ids.edit(i) as move:
+ move.quantity_done += 1
+ mo = mo_form.save()
self.assertEqual(len(mo.move_raw_ids), 2)
self.assertEqual(len(mo.move_raw_ids.mapped('move_line_ids')), 2)
self.assertEqual(mo.move_raw_ids[0].move_line_ids.mapped('qty_done'), [2])
@@ -248,11 +240,9 @@ class TestMrpOrder(TestMrpCommon):
self.assertEqual(mo_custom_laptop.reservation_state, 'assigned')
# produce one item, call `post_inventory`
- context = {"active_ids": [mo_custom_laptop.id], "active_id": mo_custom_laptop.id}
- produce_form = Form(self.env['mrp.product.produce'].with_context(context))
- produce_form.qty_producing = 1.00
- custom_laptop_produce = produce_form.save()
- custom_laptop_produce.do_produce()
+ mo_form = Form(mo_custom_laptop)
+ mo_form.qty_producing = 1.00
+ mo_custom_laptop = mo_form.save()
mo_custom_laptop.post_inventory()
# check the consumed quants of the produced quant
@@ -264,11 +254,9 @@ class TestMrpOrder(TestMrpCommon):
self.assertEqual(second_move.quantity_done, 0, "There is still one product to pruduce")
# produce the second item, call `post_inventory`
- context = {"active_ids": [mo_custom_laptop.id], "active_id": mo_custom_laptop.id}
- produce_form = Form(self.env['mrp.product.produce'].with_context(context))
- produce_form.qty_producing = 1.00
- custom_laptop_produce = produce_form.save()
- custom_laptop_produce.do_produce()
+ mo_form = Form(mo_custom_laptop)
+ mo_form.qty_producing = 2.00
+ mo_custom_laptop = mo_form.save()
mo_custom_laptop.post_inventory()
self.assertEqual(second_move.quantity_done, 1, "Order produce the second product")
quant_after2 = custom_laptop.qty_available
@@ -301,14 +289,15 @@ class TestMrpOrder(TestMrpCommon):
self.env['stock.quant']._update_available_quantity(p2, self.stock_location, 5)
mo.action_assign()
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- produce_wizard = produce_form.save()
- produce_wizard.do_produce()
+ mo_form = Form(mo)
+ mo_form.qty_producing = 1
+ mo = mo_form.save()
- mo.move_finished_ids.move_line_ids.qty_done -= 1
+ details_operation_form = Form(mo.move_raw_ids[1], view=self.env.ref('stock.view_stock_move_operations'))
+ with details_operation_form.move_line_ids.new() as ml:
+ ml.lot_id = lot_1
+ ml.qty_done = 20
+ details_operation_form.save()
update_quantity_wizard = self.env['change.production.qty'].create({
'mo_id': mo.id,
'product_qty': 4,
@@ -333,67 +322,25 @@ class TestMrpOrder(TestMrpCommon):
self.env['stock.quant']._update_available_quantity(p2, self.stock_location, 5)
mo.action_assign()
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- produce_form.qty_producing = 2
- produce_wizard = produce_form.save()
- produce_wizard.do_produce()
+ mo_form = Form(mo)
+ mo_form.qty_producing = 2
+ mo = mo_form.save()
+
+ mo._post_inventory()
- mo.post_inventory()
update_quantity_wizard = self.env['change.production.qty'].create({
'mo_id': mo.id,
'product_qty': 5,
})
update_quantity_wizard.change_prod_qty()
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- produce_wizard = produce_form.save()
- produce_wizard.do_produce()
+ mo_form = Form(mo)
+ mo_form.qty_producing = 5
+ mo = mo_form.save()
mo.button_mark_done()
self.assertEqual(sum(mo.move_raw_ids.filtered(lambda m: m.product_id == p1).mapped('quantity_done')), 20)
self.assertEqual(sum(mo.move_finished_ids.mapped('quantity_done')), 5)
- def test_update_quantity_3(self):
- """ Build 1 final products then update the Manufacturing
- order quantity. Check the remaining quantity to produce
- take care of the first quantity produced."""
- self.stock_location = self.env.ref('stock.stock_location_stock')
- mo, bom, p_final, p1, p2 = self.generate_mo(qty_final=2)
- self.assertEqual(len(mo), 1, 'MO should have been created')
-
- self.env['stock.quant']._update_available_quantity(p1, self.stock_location, 20)
- self.env['stock.quant']._update_available_quantity(p2, self.stock_location, 5)
- mo.action_assign()
-
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- produce_form.qty_producing = 1
- produce_wizard = produce_form.save()
- produce_wizard.do_produce()
-
- update_quantity_wizard = self.env['change.production.qty'].create({
- 'mo_id': mo.id,
- 'product_qty': 3,
- })
- update_quantity_wizard.change_prod_qty()
-
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- produce_wizard = produce_form.save()
- produce_wizard.do_produce()
- mo.button_mark_done()
- self.assertEqual(sum(mo.move_raw_ids.filtered(lambda m: m.product_id == p1).mapped('quantity_done')), 12)
- self.assertEqual(sum(mo.move_finished_ids.mapped('quantity_done')), 3)
-
def test_rounding(self):
""" Checks we round up when bringing goods to produce and round half-up when producing.
This implementation allows to implement an efficiency notion (see rev 347f140fe63612ee05e).
@@ -422,13 +369,9 @@ class TestMrpOrder(TestMrpCommon):
self.assertEqual(production.move_raw_ids[1].product_qty, 84, 'The quantity should be rounded up')
# produce product
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': production.id,
- 'active_ids': [production.id],
- }))
- produce_form.qty_producing = 8
- produce_wizard = produce_form.save()
- produce_wizard.do_produce()
+ mo_form = Form(production)
+ mo_form.qty_producing = 8
+ production = mo_form.save()
self.assertEqual(production.move_raw_ids[0].quantity_done, 16, 'Should use half-up rounding when producing')
self.assertEqual(production.move_raw_ids[1].quantity_done, 34, 'Should use half-up rounding when producing')
@@ -443,27 +386,21 @@ class TestMrpOrder(TestMrpCommon):
mo.action_assign()
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
# change the quantity done in one line
- produce_form.raw_workorder_line_ids._records[0]['qty_done'] = 1
+ details_operation_form = Form(mo.move_raw_ids[0], view=self.env.ref('stock.view_stock_move_operations'))
+ with details_operation_form.move_line_ids.edit(0) as ml:
+ ml.qty_done = 1
+ details_operation_form.save()
# change the quantity producing
- produce_form.qty_producing = 3
+ mo_form = Form(mo)
+ mo_form.qty_producing = 3
# check than all quantities are update correctly
- line1 = produce_form.raw_workorder_line_ids._records[0]
- line2 = produce_form.raw_workorder_line_ids._records[1]
- self.assertEqual(line1['qty_to_consume'], 3, "Wrong quantity to consume")
- self.assertEqual(line1['qty_done'], 3, "Wrong quantity done")
- self.assertEqual(line2['qty_to_consume'], 12, "Wrong quantity to consume")
- self.assertEqual(line2['qty_done'], 12, "Wrong quantity done")
-
- product_produce = produce_form.save()
- self.assertEqual(len(product_produce.raw_workorder_line_ids), 2, 'You should have produce lines even the consumed products are not tracked.')
- product_produce.do_produce()
+ self.assertEqual(mo_form.move_raw_ids._records[0]['product_uom_qty'], 5, "Wrong quantity to consume")
+ self.assertEqual(mo_form.move_raw_ids._records[0]['quantity_done'], 3, "Wrong quantity done")
+ self.assertEqual(mo_form.move_raw_ids._records[1]['product_uom_qty'], 20, "Wrong quantity to consume")
+ self.assertEqual(mo_form.move_raw_ids._records[1]['quantity_done'], 12, "Wrong quantity done")
def test_product_produce_2(self):
""" Checks that, for a BOM where one of the components is tracked by serial number and the
@@ -490,22 +427,19 @@ class TestMrpOrder(TestMrpCommon):
self.env['stock.quant']._update_available_quantity(p2, self.stock_location, 5)
mo.action_assign()
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- self.assertEqual(len(produce_form.raw_workorder_line_ids), 3, 'You should have 3 produce lines. One for each serial to consume and for the untracked product.')
- produce_form.qty_producing = 1
+ self.assertEqual(len(mo.move_raw_ids.move_line_ids), 3, 'You should have 3 stock move lines. One for each serial to consume and for the untracked product.')
+ mo_form = Form(mo)
+ mo_form.qty_producing = 1
+ mo = mo_form.save()
# get the proposed lot
- consumed_lots = self.env['stock.production.lot']
- for workorder_line in produce_form.raw_workorder_line_ids._records:
- if workorder_line['product_id'] == p1.id:
- consumed_lots |= self.env['stock.production.lot'].browse(workorder_line['lot_id'])
- consumed_lots.ensure_one()
- product_produce = produce_form.save()
- product_produce.do_produce()
+ details_operation_form = Form(mo.move_raw_ids.filtered(lambda move: move.product_id == p1), view=self.env.ref('stock.view_stock_move_operations'))
+ self.assertEqual(len(details_operation_form.move_line_ids), 2)
+ with details_operation_form.move_line_ids.edit(0) as ml:
+ consumed_lots = ml.lot_id
+ ml.qty_done = 1
+ details_operation_form.save()
remaining_lot = (lot_p1_1 | lot_p1_2) - consumed_lots
remaining_lot.ensure_one()
@@ -513,22 +447,22 @@ class TestMrpOrder(TestMrpCommon):
backorder = Form(self.env['mrp.production.backorder'].with_context(**action['context']))
backorder.save().action_backorder()
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- product_produce = produce_form.save()
- self.assertEqual(len(product_produce.raw_workorder_line_ids), 2, 'You should have 2 produce lines left.')
- for line in product_produce.raw_workorder_line_ids.filtered(lambda x: x.lot_id):
- self.assertEqual(line.lot_id, remaining_lot, 'Wrong lot proposed.')
+ # Check MO backorder
+ mo_backorder = mo.procurement_group_id.mrp_production_ids[-1]
+
+ mo_form = Form(mo_backorder)
+ mo_form.qty_producing = 1
+ mo_backorder = mo_form.save()
+ details_operation_form = Form(mo_backorder.move_raw_ids.filtered(lambda move: move.product_id == p1), view=self.env.ref('stock.view_stock_move_operations'))
+ self.assertEqual(len(details_operation_form.move_line_ids), 1)
+ with details_operation_form.move_line_ids.edit(0) as ml:
+ self.assertEqual(ml.lot_id, remaining_lot)
def test_product_produce_3(self):
""" Checks that, for a BOM where one of the components is tracked by lot and the other is
not tracked, when creating a manufacturing order for 1 finished product and reserving, the
- produce wizard proposes the corrects lines. Then, checks the generated move lines when over
- consuming.
+ reserved lines are displayed. Then, over-consume by creating new line.
"""
- # FIXME: some asserts on the quants after overproducing would be nice
self.stock_location = self.env.ref('stock.stock_location_stock')
self.stock_shelf_1 = self.stock_location_components
@@ -560,22 +494,31 @@ class TestMrpOrder(TestMrpCommon):
self.env['stock.quant']._update_available_quantity(p2, self.stock_location, 5)
mo.action_assign()
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- produce_form.qty_producing = 1.0
- for i in range(len(produce_form.raw_workorder_line_ids)):
- with produce_form.raw_workorder_line_ids.edit(i) as line:
- line.qty_done += 1
- product_produce = produce_form.save()
- product_produce.finished_lot_id = final_product_lot.id
- # product 1 lot 1 shelf1
- # product 1 lot 1 shelf2
- # product 1 lot 2
- self.assertEqual(len(product_produce.raw_workorder_line_ids), 4, 'You should have 4 produce lines. lot 1 shelf_1, lot 1 shelf_2, lot2 and for product which have tracking None')
-
- product_produce.do_produce()
+ mo_form = Form(mo)
+ mo_form.qty_producing = 1.0
+ mo_form.lot_producing_id = final_product_lot
+ mo = mo_form.save()
+ # p2
+ details_operation_form = Form(mo.move_raw_ids[0], view=self.env.ref('stock.view_stock_move_operations'))
+ with details_operation_form.move_line_ids.edit(0) as line:
+ line.qty_done = line.product_uom_qty
+ with details_operation_form.move_line_ids.new() as line:
+ line.qty_done = 1
+ details_operation_form.save()
+
+ # p1
+ details_operation_form = Form(mo.move_raw_ids[1], view=self.env.ref('stock.view_stock_move_operations'))
+ for i in range(len(details_operation_form.move_line_ids)):
+ # reservation in shelf1: 3 lot1, shelf2: 3 lot1, stock: 4 lot2
+ with details_operation_form.move_line_ids.edit(i) as line:
+ line.qty_done = line.product_uom_qty
+ with details_operation_form.move_line_ids.new() as line:
+ line.qty_done = 2
+ line.lot_id = first_lot_for_p1
+ with details_operation_form.move_line_ids.new() as line:
+ line.qty_done = 1
+ line.lot_id = second_lot_for_p1
+ details_operation_form.save()
move_1 = mo.move_raw_ids.filtered(lambda m: m.product_id == p1)
# qty_done/product_uom_qty lot
@@ -616,18 +559,15 @@ class TestMrpOrder(TestMrpCommon):
ml_p1[0].qty_done = 1.0
# Produce baby!
- product_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- product_produce = product_form.save()
- product_produce.do_produce()
+ mo_form = Form(mo)
+ mo_form.qty_producing = 1
+ mo = mo_form.save()
m_p1 = mo.move_raw_ids.filtered(lambda x: x.product_id == p1)
ml_p1 = m_p1.mapped('move_line_ids')
- self.assertEqual(len(ml_p1), 3)
- self.assertEqual(sorted(ml_p1.mapped('qty_done')), [1.0, 2.0, 3.0], 'Quantity done should be 1.0, 2.0 or 3.0')
- self.assertEqual(m_p1.quantity_done, 6.0, 'Total qty done should be 6.0')
+ self.assertEqual(len(ml_p1), 2)
+ self.assertEqual(sorted(ml_p1.mapped('qty_done')), [2.0, 3.0], 'Quantity done should be 1.0, 2.0 or 3.0')
+ self.assertEqual(m_p1.quantity_done, 5.0, 'Total qty done should be 6.0')
self.assertEqual(sum(ml_p1.mapped('product_uom_qty')), 5.0, 'Total qty reserved should be 5.0')
mo.button_mark_done()
@@ -636,7 +576,7 @@ class TestMrpOrder(TestMrpCommon):
def test_product_produce_6(self):
""" Plan 5 finished products, reserve and produce 3. Post the current production.
Simulate an unlock and edit and, on the opened moves, set the consumed quantity
- to 3. Now, try to update the quantity to produce to 3. It should fail since there
+ to 3. Now, try to update the quantity to mo2 to 3. It should fail since there
are consumed quantities. Unlock and edit, remove the consumed quantities and
update the quantity to produce to 3."""
self.stock_location = self.env.ref('stock.stock_location_stock')
@@ -648,13 +588,9 @@ class TestMrpOrder(TestMrpCommon):
self.env['stock.quant']._update_available_quantity(p2, self.stock_location, 5)
mo.action_assign()
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- produce_form.qty_producing = 3
- produce_wizard = produce_form.save()
- produce_wizard.do_produce()
+ mo_form = Form(mo)
+ mo_form.qty_producing = 3
+ mo = mo_form.save()
mo.post_inventory()
self.assertEqual(len(mo.move_raw_ids), 4)
@@ -675,127 +611,11 @@ class TestMrpOrder(TestMrpCommon):
self.assertTrue(all(s == 'done' for s in mo.move_raw_ids.mapped('state')))
self.assertEqual(sum(mo.move_raw_ids.mapped('move_line_ids.product_uom_qty')), 0)
- def test_product_produce_7(self):
- """ Add components in 2 different sub location. Do not reserve the MO
- and checks that the move line created takes stock from location that
- contains needed raw materials.
- """
- mo, bom, p_final, p1, p2 = self.generate_mo(qty_final=2)
- self.assertEqual(len(mo), 1, 'MO should have been created')
-
- self.stock_location = self.env.ref('stock.stock_location_stock')
- self.stock_shelf_1 = self.stock_location_components
- self.stock_shelf_2 = self.stock_location_14
-
- self.env['stock.quant']._update_available_quantity(p1, self.stock_shelf_1, 3)
- self.env['stock.quant']._update_available_quantity(p1, self.stock_location, 3)
- self.env['stock.quant']._update_available_quantity(p1, self.stock_shelf_2, 2)
-
- self.env['stock.quant']._update_available_quantity(p2, self.stock_shelf_1, 1)
- self.env['stock.quant']._update_available_quantity(p2, self.stock_shelf_2, 1)
-
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- produce_form.qty_producing = 1
- produce_wizard = produce_form.save()
-
- self.assertEqual(len(produce_wizard.raw_workorder_line_ids), 2)
- produce_wizard.do_produce()
-
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- produce_form.qty_producing = 1
-
- produce_wizard = produce_form.save()
-
- self.assertEqual(len(produce_wizard.raw_workorder_line_ids), 2)
- produce_wizard.do_produce()
-
- mo.button_mark_done()
- mo_move_line_p1 = mo.move_raw_ids[1].move_line_ids
- self.assertEqual(sum(mo_move_line_p1.filtered(lambda ml: ml.location_id == self.stock_location).mapped('qty_done')), 3)
- self.assertEqual(sum(mo_move_line_p1.filtered(lambda ml: ml.location_id == self.stock_shelf_1).mapped('qty_done')), 3)
- self.assertEqual(sum(mo_move_line_p1.filtered(lambda ml: ml.location_id == self.stock_shelf_2).mapped('qty_done')), 2)
- self.assertEqual(sum(mo.move_finished_ids.move_line_ids.mapped('qty_done')), 2)
-
- self.assertEqual(self.env['stock.quant']._gather(p1, self.stock_location, strict=True).quantity, 0)
- self.assertEqual(self.env['stock.quant']._gather(p1, self.stock_shelf_1, strict=True).quantity, 0)
- self.assertEqual(self.env['stock.quant']._gather(p1, self.stock_shelf_2, strict=True).quantity, 0)
-
- self.assertEqual(self.env['stock.quant']._gather(p2, self.stock_shelf_1, strict=True).quantity, 0)
- self.assertEqual(self.env['stock.quant']._gather(p2, self.stock_shelf_2, strict=True).quantity, 0)
- self.assertEqual(self.env['stock.quant']._gather(p_final, self.stock_location, strict=True).quantity, 2)
-
- def test_product_produce_8(self):
- """ Produce more than reserved and planned. Check that produce wizard
- only propose one line for product not reserved.
- """
- mo, bom, p_final, p1, p2 = self.generate_mo(qty_final=2)
- self.assertEqual(len(mo), 1, 'MO should have been created')
-
- self.stock_location = self.env.ref('stock.stock_location_stock')
-
- self.env['stock.quant']._update_available_quantity(p1, self.stock_location, 5)
- self.env['stock.quant']._update_available_quantity(p2, self.stock_location, 2)
-
- mo.action_assign()
-
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- produce_form.qty_producing = 1
- produce_wizard = produce_form.save()
- self.assertEqual(len(produce_wizard.raw_workorder_line_ids), 2)
- self.assertEqual(produce_wizard.raw_workorder_line_ids.filtered(lambda l: l.product_id == p1).qty_reserved, 4)
- self.assertEqual(produce_wizard.raw_workorder_line_ids.filtered(lambda l: l.product_id == p2).qty_reserved, 1)
- produce_wizard.do_produce()
-
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- produce_form.qty_producing = 1
- produce_wizard = produce_form.save()
- # p1 1 1 1
- # p1 3 0 3
- # p2 1 1 1
- self.assertEqual(len(produce_wizard.raw_workorder_line_ids), 3)
- self.assertEqual(sum(produce_wizard.raw_workorder_line_ids.filtered(lambda l: l.product_id == p1).mapped('qty_reserved')), 1)
- self.assertEqual(produce_wizard.raw_workorder_line_ids.filtered(lambda l: l.product_id == p1 and l.qty_reserved).qty_to_consume, 1)
- self.assertEqual(produce_wizard.raw_workorder_line_ids.filtered(lambda l: l.product_id == p1 and not l.qty_reserved).qty_to_consume, 3)
- self.assertEqual(produce_wizard.raw_workorder_line_ids.filtered(lambda l: l.product_id == p2).qty_reserved, 1)
-
- with Form(produce_wizard) as produce_form:
- produce_form.qty_producing = 2
- # p1 1 1 1
- # p1 7 0 7
- # p2 1 1 1
- # p2 1 0 1
- self.assertEqual(len(produce_wizard.raw_workorder_line_ids), 4)
- self.assertEqual(sum(produce_wizard.raw_workorder_line_ids.filtered(lambda l: l.product_id == p1).mapped('qty_reserved')), 1)
- self.assertEqual(produce_wizard.raw_workorder_line_ids.filtered(lambda l: l.product_id == p1 and l.qty_reserved).qty_to_consume, 1)
- self.assertEqual(produce_wizard.raw_workorder_line_ids.filtered(lambda l: l.product_id == p1 and not l.qty_reserved).qty_to_consume, 7)
- self.assertEqual(sum(produce_wizard.raw_workorder_line_ids.filtered(lambda l: l.product_id == p2).mapped('qty_reserved')), 1)
-
- produce_wizard.do_produce()
-
- mo.button_mark_done()
-
- self.assertEqual(self.env['stock.quant']._gather(p1, self.stock_location, strict=True).quantity, -7)
- self.assertEqual(self.env['stock.quant']._gather(p2, self.stock_location, strict=True).quantity, -1)
- self.assertEqual(self.env['stock.quant']._gather(p_final, self.stock_location, strict=True).quantity, 3)
-
def test_product_produce_9(self):
- """ Checks the constraints of a strict BOM without tracking when playing around in the
- produce wizard.
- """
+ """ Checks the constraints of a strict BOM without tracking when playing around
+ quantities to consume."""
self.stock_location = self.env.ref('stock.stock_location_stock')
- mo, bom, p_final, p1, p2 = self.generate_mo()
+ mo, bom, p_final, p1, p2 = self.generate_mo(consumption='strict')
self.assertEqual(len(mo), 1, 'MO should have been created')
self.env['stock.quant']._update_available_quantity(p1, self.stock_location, 100)
@@ -803,52 +623,22 @@ class TestMrpOrder(TestMrpCommon):
mo.action_assign()
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
+ mo_form = Form(mo.with_context({'debug': True}))
with self.assertRaises(UserError):
# try adding another line for a bom product to increase the quantity
- produce_form.qty_producing = 1
- with produce_form.raw_workorder_line_ids.new() as line:
- line.product_id = p1
- line.qty_done = 1
- product_produce = produce_form.save()
- product_produce.do_produce()
+ mo_form.qty_producing = 1
+ with mo_form.move_raw_ids.new() as move:
+ move.product_id = p1
+ move.quantity_done = 1
+ mo = mo_form.save()
+ mo.button_mark_done()
with self.assertRaises(UserError):
# Try updating qty_done
- product_produce = produce_form.save()
- product_produce.raw_workorder_line_ids[0].qty_done += 1
- product_produce.do_produce()
-
- with self.assertRaises(UserError):
- # try adding another product
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- produce_form.qty_producing = 1
- with produce_form.raw_workorder_line_ids.new() as line:
- line.product_id = self.product_4
- line.qty_done = 1
- product_produce = produce_form.save()
- product_produce.do_produce()
-
- # try adding another line for a bom product but the total quantity is good
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- produce_form.qty_producing = 1
-
- with produce_form.raw_workorder_line_ids.new() as line:
- line.product_id = p1
- line.qty_done = 1
- product_produce = produce_form.save()
- product_produce.raw_workorder_line_ids[1].qty_done -= 1
- product_produce.do_produce()
+ mo = mo_form.save()
+ mo.move_raw_ids[0].move_line_ids[0].qty_done += 1
+ mo.button_mark_done()
def test_product_produce_10(self):
""" Produce byproduct with serial, lot and not tracked.
@@ -1027,43 +817,39 @@ class TestMrpOrder(TestMrpCommon):
mo.bom_id.consumption = 'flexible' # Because we'll over-consume with a product not defined in the BOM
mo.action_assign()
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- produce_form.qty_producing = 3
- self.assertEqual(len(produce_form.raw_workorder_line_ids._records), 4, 'Update the produce quantity should change the components quantity.')
- self.assertEqual(sum([x['qty_done'] for x in produce_form.raw_workorder_line_ids._records]), 15, 'Update the produce quantity should change the components quantity.')
- self.assertEqual(sum([x['qty_reserved'] for x in produce_form.raw_workorder_line_ids._records]), 5, 'Update the produce quantity should not change the components reserved quantity.')
- produce_form.qty_producing = 4
- self.assertEqual(len(produce_form.raw_workorder_line_ids._records), 4, 'Update the produce quantity should change the components quantity.')
- self.assertEqual(sum([x['qty_done'] for x in produce_form.raw_workorder_line_ids._records]), 20, 'Update the produce quantity should change the components quantity.')
- self.assertEqual(sum([x['qty_reserved'] for x in produce_form.raw_workorder_line_ids._records]), 5, 'Update the produce quantity should not change the components reserved quantity.')
-
- produce_form.qty_producing = 1
- self.assertEqual(len(produce_form.raw_workorder_line_ids._records), 2, 'Update the produce quantity should change the components quantity.')
- self.assertEqual(sum([x['qty_done'] for x in produce_form.raw_workorder_line_ids._records]), 5, 'Update the produce quantity should change the components quantity.')
- self.assertEqual(sum([x['qty_reserved'] for x in produce_form.raw_workorder_line_ids._records]), 5, 'Update the produce quantity should not change the components reserved quantity.')
+ mo_form = Form(mo.with_context({'debug': True}))
+ mo_form.qty_producing = 3
+ self.assertEqual(sum([x['quantity_done'] for x in mo_form.move_raw_ids._records]), 15, 'Update the produce quantity should change the components quantity.')
+ self.assertEqual(sum([x['reserved_availability'] for x in mo_form.move_raw_ids._records]), 5, 'Update the produce quantity should not change the components reserved quantity.')
+ mo_form.qty_producing = 4
+ self.assertEqual(sum([x['quantity_done'] for x in mo_form.move_raw_ids._records]), 20, 'Update the produce quantity should change the components quantity.')
+ self.assertEqual(sum([x['reserved_availability'] for x in mo_form.move_raw_ids._records]), 5, 'Update the produce quantity should not change the components reserved quantity.')
+ mo_form.qty_producing = 1
+ self.assertEqual(sum([x['quantity_done'] for x in mo_form.move_raw_ids._records]), 5, 'Update the produce quantity should change the components quantity.')
+ self.assertEqual(sum([x['reserved_availability'] for x in mo_form.move_raw_ids._records]), 5, 'Update the produce quantity should not change the components reserved quantity.')
# try adding another product that doesn't belong to the BoM
- with produce_form.raw_workorder_line_ids.new() as line:
- line.product_id = self.product_4
- line.qty_done = 1
- produce_wizard = produce_form.save()
- produce_wizard.do_produce()
+ with mo_form.move_raw_ids.new() as move:
+ move.product_id = self.product_4
+ move.quantity_done = 10
+ # Check that this new product is not updated by qty_producing
+ mo_form.qty_producing = 2
+ for move in mo_form.move_raw_ids._records:
+ if move['product_id'] == self.product_4.id:
+ self.assertEqual(move['quantity_done'], 10)
+ break
+ mo = mo_form.save()
+ mo.button_mark_done()
def test_product_produce_duplicate_1(self):
""" produce a finished product tracked by serial number 2 times with the
same SN. Check that an error is raised the second time"""
mo1, bom, p_final, p1, p2 = self.generate_mo(tracking_final='serial', qty_final=1, qty_base_1=1,)
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo1.id,
- 'active_ids': [mo1.id],
- }))
- product_produce = produce_form.save()
- product_produce.action_generate_serial()
- sn = product_produce.finished_lot_id
- product_produce.do_produce()
+ mo_form = Form(mo1)
+ mo_form.qty_producing = 1
+ mo1 = mo_form.save()
+ mo1.action_generate_serial()
+ sn = mo1.lot_producing_id
mo1.button_mark_done()
mo_form = Form(self.env['mrp.production'])
@@ -1073,14 +859,11 @@ class TestMrpOrder(TestMrpCommon):
mo2 = mo_form.save()
mo2.action_confirm()
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo2.id,
- 'active_ids': [mo2.id],
- }))
- produce_form.finished_lot_id = sn
- product_produce = produce_form.save()
+ mo_form = Form(mo2)
+ mo_form.lot_producing_id = sn
+ mo2 = mo_form.save()
with self.assertRaises(UserError):
- product_produce.do_produce()
+ mo2.button_mark_done()
def test_product_produce_duplicate_2(self):
""" produce a finished product with component tracked by serial number 2
@@ -1091,14 +874,13 @@ class TestMrpOrder(TestMrpCommon):
'product_id': p2.id,
'company_id': self.env.company.id,
})
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo1.id,
- 'active_ids': [mo1.id],
- }))
- with produce_form.raw_workorder_line_ids.edit(0) as line:
- line.lot_id = sn
- product_produce = produce_form.save()
- product_produce.do_produce()
+ mo_form = Form(mo1)
+ mo_form.qty_producing = 1
+ mo1 = mo_form.save()
+ details_operation_form = Form(mo1.move_raw_ids[0], view=self.env.ref('stock.view_stock_move_operations'))
+ with details_operation_form.move_line_ids.new() as ml:
+ ml.lot_id = sn
+ details_operation_form.save()
mo1.button_mark_done()
mo_form = Form(self.env['mrp.production'])
@@ -1108,15 +890,15 @@ class TestMrpOrder(TestMrpCommon):
mo2 = mo_form.save()
mo2.action_confirm()
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo2.id,
- 'active_ids': [mo2.id],
- }))
- with produce_form.raw_workorder_line_ids.edit(0) as line:
- line.lot_id = sn
- product_produce = produce_form.save()
+ mo_form = Form(mo2)
+ mo_form.qty_producing = 1
+ mo2 = mo_form.save()
+ details_operation_form = Form(mo2.move_raw_ids[0], view=self.env.ref('stock.view_stock_move_operations'))
+ with details_operation_form.move_line_ids.new() as ml:
+ ml.lot_id = sn
+ details_operation_form.save()
with self.assertRaises(UserError):
- product_produce.do_produce()
+ mo2.button_mark_done()
def test_product_produce_duplicate_3(self):
""" produce a finished product with by-product tracked by serial number 2
@@ -1148,15 +930,15 @@ class TestMrpOrder(TestMrpCommon):
'product_id': byproduct.id,
'company_id': self.env.company.id,
})
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
-
- with produce_form.finished_workorder_line_ids.edit(0) as line:
- line.lot_id = sn
- product_produce = produce_form.save()
- product_produce.do_produce()
+
+ mo_form = Form(mo)
+ mo_form.qty_producing = 1
+ mo = mo_form.save()
+ move_byproduct = mo.move_finished_ids.filtered(lambda m: m.product_id != mo.product_id)
+ details_operation_form = Form(move_byproduct, view=self.env.ref('stock.view_stock_move_operations'))
+ with details_operation_form.move_line_ids.new() as ml:
+ ml.lot_id = sn
+ details_operation_form.save()
mo.button_mark_done()
mo_form = Form(self.env['mrp.production'])
@@ -1166,15 +948,16 @@ class TestMrpOrder(TestMrpCommon):
mo2 = mo_form.save()
mo2.action_confirm()
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo2.id,
- 'active_ids': [mo2.id],
- }))
- with produce_form.finished_workorder_line_ids.edit(0) as line:
- line.lot_id = sn
- product_produce = produce_form.save()
+ mo_form = Form(mo2)
+ mo_form.qty_producing = 1
+ mo2 = mo_form.save()
+ move_byproduct = mo2.move_finished_ids.filtered(lambda m: m.product_id != mo.product_id)
+ details_operation_form = Form(move_byproduct, view=self.env.ref('stock.view_stock_move_operations'))
+ with details_operation_form.move_line_ids.new() as ml:
+ ml.lot_id = sn
+ details_operation_form.save()
with self.assertRaises(UserError):
- product_produce.do_produce()
+ mo2.button_mark_done()
def test_product_produce_duplicate_4(self):
""" Consuming the same serial number two times should not give an error if
@@ -1185,14 +968,13 @@ class TestMrpOrder(TestMrpCommon):
'product_id': p2.id,
'company_id': self.env.company.id,
})
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo1.id,
- 'active_ids': [mo1.id],
- }))
- with produce_form.raw_workorder_line_ids.edit(0) as line:
- line.lot_id = sn
- product_produce = produce_form.save()
- product_produce.do_produce()
+ mo_form = Form(mo1)
+ mo_form.qty_producing = 1
+ mo1 = mo_form.save()
+ details_operation_form = Form(mo1.move_raw_ids[0], view=self.env.ref('stock.view_stock_move_operations'))
+ with details_operation_form.move_line_ids.new() as ml:
+ ml.lot_id = sn
+ details_operation_form.save()
mo1.button_mark_done()
unbuild_form = Form(self.env['mrp.unbuild'])
@@ -1210,15 +992,15 @@ class TestMrpOrder(TestMrpCommon):
mo2 = mo_form.save()
mo2.action_confirm()
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo2.id,
- 'active_ids': [mo2.id],
- }))
- with produce_form.raw_workorder_line_ids.edit(0) as line:
- line.lot_id = sn
- product_produce = produce_form.save()
- product_produce.do_produce()
-
+ mo_form = Form(mo2)
+ mo_form.qty_producing = 1
+ mo2 = mo_form.save()
+ details_operation_form = Form(mo2.move_raw_ids[0], view=self.env.ref('stock.view_stock_move_operations'))
+ with details_operation_form.move_line_ids.new() as ml:
+ ml.lot_id = sn
+ details_operation_form.save()
+ mo2.button_mark_done()
+
def test_product_produce_uom(self):
""" Produce a finished product tracked by serial number. Set another
UoM on the bom. The produce wizard should keep the UoM of the product (unit)
@@ -1268,86 +1050,20 @@ class TestMrpOrder(TestMrpCommon):
self.assertEqual(mo.move_raw_ids.product_qty, 12, '12 units should be reserved.')
# produce product
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- produce_form.finished_lot_id = final_product_lot
- product_produce = produce_form.save()
- self.assertEqual(product_produce.qty_producing, 1)
- self.assertEqual(product_produce.product_uom_id, unit, 'Should be 1 unit since the tracking is serial.')
- product_produce.finished_lot_id = final_product_lot.id
-
- product_produce.do_produce()
+ mo_form = Form(mo)
+ mo_form.qty_producing = 1/12.0
+ mo_form.lot_producing_id = final_product_lot
+ mo = mo_form.save()
+
move_line_raw = mo.move_raw_ids.mapped('move_line_ids').filtered(lambda m: m.qty_done)
self.assertEqual(move_line_raw.qty_done, 1)
self.assertEqual(move_line_raw.product_uom_id, unit, 'Should be 1 unit since the tracking is serial.')
+ mo._post_inventory()
move_line_finished = mo.move_finished_ids.mapped('move_line_ids').filtered(lambda m: m.qty_done)
self.assertEqual(move_line_finished.qty_done, 1)
self.assertEqual(move_line_finished.product_uom_id, unit, 'Should be 1 unit since the tracking is serial.')
- def test_product_produce_uom_2(self):
- """ Create a bom with a serial tracked component and a pair UoM (2 x unit).
- The produce wizard should create 2 line with quantity = 1 and UoM = unit for
- this component. """
-
- unit = self.env.ref("uom.product_uom_unit")
- categ_unit_id = self.env.ref('uom.product_uom_categ_unit')
- paire = self.env['uom.uom'].create({
- 'name': 'Paire',
- 'factor_inv': 2,
- 'uom_type': 'bigger',
- 'rounding': 0.001,
- 'category_id': categ_unit_id.id
- })
- binocular = self.env['product.product'].create({
- 'name': 'Binocular',
- 'type': 'product',
- 'uom_id': unit.id,
- 'uom_po_id': unit.id
- })
- nocular = self.env['product.product'].create({
- 'name': 'Nocular',
- 'type': 'product',
- 'tracking': 'serial',
- 'uom_id': unit.id,
- 'uom_po_id': unit.id
- })
- bom_binocular = self.env['mrp.bom'].create({
- 'product_tmpl_id': binocular.product_tmpl_id.id,
- 'product_qty': 1,
- 'product_uom_id': unit.id,
- 'bom_line_ids': [(0, 0, {
- 'product_id': nocular.id,
- 'product_qty': 1,
- 'product_uom_id': paire.id
- })]
- })
- mo_form = Form(self.env['mrp.production'])
- mo_form.product_id = binocular
- mo_form.bom_id = bom_binocular
- mo_form.product_uom_id = unit
- mo_form.product_qty = 1
- mo = mo_form.save()
-
- mo.action_confirm()
- self.assertEqual(mo.move_raw_ids.product_uom_qty, 1, 'Quantity should be 1.')
- self.assertEqual(mo.move_raw_ids.product_uom, paire, 'Move UoM should be "Paire".')
-
- # produce product
- produce_form = Form(self.env['mrp.product.produce'].with_context({
- 'active_id': mo.id,
- 'active_ids': [mo.id],
- }))
- product_produce = produce_form.save()
- self.assertEqual(product_produce.qty_producing, 1)
- self.assertEqual(len(product_produce.raw_workorder_line_ids), 2, 'Should be 2 lines since the component tracking is serial and quantity 2.')
- self.assertEqual(product_produce.raw_workorder_line_ids[0].qty_to_consume, 1, 'Should be 1 unit since the tracking is serial and quantity 2.')
- self.assertEqual(product_produce.raw_workorder_line_ids[0].product_uom_id, unit, 'Should be the product uom so "unit"')
- self.assertEqual(product_produce.raw_workorder_line_ids[1].qty_to_consume, 1, 'Should be 1 unit since the tracking is serial and quantity 2.')
- self.assertEqual(product_produce.raw_workorder_line_ids[1].product_uom_id, unit, 'should be the product uom so "unit"')
-
def test_product_type_service_1(self):
# Create finished product
finished_product = self.env['product.product'].create({