[FIX] mrp: handle the case of empty routings

Before, when the routing of a production order was empty (no operations),
it got into an inconsistent state (you click on "plan" and nothing happens).

Empty routings were used before to do subcontracting or 2-steps inventeory
(we did not set any operations on the routing but we set a location).

Here, we change the related routing field on the production order into a
calculated field which becomes empty when the routing has no operations.
This way, the "produce" button is displayed (as for production orders
without routing) and working/

This is a temporary patch to workaround the issuein a stable release.
In master, we might remove the location on routing and place it on the
workcenters and put a constraint that does not allow an empty routing.
This commit is contained in:
Josse Colpaert
2017-01-10 18:37:53 +01:00
parent 909ce5175f
commit 2f66e7abde
2 changed files with 23 additions and 5 deletions
+10 -5
View File
@@ -94,7 +94,7 @@ class MrpProduction(models.Model):
help="Bill of Materials allow you to define the list of required raw materials to make a finished product.")
routing_id = fields.Many2one(
'mrp.routing', 'Routing',
readonly=True, related='bom_id.routing_id', store=True,
readonly=True, compute='_compute_routing', store=True,
help="The list of operations (list of work centers) to produce the finished product. The routing "
"is mainly used to compute work center costs during operations and to plan future loads on "
"work centers based on production planning.")
@@ -152,6 +152,15 @@ class MrpProduction(models.Model):
priority = fields.Selection([('0', 'Not urgent'), ('1', 'Normal'), ('2', 'Urgent'), ('3', 'Very Urgent')], 'Priority',
readonly=True, states={'confirmed': [('readonly', False)]}, default='1')
@api.multi
@api.depends('bom_id.routing_id', 'bom_id.routing_id.operation_ids')
def _compute_routing(self):
for production in self:
if production.bom_id.routing_id.operation_ids:
production.routing_id = production.bom_id.routing_id.id
else:
production.routing_id = False
@api.multi
@api.depends('workorder_ids')
def _compute_workorder_count(self):
@@ -243,10 +252,6 @@ class MrpProduction(models.Model):
self.location_src_id = self.picking_type_id.default_location_src_id.id or location.id
self.location_dest_id = self.picking_type_id.default_location_dest_id.id or location.id
@api.onchange('bom_id')
def onchange_bom_id(self):
self.routing_id = self.bom_id.routing_id.id
@api.model
def create(self, values):
if not values.get('name', False) or values['name'] == _('New'):
+13
View File
@@ -332,3 +332,16 @@ class TestMrpOrder(TestMrpCommon):
production_2.action_assign()
# check sub product availability state is assigned
self.assertEqual(production_2.availability, 'assigned', 'Production order should be availability for assigned state')
def test_empty_routing(self):
""" Check what happens when you work with an empty routing"""
routing = self.env['mrp.routing'].create({'name': 'Routing without operations',
'location_id': self.warehouse_1.wh_input_stock_loc_id.id,})
self.bom_3.routing_id = routing.id
production = self.env['mrp.production'].create({'name': 'MO test',
'product_id': self.product_6.id,
'product_qty': 3,
'bom_id': self.bom_3.id,
'product_uom_id': self.product_6.uom_id.id,})
self.assertEqual(production.routing_id.id, False, 'The routing field should be empty on the mo')
self.assertEqual(production.move_raw_ids[0].location_id.id, self.warehouse_1.wh_input_stock_loc_id.id, 'Raw moves start location should have altered.')