[FIX] mrp: delay_alert and manufacturing order
When a manufacturing order was created through a stock rule, the `delay_alert` feature was broken. Indeed, we should store on the order the `delay_alert` value similar to what we do with the `propagate_date`, `propagate_date_minimum_delta` and `propagate_cancel` fields. We thus add the missing field and add the values in the multiple prepare methods. We also the missing values for `propagate_date_minimum_delta` and `propagate_date` in `_get_move_raw_values`. task-2154781 closes odoo/odoo#42032 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
@@ -208,6 +208,7 @@ class MrpProduction(models.Model):
|
||||
propagate_cancel = fields.Boolean(
|
||||
'Propagate cancel and split',
|
||||
help='If checked, when the previous move of the move (which was generated by a next procurement) is cancelled or split, the move generated by this move will too')
|
||||
delay_alert = fields.Boolean(string='Delay alert')
|
||||
propagate_date = fields.Boolean(string="Propagate Rescheduling",
|
||||
help='The rescheduling is propagated to the next move.')
|
||||
propagate_date_minimum_delta = fields.Integer(string='Reschedule if Higher Than',
|
||||
@@ -552,6 +553,7 @@ class MrpProduction(models.Model):
|
||||
'group_id': self.procurement_group_id.id,
|
||||
'propagate_cancel': self.propagate_cancel,
|
||||
'propagate_date': self.propagate_date,
|
||||
'delay_alert': self.delay_alert,
|
||||
'propagate_date_minimum_delta': self.propagate_date_minimum_delta,
|
||||
'move_dest_ids': [(4, x.id) for x in self.move_dest_ids],
|
||||
}
|
||||
@@ -614,6 +616,9 @@ class MrpProduction(models.Model):
|
||||
'warehouse_id': source_location.get_warehouse().id,
|
||||
'group_id': self.procurement_group_id.id,
|
||||
'propagate_cancel': self.propagate_cancel,
|
||||
'propagate_date': self.propagate_date,
|
||||
'propagate_date_minimum_delta': self.propagate_date_minimum_delta,
|
||||
'delay_alert': self.delay_alert
|
||||
}
|
||||
return data
|
||||
|
||||
|
||||
@@ -251,7 +251,7 @@ class StockMove(models.Model):
|
||||
|
||||
def _delay_alert_get_documents(self):
|
||||
res = super(StockMove, self)._delay_alert_get_documents()
|
||||
productions = self.mapped('raw_material_production_id')
|
||||
productions = self.raw_material_production_id | self.production_id
|
||||
return res + list(productions)
|
||||
|
||||
def _should_be_assigned(self):
|
||||
|
||||
@@ -86,6 +86,7 @@ class StockRule(models.Model):
|
||||
'date_planned_finished': date_deadline,
|
||||
'date_planned_start': fields.Datetime.from_string(date_deadline) - relativedelta(hours=1),
|
||||
'procurement_group_id': False,
|
||||
'delay_alert': self.delay_alert,
|
||||
'propagate_cancel': self.propagate_cancel,
|
||||
'propagate_date': self.propagate_date,
|
||||
'propagate_date_minimum_delta': self.propagate_date_minimum_delta,
|
||||
|
||||
@@ -247,3 +247,61 @@ class TestProcurement(TestMrpCommon):
|
||||
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.')
|
||||
|
||||
def test_production_delay_alert(self):
|
||||
"""Check if the delay alert is set to True on the stock move."""
|
||||
self.env['stock.rule'].search([]).delay_alert = True
|
||||
|
||||
parent_product = self.env['product.template'].create({
|
||||
'name': 'Parent product',
|
||||
'route_ids': [
|
||||
(4, self.env.ref('mrp.route_warehouse0_manufacture').id, 0),
|
||||
(4, self.env.ref('stock.route_warehouse0_mto').id, 0)
|
||||
]
|
||||
})
|
||||
child_product = self.env['product.template'].create({
|
||||
'name': 'Child product',
|
||||
'route_ids': [
|
||||
(4, self.env.ref('mrp.route_warehouse0_manufacture').id, 0),
|
||||
(4, self.env.ref('stock.route_warehouse0_mto').id, 0)
|
||||
]
|
||||
})
|
||||
child_component = self.env['product.template'].create({
|
||||
'name': 'Child product',
|
||||
})
|
||||
parent_bom = self.env['mrp.bom'].create({
|
||||
'product_id': parent_product.product_variant_ids.id,
|
||||
'product_tmpl_id': parent_product.id,
|
||||
'product_uom_id': self.uom_unit.id,
|
||||
'product_qty': 4.0,
|
||||
'routing_id': self.routing_2.id,
|
||||
'type': 'normal',
|
||||
})
|
||||
self.env['mrp.bom.line'].create({
|
||||
'bom_id': parent_bom.id,
|
||||
'product_id': child_product.product_variant_ids.id,
|
||||
'product_qty': 2,
|
||||
})
|
||||
child_bom = self.env['mrp.bom'].create({
|
||||
'product_id': child_product.product_variant_ids.id,
|
||||
'product_tmpl_id': child_product.id,
|
||||
'product_uom_id': self.uom_unit.id,
|
||||
'product_qty': 4.0,
|
||||
'routing_id': self.routing_2.id,
|
||||
'type': 'normal',
|
||||
})
|
||||
self.env['mrp.bom.line'].create({
|
||||
'bom_id': child_bom.id,
|
||||
'product_id': child_component.product_variant_ids.id,
|
||||
'product_qty': 2,
|
||||
})
|
||||
|
||||
mrp_order_form = Form(self.env['mrp.production'])
|
||||
mrp_order_form.product_id = parent_product.product_variant_ids
|
||||
mrp_order = mrp_order_form.save()
|
||||
mrp_order.action_confirm()
|
||||
|
||||
child_mrp_production = self.env['mrp.production'].search([('product_id', '=', child_product.product_variant_ids.id)])
|
||||
|
||||
self.assertTrue(child_mrp_production.delay_alert)
|
||||
self.assertTrue(child_mrp_production.move_raw_ids.delay_alert)
|
||||
|
||||
Reference in New Issue
Block a user