From a0318270f5f2e3bad409ec857b7469577bc26f7a Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Fri, 12 Jul 2013 18:05:33 +0200 Subject: [PATCH] [WIP] stock_location: if a route is defined on the procurement it has higher priority + refactoring bzr revid: qdp-launchpad@openerp.com-20130712160533-41ts0t6tgorgptdz --- addons/mrp/procurement.py | 7 +------ addons/procurement/procurement.py | 3 --- addons/purchase/purchase.py | 3 +-- addons/stock/procurement.py | 8 +++++--- addons/stock_account/stock_account.py | 2 +- addons/stock_location/stock_location.py | 10 +++++++--- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/addons/mrp/procurement.py b/addons/mrp/procurement.py index 92b8a30ad13..b667f2e075f 100644 --- a/addons/mrp/procurement.py +++ b/addons/mrp/procurement.py @@ -40,15 +40,12 @@ class procurement_order(osv.osv): 'production_id': fields.many2one('mrp.production', 'Manufacturing Order'), } - - def _find_suitable_rule(self, cr, uid, procurement, context=None): rule_id = super(procurement_order, self)._find_suitable_rule(cr, uid, procurement, context=context) 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 self.check_bom_exists(cr, uid, [procurement.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 = self._search_suitable_rule(cr, uid, procurement, [('action', '=', 'manufacture'), ('location_id', '=', procurement.location_id.id)], context=context) rule_id = rule_id and rule_id[0] or False return rule_id @@ -63,8 +60,6 @@ class procurement_order(osv.osv): return True return super(procurement_order, self)._check(cr, uid, procurement, context=context) - - def _prepare_order_line_procurement(self, cr, uid, order, line, move_id, date_planned, context=None): result = super(procurement_order, self)._prepare_order_line_procurement(cr, uid, order, line, move_id, date_planned, context) result['property_ids'] = [(6, 0, [x.id for x in line.property_ids])] diff --git a/addons/procurement/procurement.py b/addons/procurement/procurement.py index 8f8766fcb66..39641033bcc 100644 --- a/addons/procurement/procurement.py +++ b/addons/procurement/procurement.py @@ -167,9 +167,6 @@ 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. diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 6d68467bf50..c5b30f58a77 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -1039,8 +1039,7 @@ 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): - 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 = self._search_suitable_rule(cr, uid, procurement, [('action', '=', 'buy'), ('location_id', '=', procurement.location_id.id)], context=context) rule_id = rule_id and rule_id[0] or False return rule_id diff --git a/addons/stock/procurement.py b/addons/stock/procurement.py index a83a7edf0d9..6b68fdf0d69 100644 --- a/addons/stock/procurement.py +++ b/addons/stock/procurement.py @@ -50,12 +50,14 @@ class procurement_order(osv.osv): 'move_dest_id': fields.many2one('stock.move', 'Destination Move', help="Move which caused (created) the procurement") } + def _search_suitable_rule(self, cr, uid, procurement, domain, context=None): + '''method overwritten in stock_location that is used to search the best suitable rule''' + return self.pool.get('procurement.rule').search(cr, uid, domain, context=context) + def _find_suitable_rule(self, cr, uid, procurement, context=None): res = super(procurement_order, self)._find_suitable_rule(cr, uid, procurement, context=context) if not res: - rule_obj = self.pool.get('procurement.rule') - 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 = self._search_suitable_rule(cr, uid, procurement, [('action', '=', 'move'), ('location_id', '=', procurement.location_id.id)], context=context) res = res and res[0] or False return res diff --git a/addons/stock_account/stock_account.py b/addons/stock_account/stock_account.py index 8079c7fc722..57199037287 100644 --- a/addons/stock_account/stock_account.py +++ b/addons/stock_account/stock_account.py @@ -80,7 +80,7 @@ class stock_quant(osv.osv): if company_from == company_to: return False - journal_id, acc_src, acc_dest, acc_valuation = self._get_accounting_data_fir_valuation(cr, uid, move, context=context) + journal_id, acc_src, acc_dest, acc_valuation = self._get_accounting_data_for_valuation(cr, uid, move, context=context) account_moves = [] # Create Journal Entry for products arriving in the company if company_to: diff --git a/addons/stock_location/stock_location.py b/addons/stock_location/stock_location.py index 11586535dc2..a2ac62679f3 100644 --- a/addons/stock_location/stock_location.py +++ b/addons/stock_location/stock_location.py @@ -145,10 +145,14 @@ class procurement_order(osv.osv): }) return d - - def _get_route_domain(self, cr, uid, procurement, context=None): + def _search_suitable_rule(self, cr, uid, procurement, domain, context=None): + '''we try to first find a rule among the ones defined on the procurement order and if none is find, we fallback on the default behavior''' route_ids = [x.id for x in procurement.product_id.route_ids] - return [('route_id', 'in', route_ids)] + res = super(procurement_order, self)._search_suitable_rule(cr, uid, procurement, domain + [('route_id', 'in', route_ids)], context=context) + if not res: + return super(procurement_order, self)._search_suitable_rule(cr, uid, procurement, domain, context=context) + return res + class product_putaway_strategy(osv.osv): _name = 'product.putaway'