if not rule_id:
#if there isn't any specific procurement.rule defined for the product, we try to directly supply it from a supplier
if procurement.product_id.supply_method == 'manufacture' and procurement.product_id.bom_id: #Actually not needed anymore?
- rule_id = self.pool.get('procurement.rule').search(cr, uid, [('action', '=', 'manufacture'), ('location_id', '=', procurement.location_id.id)], context=context)
+ domain = [('action', '=', 'manufacture'), ('location_id', '=', procurement.location_id.id)] + self._get_route_domain(cr, uid, procurement, context=context)
+ rule_id = self.pool.get('procurement.rule').search(cr, uid, domain, context=context)
rule_id = rule_id and rule_id[0] or False
return rule_id
#
# Method to overwrite in different procurement modules
#
+
+ def _get_route_domain(self, cr, uid, procurement, context=None):
+ return []
+
def _find_suitable_rule(self, cr, uid, procurement, context=None):
'''This method returns a procurement.rule that depicts what to do with the given procurement
in order to complete its needs. It returns False if no suiting rule is found.
if not rule_id:
#if there isn't any specific procurement.rule defined for the product, we try to directly supply it from a supplier
if procurement.product_id.supply_method == 'buy' and self._check_supplier_info(cr, uid, [procurement.id], context=context):
- rule_id = self.pool.get('procurement.rule').search(cr, uid, [('action', '=', 'buy'), ('location_id', '=', procurement.location_id.id)], context=context)
+ domain = [('action', '=', 'buy'), ('location_id', '=', procurement.location_id.id)] + self._get_route_domain(cr, uid, procurement, context=context)
+ rule_id = self.pool.get('procurement.rule').search(cr, uid, domain, context=context)
rule_id = rule_id and rule_id[0] or False
return rule_id
res = super(procurement_order, self)._find_suitable_rule(cr, uid, procurement, context=context)
if not res:
rule_obj = self.pool.get('procurement.rule')
- res = rule_obj.search(cr, uid, [('location_id', '=', procurement.location_id.id)], context=context)
+ domain = [('location_id', '=', procurement.location_id.id)] + self._get_route_domain(cr, uid, procurement, context=context)
+ res = rule_obj.search(cr, uid, domain, context=context)
res = res and res[0] or False
return res
})
return d
- # TODO: implement using routes on products
- def _find_suitable_rule(self, cr, uid, procurement, context=None):
- res = False
- if procurement.location_id:
- rule_obj = self.pool.get('procurement.rule')
- route_ids = [x.id for x in procurement.product_id.route_ids]
- res = rule_obj.search(cr, uid, [('location_id', '=', procurement.location_id.id), ('route_id', 'in', route_ids), ], context=context)
- return res and res[0] or super(procurement_order, self)._find_suitable_rule(cr, uid, procurement, context=context)
+# # TODO: implement using routes on products
+# def _find_suitable_rule(self, cr, uid, procurement, context=None):
+# res = False
+# if procurement.location_id:
+# rule_obj = self.pool.get('procurement.rule')
+# route_ids = [x.id for x in procurement.product_id.route_ids]
+# res = rule_obj.search(cr, uid, [('location_id', '=', procurement.location_id.id), ('route_id', 'in', route_ids), ], context=context)
+# return res and res[0] or super(procurement_order, self)._find_suitable_rule(cr, uid, procurement, context=context)
+
+
+ def _get_route_domain(self, cr, uid, procurement, context=None):
+ route_ids = [x.id for x in procurement.product_id.route_ids]
+ return [('route_id', 'in', route_ids)]
class product_putaway_strategy(osv.osv):
_name = 'product.putaway'