[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
This commit is contained in:
Victor Feyens
2020-04-16 11:48:56 +00:00
parent f5a047955c
commit 6fd2d9b898
2 changed files with 9 additions and 5 deletions
+7 -3
View File
@@ -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)
+2 -2
View File
@@ -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)