[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>
This commit is contained in:
Romain Derie
2019-04-26 08:02:07 +00:00
parent 50caae5bc0
commit 01d1cf35bb
2 changed files with 15 additions and 9 deletions
+8 -1
View File
@@ -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
@@ -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