details:   https://code.tryton.org/tryton/commit/3a5be05ef75d
branch:    default
user:      Cédric Krier <[email protected]>
date:      Tue Sep 23 16:15:57 2025 +0200
description:
        Insert last Shopify contact mechanism as first of its type

        Closes #14252
diffstat:

 modules/web_shop_shopify/party.py |  20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)

diffs (39 lines):

diff -r bca2b503c6e3 -r 3a5be05ef75d modules/web_shop_shopify/party.py
--- a/modules/web_shop_shopify/party.py Tue Sep 23 16:04:29 2025 +0200
+++ b/modules/web_shop_shopify/party.py Tue Sep 23 16:15:57 2025 +0200
@@ -1,5 +1,6 @@
 # This file is part of Tryton.  The COPYRIGHT file at the top level of
 # this repository contains the full copyright notices and license terms.
+from trytond.model import sequence_reorder
 from trytond.pool import Pool, PoolMeta
 from trytond.tools import remove_forbidden_chars
 
@@ -27,16 +28,21 @@
             value = remove_forbidden_chars(value)
             if not value:
                 continue
-            for contact_mechanism in contact_mechanisms:
-                if (contact_mechanism.type in types
-                        and (contact_mechanism.value_compact
+            index = len(contact_mechanisms)
+            for i, contact_mechanism in enumerate(contact_mechanisms):
+                if contact_mechanism.type in types:
+                    index = min(i, index)
+                    if (contact_mechanism.value_compact
                             == contact_mechanism.format_value_compact(
-                                value, contact_mechanism.type))):
-                    break
+                                value, contact_mechanism.type)):
+                        contact_mechanisms.insert(
+                            index,
+                            contact_mechanisms.pop(i))
+                        break
             else:
-                contact_mechanisms.append(ContactMechanism(
+                contact_mechanisms.insert(index, ContactMechanism(
                         type=types[0], value=value))
-        party.contact_mechanisms = contact_mechanisms
+        party.contact_mechanisms = sequence_reorder(contact_mechanisms)
         # TODO tax_exempt
         return party
 

Reply via email to