[FIX] mrp: delivery moves not cancelled

Before this -
If we have follwing configuration -
Manufacturing -> Propagate Cancel -> True
Buy -> Propagate Cancel -> True

* BOM of a Car -
	1) Component 1 -> Iron (MTO & Buy)

Now create a SO of product Car and confirm it.
It will create a MO (Car) and then PO (Iron).
Now if PO is cancelled, it will cancel its
move_dest_ids and on change of it MO will be
cancelled but delivery move will remain ongoing.

When action cancel is called on a move raw, it will
check if the production order is also cancelled.
If the MO is cancel, in this case cancel also its
move finished.

Task-2117832

closes odoo/odoo#42209

X-original-commit: 9522e51a3b290c91f23658a4fb781003ff1fd8d2
Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
This commit is contained in:
Pratima Gupta
2019-12-19 16:45:55 +00:00
committed by Arnold Moyaux
parent 7dfc79252d
commit d255bdbfac
2 changed files with 51 additions and 0 deletions
+8
View File
@@ -198,6 +198,14 @@ class StockMove(models.Model):
self.sudo().unlink()
return processed_moves
def _action_cancel(self):
res = super(StockMove, self)._action_cancel()
for production in self.mapped('raw_material_production_id'):
if production.state != 'cancel':
continue
production._action_cancel()
return res
def _decrease_reserved_quanity(self, quantity):
""" Decrease the reservation on move lines but keeps the
all other data.
+43
View File
@@ -197,3 +197,46 @@ class TestProcurement(TestMrpCommon):
# Adding 5 days to the date planned start makes the next move's date 4 days and 23 hours
# later since the date planned start was set one hour before the date_planned_end.
self.assertAlmostEqual(move_dest.date_expected, move_dest_scheduled_date + timedelta(days=4, hours=23), delta=timedelta(seconds=1), msg='date is not propagated')
def test_finished_move_cancellation(self):
"""Check state of finished move on cancellation of raw moves. """
product_bottle = self.env['product.product'].create({
'name': 'Plastic Bottle',
'route_ids': [(4, self.ref('mrp.route_warehouse0_manufacture'))]
})
component_mold = self.env['product.product'].create({
'name': 'Plastic Mold',
})
self.env['mrp.bom'].create({
'product_id': product_bottle.id,
'product_tmpl_id': product_bottle.product_tmpl_id.id,
'product_uom_id': self.uom_unit.id,
'product_qty': 1.0,
'type': 'normal',
'bom_line_ids': [
(0, 0, {'product_id': component_mold.id, 'product_qty': 1}),
]})
move_dest = self.env['stock.move'].create({
'name': 'move_bottle',
'product_id': product_bottle.id,
'product_uom': self.ref('uom.product_uom_unit'),
'propagate_date': True,
'propagate_date_minimum_delta': 1,
'location_id': self.ref('stock.stock_location_stock'),
'location_dest_id': self.ref('stock.stock_location_output'),
'product_uom_qty': 10,
'procure_method': 'make_to_order',
})
move_dest._action_confirm()
mo = self.env['mrp.production'].search([
('product_id', '=', product_bottle.id),
('state', '=', 'confirmed')
])
mo.move_raw_ids[0]._action_cancel()
self.assertEqual(mo.state, 'cancel', 'Manufacturing order should be cancelled.')
self.assertEqual(mo.move_finished_ids[0].state, 'cancel', 'Finished move should be cancelled if mo is cancelled.')
self.assertEqual(mo.move_dest_ids[0].state, 'waiting', 'Destination move should not be cancelled if prapogation cancel is False on manufacturing rule.')