[IMP] base: Don't show language if only one active

If only one language is active, don't show in the contact
form view (`res.partner`) the language field. Changing the language is
not possible since there is only one language.
Hence the field is useless and therefore hidden.
This commit is contained in:
Lucas Lefèvre
2019-07-16 17:28:52 +02:00
committed by Yannick Tivisse
parent 4f47b729b1
commit a5077b300c
2 changed files with 9 additions and 2 deletions
+6
View File
@@ -154,6 +154,7 @@ class Partner(models.Model):
ref = fields.Char(string='Reference', index=True)
lang = fields.Selection(_lang_get, string='Language', default=lambda self: self.env.lang,
help="All the emails and documents sent to this contact will be translated in this language.")
active_lang_count = fields.Integer(compute='_compute_active_lang_count')
tz = fields.Selection(_tz_get, string='Timezone', default=lambda self: self._context.get('tz'),
help="When printing documents and exporting/importing data, time values are computed according to this timezone.\n"
"If the timezone is not set, UTC (Coordinated Universal Time) is used.\n"
@@ -253,6 +254,11 @@ class Partner(models.Model):
for partner in self:
partner.display_name = names.get(partner.id)
def _compute_active_lang_count(self):
lang_count = len(self.env['res.lang'].get_installed())
for partner in self:
partner.active_lang_count = lang_count
@api.depends('tz')
def _compute_tz_offset(self):
for partner in self:
+3 -2
View File
@@ -262,8 +262,9 @@
<field name="website" widget="url" placeholder="e.g. www.odoo.com"/>
<field name="title" options='{"no_open": True}'
attrs="{'invisible': [('is_company', '=', True)]}"/>
<label for="lang"/>
<div class="o_row">
<field name="active_lang_count" invisible="1"/>
<label for="lang" attrs="{'invisible': [('active_lang_count', '&lt;=', 1)]}"/>
<div class="o_row" attrs="{'invisible': [('active_lang_count', '&lt;=', 1)]}">
<field name="lang" placeholder="System (English)"/>
<button
type="action"