[IMP] website, website_slides: adapt get_base_url for website

On `website` itself there is no `website_id` so the domain has to be read from
`self` directly.

Also oversight of forward-port 039e6bae99:
On `slide.channel` the override that was done in an earlier version is doing the
same as the generic override that was introduced later, so it can be removed.

closes odoo/odoo#35839

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
Sébastien Theys
2019-08-20 10:45:54 +00:00
parent df1aa689be
commit 1e8b9254f5
3 changed files with 18 additions and 11 deletions
+4
View File
@@ -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'
+14 -6
View File
@@ -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)
@@ -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()