[REF] website_sale: force website methods to be called on a record

Part-of: odoo/odoo#82374
This commit is contained in:
Victor Feyens
2022-02-21 08:41:32 +00:00
parent 6d587718aa
commit 1c6ec568ac
2 changed files with 8 additions and 13 deletions
+5 -11
View File
@@ -6,7 +6,6 @@ import logging
from odoo import api, fields, models, tools, SUPERUSER_ID, _
from odoo.http import request
from odoo.addons.website.models import ir_http
from odoo.addons.http_routing.models.ir_http import url_for
_logger = logging.getLogger(__name__)
@@ -158,16 +157,11 @@ class Website(models.Model):
:param bool show_visible: if True, we don't display pricelist where selectable is False (Eg: Code promo)
:returns: pricelist recordset
"""
website = ir_http.get_request_website()
if not website:
if self.env.context.get('website_id'):
website = self.browse(self.env.context['website_id'])
else:
# In the weird case we are coming from the backend (https://github.com/odoo/odoo/issues/20245)
website = len(self) == 1 and self or self.search([], limit=1)
isocountry = req and req.session.geoip and req.session.geoip.get('country_code') or False
self.ensure_one()
website = website.with_company(website.company_id)
country_code = req and req.session.geoip and req.session.geoip.get('country_code') or False
website = self.with_company(self.company_id)
partner_sudo = website.env.user.partner_id
last_order_pricelist = partner_sudo.last_website_so_id.pricelist_id
@@ -178,7 +172,7 @@ class Website(models.Model):
current_pricelist_id = req and req.session.get('website_sale_current_pl') or None
pricelist_ids = website._get_pl_partner_order(
isocountry,
country_code,
show_visible,
website_pricelist.id,
current_pricelist_id,
@@ -293,8 +293,9 @@ def simulate_frontend_context(self, website_id=1):
class TestWebsitePriceListAvailable(TransactionCase):
# This is enough to avoid a mock (request.session/website do not exist during test)
def get_pricelist_available(self, show_visible=False, website_id=1, country_code=None, website_sale_current_pl=None):
website = self.env['website'].browse(website_id)
request = DotDict({
'website': self.env['website'].browse(website_id),
'website': website,
'session': {
'geoip': {
'country_code': country_code,
@@ -302,7 +303,7 @@ class TestWebsitePriceListAvailable(TransactionCase):
'website_sale_current_pl': website_sale_current_pl,
},
})
return self.env['website']._get_pricelist_available(request, show_visible)
return website._get_pricelist_available(request, show_visible)
def setUp(self):
super(TestWebsitePriceListAvailable, self).setUp()