diff options
| author | Romain Derie <rde@odoo.com> | 2019-04-25 14:57:47 +0000 |
|---|---|---|
| committer | Romain Derie <rde@odoo.com> | 2019-04-26 08:02:07 +0000 |
| commit | 01d1cf35bbbcf020d1357edbb25d5111cdd97de1 (patch) | |
| tree | e8dd7851a751f28615ec224848906e5302fafcea /addons | |
| parent | 50caae5bc02bc6eaa1b4a4dfd965c84c940bb84b (diff) | |
[FIX] website_sale: fix pricelist GeoIP
Before this commit:
If the user was GeoIP located and it's pricelist (property_product_pricelist)
was not allowed for it's GeoIP country, that pricelist would still be return.
This issue was detected as a test `test_get_pricelist_available_geoip2` was not
working since forward ported in master (only on theme runbot or local..).
Before master (saas-12.4), `property_product_pricelist` would not be recomputed
once set, so the test was actually not working as expected.
Since master, reading `property_product_pricelist` just after setting it goes
through the compute method, resulting in different value than in previous
versions.
closes odoo/odoo#32961
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/website_sale/models/website.py | 9 | ||||
| -rw-r--r-- | addons/website_sale/tests/test_website_sale_pricelist.py | 15 |
2 files changed, 15 insertions, 9 deletions
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 |
