changeset 6f4256e8e68d in modules/party:default
details: https://hg.tryton.org/modules/party?cmd=changeset&node=6f4256e8e68d
description:
        Add language to contact mechanism

        issue10223
        review349611002
diffstat:

 CHANGELOG                                |   1 +
 __init__.py                              |   1 +
 contact_mechanism.py                     |  22 ++++++++++++++++++++--
 ir.py                                    |  16 ++++++++++++----
 view/contact_mechanism_form.xml          |   5 ++++-
 view/contact_mechanism_tree.xml          |   1 +
 view/contact_mechanism_tree_sequence.xml |   1 +
 7 files changed, 40 insertions(+), 7 deletions(-)

diffs (127 lines):

diff -r afe147819302 -r 6f4256e8e68d CHANGELOG
--- a/CHANGELOG Wed Apr 07 15:37:19 2021 +0200
+++ b/CHANGELOG Sun Apr 11 18:37:41 2021 +0200
@@ -1,3 +1,4 @@
+* Add language to contact mechanism
 * Add contact_mechanism as email recipient
 * Rename zip into postal code
 * Add simple distance between parties
diff -r afe147819302 -r 6f4256e8e68d __init__.py
--- a/__init__.py       Wed Apr 07 15:37:19 2021 +0200
+++ b/__init__.py       Sun Apr 11 18:37:41 2021 +0200
@@ -24,6 +24,7 @@
         address.AddressFormat,
         address.SubdivisionType,
         contact_mechanism.ContactMechanism,
+        contact_mechanism.ContactMechanismLanguage,
         configuration.Configuration,
         configuration.ConfigurationSequence,
         configuration.ConfigurationLang,
diff -r afe147819302 -r 6f4256e8e68d contact_mechanism.py
--- a/contact_mechanism.py      Wed Apr 07 15:37:19 2021 +0200
+++ b/contact_mechanism.py      Sun Apr 11 18:37:41 2021 +0200
@@ -9,7 +9,8 @@
 
 from trytond.i18n import gettext
 from trytond.model import (
-    ModelView, ModelSQL, DeactivableMixin, fields, sequence_ordered)
+    ModelView, ModelSQL, DeactivableMixin, MultiValueMixin, ValueMixin, fields,
+    sequence_ordered)
 from trytond.model.exceptions import AccessError
 from trytond.pyson import Eval
 from trytond.transaction import Transaction
@@ -37,7 +38,8 @@
 
 
 class ContactMechanism(
-        DeactivableMixin, sequence_ordered(), ModelSQL, ModelView):
+        DeactivableMixin, sequence_ordered(), ModelSQL, ModelView,
+        MultiValueMixin):
     "Contact Mechanism"
     __name__ = 'party.contact_mechanism'
     _rec_name = 'value'
@@ -53,6 +55,13 @@
     comment = fields.Text("Comment")
     party = fields.Many2One(
         'party.party', "Party", required=True, ondelete='CASCADE', select=True)
+    language = fields.MultiValue(
+        fields.Many2One('ir.lang', "Language",
+            help="Used to translate communication made "
+            "using the contact mechanism.\n"
+            "Leave empty for the party language."))
+    languages = fields.One2Many(
+        'party.contact_mechanism.language', 'contact_mechanism', "Languages")
     email = fields.Function(fields.Char('E-Mail', states={
         'invisible': Eval('type') != 'email',
         'required': Eval('type') == 'email',
@@ -267,3 +276,12 @@
             for name, desc in cls.fields_get(_fields).items():
                 usages.append((name, desc['string']))
         return usages
+
+
+class ContactMechanismLanguage(ModelSQL, ValueMixin):
+    "Contact Mechanism Language"
+    __name__ = 'party.contact_mechanism.language'
+    contact_mechanism = fields.Many2One(
+        'party.contact_mechanism', "Contact Mechanism",
+        ondelete='CASCADE', select=True)
+    language = fields.Many2One('ir.lang', "Language")
diff -r afe147819302 -r 6f4256e8e68d ir.py
--- a/ir.py     Wed Apr 07 15:37:19 2021 +0200
+++ b/ir.py     Sun Apr 11 18:37:41 2021 +0200
@@ -76,8 +76,16 @@
         Party = pool.get('party.party')
         ContactMechanism = pool.get('party.contact_mechanism')
         language = super()._get_language(record)
-        if isinstance(record, Party) and record.lang:
-            language = record.lang
-        if isinstance(record, ContactMechanism) and record.party.lang:
-            language = record.party.lang
+        if isinstance(record, Party):
+            usage = Transaction().context.get('usage')
+            contact = record.contact_mechanism_get('email', usage=usage)
+            if contact.language:
+                language = contact.language
+            elif record.lang:
+                language = record.lang
+        if isinstance(record, ContactMechanism):
+            if record.language:
+                language = record.language
+            elif record.party.lang:
+                language = record.party.lang
         return language
diff -r afe147819302 -r 6f4256e8e68d view/contact_mechanism_form.xml
--- a/view/contact_mechanism_form.xml   Wed Apr 07 15:37:19 2021 +0200
+++ b/view/contact_mechanism_form.xml   Sun Apr 11 18:37:41 2021 +0200
@@ -27,7 +27,10 @@
         <field name="sip" widget="sip"/>
     </group>
     <label name="name"/>
-    <field name="name" colspan="3"/>
+    <field name="name"/>
+    <label name="language"/>
+    <field name="language" widget="selection"/>
+
     <separator name="comment" colspan="6"/>
     <field name="comment" colspan="6"/>
 </form>
diff -r afe147819302 -r 6f4256e8e68d view/contact_mechanism_tree.xml
--- a/view/contact_mechanism_tree.xml   Wed Apr 07 15:37:19 2021 +0200
+++ b/view/contact_mechanism_tree.xml   Sun Apr 11 18:37:41 2021 +0200
@@ -6,4 +6,5 @@
     <field name="value" expand="1"/>
     <field name="name" expand="1"/>
     <field name="party" expand="2"/>
+    <field name="language" widget="selection"/>
 </tree>
diff -r afe147819302 -r 6f4256e8e68d view/contact_mechanism_tree_sequence.xml
--- a/view/contact_mechanism_tree_sequence.xml  Wed Apr 07 15:37:19 2021 +0200
+++ b/view/contact_mechanism_tree_sequence.xml  Sun Apr 11 18:37:41 2021 +0200
@@ -6,5 +6,6 @@
     <field name="value" expand="1"/>
     <field name="name" expand="1"/>
     <field name="party" expand="2"/>
+    <field name="language" widget="selection"/>
     <field name="url" widget="url"/>
 </tree>

Reply via email to