diff --git a/addons/mrp/models/stock_rule.py b/addons/mrp/models/stock_rule.py index b9a285c5c4a..4e12750ca4d 100644 --- a/addons/mrp/models/stock_rule.py +++ b/addons/mrp/models/stock_rule.py @@ -53,7 +53,7 @@ class StockRule(models.Model): # create the MO as SUPERUSER because the current user may not have the rights to do it (mto product launched by a sale for example) productions = self.env['mrp.production'].sudo().with_company(company_id).create(productions_values) self.env['stock.move'].sudo().create(productions._get_moves_raw_values()) - productions.action_confirm() + productions.filtered(lambda p: p.move_raw_ids).action_confirm() for production in productions: origin_production = production.move_dest_ids and production.move_dest_ids[0].raw_material_production_id or False diff --git a/addons/mrp/tests/test_procurement.py b/addons/mrp/tests/test_procurement.py index e398f43e714..f74ed52c1f4 100644 --- a/addons/mrp/tests/test_procurement.py +++ b/addons/mrp/tests/test_procurement.py @@ -305,3 +305,55 @@ class TestProcurement(TestMrpCommon): self.assertTrue(child_mrp_production.delay_alert) self.assertTrue(child_mrp_production.move_raw_ids.delay_alert) + + def test_procurement_with_empty_bom(self): + """Ensure that a procurement request using a product with an empty BoM + will create a MO in draft state that could be completed afterwards. + """ + self.warehouse = self.env.ref('stock.warehouse0') + route_manufacture = self.warehouse.manufacture_pull_id.route_id.id + route_mto = self.warehouse.mto_pull_id.route_id.id + product = self.env['product.product'].create({ + 'name': 'Clafoutis', + 'route_ids': [(6, 0, [route_manufacture, route_mto])] + }) + self.env['mrp.bom'].create({ + 'product_id': product.id, + 'product_tmpl_id': product.product_tmpl_id.id, + 'product_uom_id': self.uom_unit.id, + 'product_qty': 1.0, + 'type': 'normal', + }) + move_dest = self.env['stock.move'].create({ + 'name': 'Customer MTO Move', + 'product_id': product.id, + 'product_uom': self.ref('uom.product_uom_unit'), + '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() + + production = self.env['mrp.production'].search([('product_id', '=', product.id)]) + self.assertTrue(production) + self.assertFalse(production.move_raw_ids) + self.assertEqual(production.state, 'draft') + + comp1 = self.env['product.product'].create({ + 'name': 'egg', + }) + move_values = production._get_move_raw_values(comp1, 40.0, self.env.ref('uom.product_uom_unit')) + self.env['stock.move'].create(move_values) + + production.action_confirm() + produce_form = Form(self.env['mrp.product.produce'].with_context({ + 'active_id': production.id, + 'active_ids': [production.id], + })) + product_produce = produce_form.save() + product_produce.do_produce() + production.button_mark_done() + + move_dest._action_assign() + self.assertEqual(move_dest.reserved_availability, 10.0) diff --git a/addons/sale_mrp/tests/test_sale_mrp_flow.py b/addons/sale_mrp/tests/test_sale_mrp_flow.py index d014b9d80ba..870869da553 100644 --- a/addons/sale_mrp/tests/test_sale_mrp_flow.py +++ b/addons/sale_mrp/tests/test_sale_mrp_flow.py @@ -1534,8 +1534,7 @@ class TestSaleMrpFlow(AccountTestCommon): line.price_unit = 10.0 sale_order = sale_form.save() - with self.assertRaises(UserError): - sale_order.action_confirm() + sale_order.action_confirm() mo = self.env['mrp.production'].search([('product_id', '=', finished_product.id)])