Before Odoo saas-14.4, one should call `_get_http_domain()` on website to get its domain. Indeed, that method was in charge of cleaning that domain, as it was done with commit [1]. Since Odoo saas-14.4, that cleaning is automatically performed on domain before saving it into database, thanks to commit [2]. Thus, we can now remove the `_get_http_domain()` and use directly the domain as it is considered clean. Note that migrated databases coming from version older than Odoo saas-14.4 could still have an incorrect domain (trailing slash, no scheme..). This will be handled during migration with [3]. [1]: https://github.com/odoo/odoo/commit/3ad775aab717b395a5d11527aeb3596af66afa99 [2]: https://github.com/odoo/odoo/commit/042c95b0219bb0aa13e73385e092fa76ff1a1b0a [3]: https://github.com/odoo/upgrade/pull/2951 closes odoo/odoo#78766 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import models
|
|
|
|
|
|
class BaseModel(models.AbstractModel):
|
|
_inherit = 'base'
|
|
|
|
def get_base_url(self):
|
|
"""
|
|
Returns the base url for a given record, given the following priority:
|
|
1. If the record has a `website_id` field, we use the url from this
|
|
website as base url, if set.
|
|
2. If the record has a `company_id` field, we use the website from that
|
|
company (if set). Note that a company doesn't really have a website,
|
|
it is retrieve through some heuristic in its `website_id`'s compute.
|
|
3. Use the ICP `web.base.url` (super)
|
|
|
|
:return: the base url for this record
|
|
:rtype: string
|
|
"""
|
|
# Ensure zero or one record
|
|
if not self:
|
|
return super().get_base_url()
|
|
self.ensure_one()
|
|
|
|
if self._name == 'website':
|
|
# Note that website_1.company_id.website_id might not be website_1
|
|
return self.domain or super().get_base_url()
|
|
if 'website_id' in self and self.website_id.domain:
|
|
return self.website_id.domain
|
|
if 'company_id' in self and self.company_id.website_id.domain:
|
|
return self.company_id.website_id.domain
|
|
return super().get_base_url()
|
|
|
|
def get_website_meta(self):
|
|
# dummy version of 'get_website_meta' above; this is a graceful fallback
|
|
# for models that don't inherit from 'website.seo.metadata'
|
|
return {}
|