[IMP] mrp: procurement with service BoM
Previously when the BoM on a product do not have components but only services. Then during scheduler a log was posted on the product explaining that components are required. However since this process is possible in another usecase it should be possible with procurement. The only difference is that procurements confirm records in order to propagate. In this case since there is no components and services are not propagate with procurements, it's not needed to confirm the MO. closes odoo/odoo#43133 Task: 2170845 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user