[WIP] Add _get_route_domain for finding suitable rules in purchase/mrp when stock_loc...
authorJosse Colpaert <jco@openerp.com>
Fri, 12 Jul 2013 08:37:40 +0000 (10:37 +0200)
committerJosse Colpaert <jco@openerp.com>
Fri, 12 Jul 2013 08:37:40 +0000 (10:37 +0200)
bzr revid: jco@openerp.com-20130712083740-hz8um0e208r7jsbi

addons/mrp/procurement.py
addons/procurement/procurement.py
addons/purchase/purchase.py
addons/stock/procurement.py
addons/stock_location/stock_location.py

index 0c761e1..c757b5f 100644 (file)
@@ -47,7 +47,8 @@ class procurement_order(osv.osv):
         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
 
index de92d48..8f8766f 100644 (file)
@@ -166,6 +166,10 @@ class procurement_order(osv.osv):
     #
     # 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.
index 36f50aa..6d68467 100644 (file)
@@ -1039,7 +1039,8 @@ class procurement_order(osv.osv):
         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
 
index 8103cbe..a83a7ed 100644 (file)
@@ -54,7 +54,8 @@ class procurement_order(osv.osv):
         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
 
index 7b896ed..6a18374 100644 (file)
@@ -145,14 +145,19 @@ class procurement_order(osv.osv):
         })
         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'