diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index a06bff14fcd..83758b5656f 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -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 diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index c1e758f2871..d09c3980fe3 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -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): diff --git a/addons/mrp/models/stock_rule.py b/addons/mrp/models/stock_rule.py index a003063d9bd..c081bacc8b9 100644 --- a/addons/mrp/models/stock_rule.py +++ b/addons/mrp/models/stock_rule.py @@ -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, diff --git a/addons/mrp/tests/test_procurement.py b/addons/mrp/tests/test_procurement.py index 0fb99e5570c..e398f43e714 100644 --- a/addons/mrp/tests/test_procurement.py +++ b/addons/mrp/tests/test_procurement.py @@ -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)