diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 4a5b2567377..8cae5a1cf15 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -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 = [ [ diff --git a/addons/purchase_requisition/purchase_requisition.py b/addons/purchase_requisition/purchase_requisition.py index c15d145a7cd..c1d80c7bf46 100644 --- a/addons/purchase_requisition/purchase_requisition.py +++ b/addons/purchase_requisition/purchase_requisition.py @@ -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')