Browse Source

[IMP] partner_contact_lang: Change language when assigning parent if virtual record

If the record hasn't been created yet, we can assume that the language set currently
is the default one, so we can switch it to the parent one.
12.0
Pedro M. Baeza 4 years ago
parent
commit
c56e964934
  1. 6
      partner_contact_lang/README.rst
  2. 18
      partner_contact_lang/models/res_partner.py
  3. 6
      partner_contact_lang/readme/DESCRIPTION.rst
  4. 16
      partner_contact_lang/static/description/index.html

6
partner_contact_lang/README.rst

@ -32,11 +32,11 @@ This module fills this gap, and also provides other facilities for the
contact language management:
#. Put the language of the parent company when the contact doesn't have a
language and this parent company is assigned.
language and this parent company is assigned.
#. When the company changes the language, it fills with the same language all
the contacts that don't have any.
the contacts that don't have any.
#. Show the language in the inner narrowed Contact form and
set the new conctact with a different language if needed.
set the new conctact with a different language if needed.
#. Search and also group contacts by their language.
**Table of contents**

18
partner_contact_lang/models/res_partner.py

@ -1,5 +1,5 @@
# Copyright 2016 Tecnativa - Pedro M. Baeza <pedro.baeza@tecnativa.com>
# Copyright 2017 Tecnativa - Vicent Cubells <vicent.cubells@tecnativa.com>
# Copyright 2016-2020 Tecnativa - Pedro M. Baeza
# Copyright 2017 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
@ -28,13 +28,17 @@ class ResPartner(models.Model):
@api.onchange("parent_id")
def onchange_parent_id(self):
"""Change language if the parent company changes and there's no
language defined yet"""
language defined yet.
A special case is made for virtual records, where default lang value
is assigned at startup, so we always overwrite language in that case.
"""
res = super(ResPartner, self).onchange_parent_id()
if (
self.parent_id
and self.parent_id != self
and not self.lang
and self.parent_id.lang
self.parent_id.lang and (
not self.lang or
(isinstance(self.id, models.NewId) and not self._origin)
) and self.parent_id.lang != self.lang
):
self.lang = self.parent_id.lang
return res

6
partner_contact_lang/readme/DESCRIPTION.rst

@ -5,9 +5,9 @@ This module fills this gap, and also provides other facilities for the
contact language management:
#. Put the language of the parent company when the contact doesn't have a
language and this parent company is assigned.
language and this parent company is assigned.
#. When the company changes the language, it fills with the same language all
the contacts that don't have any.
the contacts that don't have any.
#. Show the language in the inner narrowed Contact form and
set the new conctact with a different language if needed.
set the new conctact with a different language if needed.
#. Search and also group contacts by their language.

16
partner_contact_lang/static/description/index.html

@ -372,13 +372,15 @@ ul.auto-toc {
form, but it doesn’t allow to change it once created.</p>
<p>This module fills this gap, and also provides other facilities for the
contact language management:</p>
<p>#. Put the language of the parent company when the contact doesn’t have a
language and this parent company is assigned.
#. When the company changes the language, it fills with the same language all
the contacts that don’t have any.
#. Show the language in the inner narrowed Contact form and
set the new conctact with a different language if needed.
#. Search and also group contacts by their language.</p>
<ol class="arabic simple">
<li>Put the language of the parent company when the contact doesn’t have a
language and this parent company is assigned.</li>
<li>When the company changes the language, it fills with the same language all
the contacts that don’t have any.</li>
<li>Show the language in the inner narrowed Contact form and
set the new conctact with a different language if needed.</li>
<li>Search and also group contacts by their language.</li>
</ol>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">

Loading…
Cancel
Save