[WIP] stock_location: if a route is defined on the procurement it has higher priority + refactoring
bzr revid: qdp-launchpad@openerp.com-20130712160533-41ts0t6tgorgptdz
This commit is contained in:
parent
a78ad15df1
commit
a0318270f5
|
@ -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])]
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue