diff --git a/addons/website_sale/models/website.py b/addons/website_sale/models/website.py index 926899c3697..5d76fdf2f7c 100644 --- a/addons/website_sale/models/website.py +++ b/addons/website_sale/models/website.py @@ -103,7 +103,14 @@ class Website(models.Model): # if logged in, add partner pl (which is `property_product_pricelist`, might not be website compliant) is_public = self.user_id.id == self.env.user.id if not is_public: - pricelists |= pricelists.browse(partner_pl).filtered(lambda pl: pl._is_available_on_website(self.id) and _check_show_visible(pl)) + # keep partner_pl only if website compliant + partner_pl = pricelists.browse(partner_pl).filtered(lambda pl: pl._is_available_on_website(self.id) and _check_show_visible(pl)) + if country_code: + # keep partner_pl only if GeoIP compliant in case of GeoIP enabled + partner_pl = partner_pl.filtered( + lambda pl: pl.country_group_ids and country_code in pl.country_group_ids.mapped('country_ids.code') + ) + pricelists |= partner_pl # This method is cached, must not return records! See also #8795 return pricelists.ids diff --git a/addons/website_sale/tests/test_website_sale_pricelist.py b/addons/website_sale/tests/test_website_sale_pricelist.py index 4a4097c2826..8f1179bedb2 100644 --- a/addons/website_sale/tests/test_website_sale_pricelist.py +++ b/addons/website_sale/tests/test_website_sale_pricelist.py @@ -219,17 +219,17 @@ class TestWebsitePriceListAvailable(TransactionCase): 'website_id': self.website.id, 'selectable': True, }) - self.w1_pl_code = Pricelist.create({ - 'name': 'Website 1 Pricelist Code', - 'website_id': self.website.id, - 'code': 'W1CODE', - }) self.w1_pl_code_select = Pricelist.create({ 'name': 'Website 1 Pricelist Code Selectable', 'website_id': self.website.id, 'code': 'W1CODESELECT', 'selectable': True, }) + self.w1_pl_code = Pricelist.create({ + 'name': 'Website 1 Pricelist Code', + 'website_id': self.website.id, + 'code': 'W1CODE', + }) self.w2_pl = Pricelist.create({ 'name': 'Website 2 Pricelist', 'website_id': self.website2.id, @@ -290,8 +290,8 @@ class TestWebsitePriceListAvailableGeoIP(TestWebsitePriceListAvailable): # generic_pl_code_select | V | | V | BENELUX | # w1_pl | | 1 | | BENELUX | # w1_pl_select | V | 1 | | BE | - # w1_pl_code | | 1 | V | EUR | # w1_pl_code_select | V | 1 | V | NL | + # w1_pl_code | | 1 | V | EUR | # w2_pl | | 2 | | BENELUX | # available pl for website 1 for GeoIP BE (anything except website 2, backend and NL) @@ -315,9 +315,8 @@ class TestWebsitePriceListAvailableGeoIP(TestWebsitePriceListAvailable): def test_get_pricelist_available_geoip3(self): # Test get all available pricelists with geoip and a partner pricelist (ir.property) website compliant (but not geoip compliant) self.env.user.partner_id.property_product_pricelist = self.w1_pl_code_select - self.website1_be_pl += self.env.user.partner_id.property_product_pricelist pls = self.get_pricelist_available(country_code=self.BE.code) - self.assertEqual(pls, self.website1_be_pl, "Only pricelists for BE and accessible on website should be returned, plus the partner pricelist as it is website compliant") + self.assertEqual(pls, self.website1_be_pl, "Only pricelists for BE and accessible on website should be returned, but not the partner pricelist as it is website compliant but not GeoIP compliant.") def test_get_pricelist_available_geoip4(self): # Test get all available with geoip and visible pricelists + promo pl