[FIX] purchase_requisition: copy method _get_warehouse from purchase module to avoid crash if purchase_requisition is updated but not purchase

bzr revid: chs@openerp.com-20131126180726-ng0gue9pedmuykj9
This commit is contained in:
Christophe Simonis
2013-11-26 19:07:26 +01:00
parent b1b787545b
commit 49fa5cab61
2 changed files with 32 additions and 0 deletions
+3
View File
@@ -1114,6 +1114,9 @@ class procurement_order(osv.osv):
If none match, returns then first warehouse of the company
"""
# TODO refactor the domain once we implement the "parent_of" domain operator
# NOTE This method has been copied in the `purchase_requisition` module to ensure
# retro-compatibility. This code duplication will be deleted in next stable version.
# Do not forget to update both version in case of modification.
company_id = (procurement.company_id or user_company).id
domains = [
[
@@ -236,6 +236,35 @@ class procurement_order(osv.osv):
'requisition_id': fields.many2one('purchase.requisition', 'Latest Requisition')
}
def _get_warehouse(self, procurement, user_company):
"""
Return the warehouse containing the procurment stock location (or one of it ancestors)
If none match, returns then first warehouse of the company
"""
# NOTE This method is a copy of the one on the procurement.order defined in purchase
# module. It's been copied to ensure it been always available, even if module
# purchase is not up to date.
# Do not forget to update both version in case of modification.
company_id = (procurement.company_id or user_company).id
domains = [
[
'&', ('company_id', '=', company_id),
'|', '&', ('lot_stock_id.parent_left', '<', procurement.location_id.parent_left),
('lot_stock_id.parent_right', '>', procurement.location_id.parent_right),
('lot_stock_id', '=', procurement.location_id.id)
],
[('company_id', '=', company_id)]
]
cr, uid = procurement._cr, procurement._uid
context = procurement._context
Warehouse = self.pool['stock.warehouse']
for domain in domains:
ids = Warehouse.search(cr, uid, domain, context=context)
if ids:
return ids[0]
return False
def make_po(self, cr, uid, ids, context=None):
res = {}
requisition_obj = self.pool.get('purchase.requisition')