Skip to content

Commit

Permalink
[FIX] purchase_requisition: copy method _get_warehouse from purchase …
Browse files Browse the repository at this point in the history
…module to avoid crash if purchase_requisition is updated but not purchase

bzr revid: [email protected]
  • Loading branch information
KangOl committed Nov 26, 2013
1 parent b1b7875 commit 49fa5ca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions addons/purchase/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,9 @@ def _get_warehouse(self, procurement, user_company):
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 = [
[
Expand Down
29 changes: 29 additions & 0 deletions addons/purchase_requisition/purchase_requisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 49fa5ca

Please sign in to comment.