diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 64c68ef5d72..a81721d9f10 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -819,6 +819,10 @@ class Website(models.Model): res = urls.url_parse(self.domain) return 'http://' + self.domain if not res.scheme else self.domain + def get_base_url(self): + self.ensure_one() + return self._get_http_domain() or super(BaseModel, self).get_base_url() + class BaseModel(models.AbstractModel): _inherit = 'base' diff --git a/addons/website/tests/test_base_url.py b/addons/website/tests/test_base_url.py index 8b98ea4e2d9..421174d0c65 100644 --- a/addons/website/tests/test_base_url.py +++ b/addons/website/tests/test_base_url.py @@ -12,22 +12,30 @@ class TestBaseUrl(odoo.tests.HttpCase): Website = self.env['website'] icp_base_url = ICP.sudo().get_param('web.base.url') - domain ='https://www.domain.jke' - + domain = 'https://www.domain.jke' website = Website.create({'name': 'test base url', 'domain': domain}) - without_website_id = website # a model that don't have website_id as field - with_website_id = self.env['res.partner'].create({'name': 'test base url'}) + # Test URL is correct for the website itself when the domain is set + self.assertEqual(website.get_base_url(), domain) + + # Test URL is correct for a model without website_id + without_website_id = self.env['ir.attachment'].create({'name': 'test base url'}) self.assertEqual(without_website_id.get_base_url(), icp_base_url) + # Test URL is correct for a model with website_id... + with_website_id = self.env['res.partner'].create({'name': 'test base url'}) + + # ...when no website is set on the model with_website_id.website_id = False self.assertEqual(with_website_id.get_base_url(), icp_base_url) + # ...when the website is correctly set with_website_id.website_id = website self.assertEqual(with_website_id.get_base_url(), domain) + # ...when the set website doesn't have a domain website.domain = False self.assertEqual(with_website_id.get_base_url(), icp_base_url) - - + # Test URL is correct for the website itself when no domain is set + self.assertEqual(website.get_base_url(), icp_base_url) diff --git a/addons/website_slides/models/slide_channel.py b/addons/website_slides/models/slide_channel.py index 9b4d7704b51..b6383e49ffd 100644 --- a/addons/website_slides/models/slide_channel.py +++ b/addons/website_slides/models/slide_channel.py @@ -296,11 +296,6 @@ class Channel(models.Model): def _get_can_publish_error_message(self): return _("Publishing is restricted to the responsible of training courses or members of the publisher group for documentation courses") - def get_base_url(self): - self.ensure_one() - icp = self.env['ir.config_parameter'].sudo().get_param('web.base.url') - return self.website_id and self.website_id._get_http_domain() or icp - @api.depends('name', 'website_id.domain') def _compute_website_url(self): super(Channel, self)._compute_website_url()