Files
odoo_source/addons/website/models/ir_model.py
T
Chong Wang (cwg) 967f6b6121 [FIX] website: fix to_translate tag
Before the task
when the default language for a website is not en_US, and users try to
edit_translations from the website, all terms are marked "translated"
because odoo adds
`data-oe-translation-state="to translate"` if the term is not extracted from
the en_US value and is the same as its en_US term

After this commit:
if the record's bounded website's default language is lang_base
odoo adds
`data-oe-translation-state="to translate"` if the term is not extracted from
the lang_base value and is the same as its lang_base term

closes odoo/odoo#127468

Task-id: 3344973
X-original-commit: 7c20510bda2f1312a9392df445ee38aea7b2267b
Signed-off-by: Julien Castiaux (juc) <juc@odoo.com>
Signed-off-by: Chong Wang (cwg) <cwg@odoo.com>
2023-07-07 12:09:54 +02:00

49 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import ir_http
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 {}
def _get_base_lang(self):
""" Returns the default language of the website as the base language if the record is bound to it """
website = ir_http.get_request_website()
if website:
return website.default_lang_id.code
return super()._get_base_lang()