From 6fd2d9b898ca656b751e3a133e2ce2c7ff8cd522 Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Thu, 16 Apr 2020 11:01:03 +0000 Subject: [PATCH] [FIX] product,website_sale: partner pricelist fallback When no pricelist property is defined for a customer, we use a search as fallback, without considering the current companies. This means you can see the pricelist of company B as pricelist for a partner, even with company A as main current company (if both company are enabled in the multi-company widget). Forward-Port of #46429 X-original-commit: 68040c92c8e09218641d823d690e0ce36dcdef30 --- addons/product/models/product_pricelist.py | 10 +++++++--- addons/website_sale/models/product.py | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/addons/product/models/product_pricelist.py b/addons/product/models/product_pricelist.py index 3f865ba1637..e6aa593f0bc 100644 --- a/addons/product/models/product_pricelist.py +++ b/addons/product/models/product_pricelist.py @@ -307,8 +307,11 @@ class Pricelist(models.Model): return pricelist.get_products_price( list(zip(**products_by_qty_by_partner))) - def _get_partner_pricelist_multi_search_domain_hook(self): - return [('active', '=', True)] + def _get_partner_pricelist_multi_search_domain_hook(self, company_id): + return [ + ('active', '=', True), + ('company_id', 'in', [company_id, False]), + ] def _get_partner_pricelist_multi_filter_hook(self): return self.filtered('active') @@ -331,10 +334,11 @@ class Pricelist(models.Model): # `partner_ids` might be ID from inactive uers. We should use active_test # as we will do a search() later (real case for website public user). Partner = self.env['res.partner'].with_context(active_test=False) + company_id = company_id or self.env.company.id Property = self.env['ir.property'].with_company(company_id) Pricelist = self.env['product.pricelist'] - pl_domain = self._get_partner_pricelist_multi_search_domain_hook() + pl_domain = self._get_partner_pricelist_multi_search_domain_hook(company_id) # if no specific property, try to find a fitting pricelist result = Property.get_multi('property_product_pricelist', Partner._name, partner_ids) diff --git a/addons/website_sale/models/product.py b/addons/website_sale/models/product.py index 15078bb4b18..ff61753a794 100644 --- a/addons/website_sale/models/product.py +++ b/addons/website_sale/models/product.py @@ -65,8 +65,8 @@ class ProductPricelist(models.Model): self.clear_cache() return res - def _get_partner_pricelist_multi_search_domain_hook(self): - domain = super(ProductPricelist, self)._get_partner_pricelist_multi_search_domain_hook() + def _get_partner_pricelist_multi_search_domain_hook(self, company_id): + domain = super(ProductPricelist, self)._get_partner_pricelist_multi_search_domain_hook(company_id) website = ir_http.get_request_website() if website: domain += self._get_website_pricelists_domain(website.id)