[IMP] mrp: Make it possible to define a rule from stock > production to use the correct procure method

It is very cumbersome to define routes which have 2 step in on production for certain products with
procurement rules (e.g. Stock > Raw Materials Location > Production), when the
products are MTS elsewhere.  That is why we add the possibility, which might be elaborated in the future,
to define rules e.g. from Stock > Production, which you can put on the product / product categories.  These
rules will only define the procure_method for now.
This commit is contained in:
Josse Colpaert 2015-03-12 10:46:19 +01:00
parent 8eb62ca282
commit 06909462b1
1 changed files with 20 additions and 5 deletions

View File

@ -1076,14 +1076,27 @@ class mrp_production(osv.osv):
#is 1 element long, so we can take the first.
return stock_move.action_confirm(cr, uid, [move_id], context=context)[0]
def _get_raw_material_procure_method(self, cr, uid, product, context=None):
'''This method returns the procure_method to use when creating the stock move for the production raw materials'''
def _get_raw_material_procure_method(self, cr, uid, product, location_id=False, location_dest_id=False, context=None):
'''This method returns the procure_method to use when creating the stock move for the production raw materials
Besides the standard configuration of looking if the product or product category has the MTO route,
you can also define a rule e.g. from Stock to Production (which might be used in the future like the sale orders)
'''
warehouse_obj = self.pool['stock.warehouse']
routes = product.route_ids + product.categ_id.total_route_ids
if location_id and location_dest_id:
pull_obj = self.pool['procurement.rule']
pulls = pull_obj.search(cr, uid, [('route_id', 'in', [x.id for x in routes]),
('location_id', '=', location_dest_id),
('location_src_id', '=', location_id)], limit=1, context=context)
if pulls:
return pull_obj.browse(cr, uid, pulls[0], context=context).procure_method
try:
mto_route = warehouse_obj._get_mto_route(cr, uid, context=context)
except:
return "make_to_stock"
routes = product.route_ids + product.categ_id.total_route_ids
if mto_route in [x.id for x in routes]:
return "make_to_order"
return "make_to_stock"
@ -1115,7 +1128,8 @@ class mrp_production(osv.osv):
move = stock_move.copy(cr, uid, move_id, default = {
'location_id': source_location_id,
'location_dest_id': dest_location_id,
'procure_method': self._get_raw_material_procure_method(cr, uid, product, context=context),
'procure_method': self._get_raw_material_procure_method(cr, uid, product, location_id=source_location_id,
location_dest_id=dest_location_id, context=context),
'raw_material_production_id': False,
'move_dest_id': move_id,
'picking_type_id': types and types[0] or False,
@ -1148,7 +1162,8 @@ class mrp_production(osv.osv):
'location_id': source_location_id,
'location_dest_id': destination_location_id,
'company_id': production.company_id.id,
'procure_method': prev_move and 'make_to_stock' or self._get_raw_material_procure_method(cr, uid, product, context=context), #Make_to_stock avoids creating procurement
'procure_method': prev_move and 'make_to_stock' or self._get_raw_material_procure_method(cr, uid, product, location_id=source_location_id,
location_dest_id=destination_location_id, context=context), #Make_to_stock avoids creating procurement
'raw_material_production_id': production.id,
#this saves us a browse in create()
'price_unit': product.standard_price,