Skip to content
Snippets Groups Projects
Commit 7c501e4b authored by amoyaux's avatar amoyaux
Browse files

[FIX] mrp: product produce line fail with consumed SN

Use case to reproduce:
- Create a product with a BOM needing one component tracked by SN
- Create a MO for this product with 2 to produce
- Produce 1
- Produce the other -> 2 lines and a wrong lot proposed

This happens when the quantity to consume is equal to 0
or if the qty_done on a move_line is equal to the reserved
quantity.

This commit change the condition after the float_compare in
order to take into account the equal comparison.
parent 7dfcbc6b
No related branches found
No related tags found
No related merge requests found
......@@ -458,3 +458,61 @@ class TestMrpOrder(TestMrpCommon):
produce_wizard.do_produce()
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')
def test_product_produce_1(self):
""" Check that no produce line are created when the consumed products are not tracked """
self.stock_location = self.env.ref('stock.stock_location_stock')
mo, bom, p_final, p1, p2 = self.generate_mo()
self.assertEqual(len(mo), 1, 'MO should have been created')
self.env['stock.quant']._update_available_quantity(p1, self.stock_location, 100)
self.env['stock.quant']._update_available_quantity(p2, self.stock_location, 5)
mo.action_assign()
product_produce = self.env['mrp.product.produce'].with_context({
'active_id': mo.id,
'active_ids': [mo.id],
}).create({})
self.assertEqual(len(product_produce.produce_line_ids), 0, 'You should not have any produce lines since the consumed products are not tracked.')
def test_product_produce_2(self):
""" Check that line are created when the consumed products are
tracked by serial and the lot proposed are correct. """
self.stock_location = self.env.ref('stock.stock_location_stock')
mo, bom, p_final, p1, p2 = self.generate_mo(tracking_base_1='serial', qty_base_1=1, qty_final=2)
self.assertEqual(len(mo), 1, 'MO should have been created')
lot_p1_1 = self.env['stock.production.lot'].create({
'name': 'lot1',
'product_id': p1.id,
})
lot_p1_2 = self.env['stock.production.lot'].create({
'name': 'lot2',
'product_id': p1.id,
})
self.env['stock.quant']._update_available_quantity(p1, self.stock_location, 1, lot_id=lot_p1_1)
self.env['stock.quant']._update_available_quantity(p1, self.stock_location, 1, lot_id=lot_p1_2)
self.env['stock.quant']._update_available_quantity(p2, self.stock_location, 5)
mo.action_assign()
product_produce = self.env['mrp.product.produce'].with_context({
'active_id': mo.id,
'active_ids': [mo.id],
}).create({})
self.assertEqual(len(product_produce.produce_line_ids), 2, 'You should have 2 produce lines. One for each serial to consume')
product_produce.product_qty = 1
produce_line_1 = product_produce.produce_line_ids[0]
produce_line_1.qty_done = 1
remaining_lot = (lot_p1_1 | lot_p1_2) - produce_line_1.lot_id
product_produce.do_produce()
product_produce = self.env['mrp.product.produce'].with_context({
'active_id': mo.id,
'active_ids': [mo.id],
}).create({})
self.assertEqual(len(product_produce.produce_line_ids), 1, 'You should have 1 produce lines since one has already be consumed.')
self.assertEqual(product_produce.produce_line_ids[0].lot_id, remaining_lot, 'Wrong lot proposed.')
......@@ -40,9 +40,9 @@ class MrpProductProduce(models.TransientModel):
for move in production.move_raw_ids.filtered(lambda x: (x.product_id.tracking != 'none') and x.state not in ('done', 'cancel') and x.bom_line_id):
qty_to_consume = todo_quantity / move.bom_line_id.bom_id.product_qty * move.bom_line_id.product_qty
for move_line in move.move_line_ids:
if float_compare(qty_to_consume, 0.0, precision_rounding=move.product_uom.rounding) < 0:
if float_compare(qty_to_consume, 0.0, precision_rounding=move.product_uom.rounding) <= 0:
break
if float_compare(move_line.product_uom_qty, move_line.qty_done, precision_rounding=move.product_uom.rounding) < 0:
if float_compare(move_line.product_uom_qty, move_line.qty_done, precision_rounding=move.product_uom.rounding) <= 0:
continue
to_consume_in_line = min(qty_to_consume, move_line.product_uom_qty)
lines.append({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment