From cd146676052be7382c217f5aaa7a78356f55c31f Mon Sep 17 00:00:00 2001 From: Wolfgang Taferner Date: Wed, 9 Aug 2023 08:17:17 +0000 Subject: [PATCH] [IMP] sale_purchase: give the possibility to inject a partner closes odoo/odoo#131399 X-original-commit: 3631c5c1e143a1634a392c510b27d1b222e68912 Signed-off-by: William Henrotin (whe) --- addons/sale_purchase/models/sale_order_line.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/sale_purchase/models/sale_order_line.py b/addons/sale_purchase/models/sale_order_line.py index c7ae04794b3..76796327d6d 100644 --- a/addons/sale_purchase/models/sale_order_line.py +++ b/addons/sale_purchase/models/sale_order_line.py @@ -211,7 +211,7 @@ class SaleOrderLine(models.Model): def _purchase_service_match_supplier(self, warning=True): # determine vendor of the order (take the first matching company and product) - suppliers = self.product_id._select_seller(quantity=self.product_uom_qty, uom_id=self.product_uom) + suppliers = self.product_id._select_seller(partner_id=self._retrieve_purchase_partner(), quantity=self.product_uom_qty, uom_id=self.product_uom) if warning and not suppliers: raise UserError(_("There is no vendor associated to the product %s. Please define a vendor for this product.") % (self.product_id.display_name,)) return suppliers[0] @@ -233,6 +233,12 @@ class SaleOrderLine(models.Model): purchase_order = self._create_purchase_order(supplierinfo) return purchase_order + def _retrieve_purchase_partner(self): + """ In case we want to explicitely name a partner from whom we want to buy or receive products + """ + self.ensure_one() + return False + def _purchase_service_create(self, quantity=False): """ On Sales Order confirmation, some lines (services ones) can create a purchase order line and maybe a purchase order. If a line should create a RFQ, it will check for existing PO. If no one is find, the SO line will create one, then adds