[FIX] base: make parent contact lang prevail on DB lang

Purpose
=======

If a user specifies a language on a company (res.partner), chances are children
of said company will speak the same language. It is at least most likely than
having them speak the default DB language.

Specifications
==============

If a language is set on the parent, the child contact created from the o2m
should have by default the same language.

Before this commit, we set lang in the context of the o2m field but it not
taken into account and is overriden by the default DB lang.

After this commit, the default lang value is forced in the default get to
be the same than the parent, if any. Else, we fallback to the default DB lang.

Link
====

Task ID: 2210350
PR #48077

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
David Beguin
2020-03-23 09:57:09 +00:00
parent fba4517567
commit 83ffe8b50b
2 changed files with 9 additions and 4 deletions
+8 -3
View File
@@ -137,10 +137,15 @@ class Partner(models.Model):
@api.model
def default_get(self, default_fields):
"""Add the company of the parent as default if we are creating a child partner."""
"""Add the company of the parent as default if we are creating a child partner.
Also take the parent lang by default if any, otherwise, fallback to default DB lang."""
values = super().default_get(default_fields)
parent = self.env["res.partner"]
if 'parent_id' in default_fields and values.get('parent_id'):
values['company_id'] = self.browse(values.get('parent_id')).company_id.id
parent = self.browse(values.get('parent_id'))
values['company_id'] = parent.company_id.id
if 'lang' in default_fields:
values['lang'] = values.get('lang') or parent.lang or self.env.lang
return values
name = fields.Char(index=True)
@@ -151,7 +156,7 @@ class Partner(models.Model):
parent_name = fields.Char(related='parent_id.name', readonly=True, string='Parent name')
child_ids = fields.One2many('res.partner', 'parent_id', string='Contact', domain=[('active', '=', True)]) # force "active_test" domain to bypass _search() override
ref = fields.Char(string='Reference', index=True)
lang = fields.Selection(_lang_get, string='Language', default=lambda self: self.env.lang,
lang = fields.Selection(_lang_get, string='Language',
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'),
+1 -1
View File
@@ -222,7 +222,7 @@
<notebook colspan="4">
<page string="Contacts &amp; Addresses" name="contact_addresses" autofocus="autofocus">
<field name="child_ids" mode="kanban" context="{'default_parent_id': active_id, 'default_street': street, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_lang': lang, 'default_user_id': user_id, 'default_type': 'other'}">
<field name="child_ids" mode="kanban" context="{'default_parent_id': active_id, 'default_street': street, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_lang': None, 'default_user_id': user_id, 'default_type': 'other'}">
<kanban>
<field name="id"/>
<field name="color"/>