FIX] website_sale: prevent website with no pricelist in multi company

Followup on 911ada2d02b24778435fd9174441a6834da2effa

When modifying the company_id of a pricelist, the check to ensure a website
has a pricelist available wasn't triggered.

This commits ensures the Each website has Valid Pricelist with Correct or
Empty company.

Fixes #50707

closes odoo/odoo#62359

X-original-commit: f196430baa8c5e2ce403808adc26d90fe84665fa
Signed-off-by: Romain Derie <rdeodoo@users.noreply.github.com>
This commit is contained in:
Swapnesh Shah
2020-11-25 19:15:32 +00:00
parent 6f65923696
commit 5e4e4836ed
+5
View File
@@ -91,6 +91,7 @@ class ProductPricelist(models.Model):
- Have its `website_id` set to current website (specific pricelist).
- Have no `website_id` set and should be `selectable` (generic pricelist)
or should have a `code` (generic promotion).
- Have no `company_id` or a `company_id` matching its website one.
Note: A pricelist without a website_id, not selectable and without a
code is a backend pricelist.
@@ -98,13 +99,17 @@ class ProductPricelist(models.Model):
Change in this method should be reflected in `_get_website_pricelists_domain`.
"""
self.ensure_one()
if self.company_id and self.company_id != self.env["website"].browse(website_id).company_id:
return False
return self.website_id.id == website_id or (not self.website_id and (self.selectable or self.sudo().code))
def _get_website_pricelists_domain(self, website_id):
''' Check above `_is_available_on_website` for explanation.
Change in this method should be reflected in `_is_available_on_website`.
'''
company_id = self.env["website"].browse(website_id).company_id.id
return [
'&', ('company_id', 'in', [False, company_id]),
'|', ('website_id', '=', website_id),
'&', ('website_id', '=', False),
'|', ('selectable', '=', True), ('code', '!=', False),