website: get_base_url was not working with unprivileged users Before this commit, when a unprivileged user tried to generate a report (in sale for example), he could not access to the field website_id on ir.ui.view An access error would be raised. This commit allows to read the base_url for all users. Misc: UI for sale order templates Before this commit, the sale order template information was not clear enough. Note: these changes were merged into a single commit to ease the manual FW port of changes in 15.3 for sale_subscription taskid: 2942621
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.sudo().website_id.domain:
|
|
return self.sudo().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 {}
|