details:   https://code.tryton.org/tryton/commit/5b3e5b30db61
branch:    default
user:      Cédric Krier <[email protected]>
date:      Tue Sep 23 18:43:08 2025 +0200
description:
        Add contact mechanism for the phone number from Shopify address

        Closes #14253
diffstat:

 modules/web_shop_shopify/party.py                            |  34 ++++++++++-
 modules/web_shop_shopify/tests/scenario_web_shop_shopify.rst |  12 +++-
 2 files changed, 39 insertions(+), 7 deletions(-)

diffs (95 lines):

diff -r 3a5be05ef75d -r 5b3e5b30db61 modules/web_shop_shopify/party.py
--- a/modules/web_shop_shopify/party.py Tue Sep 23 16:15:57 2025 +0200
+++ b/modules/web_shop_shopify/party.py Tue Sep 23 18:43:08 2025 +0200
@@ -30,7 +30,8 @@
                 continue
             index = len(contact_mechanisms)
             for i, contact_mechanism in enumerate(contact_mechanisms):
-                if contact_mechanism.type in types:
+                if (contact_mechanism.type in types
+                        and not contact_mechanism.address):
                     index = min(i, index)
                     if (contact_mechanism.value_compact
                             == contact_mechanism.format_value_compact(
@@ -49,13 +50,36 @@
     def get_address_from_shopify(self, shopify_address):
         pool = Pool()
         Address = pool.get('party.address')
+        ContactMechanism = pool.get('party.contact_mechanism')
         shopify_values = Address.get_shopify_values(shopify_address)
         for address in self.addresses:
             if address.shopify_values() == shopify_values:
-                return address
-        address = Address(**shopify_values)
-        address.party = self
-        address.save()
+                break
+        else:
+            address = Address(**shopify_values)
+            address.party = self
+            address.save()
+
+        contact_mechanisms = list(self.contact_mechanisms)
+        if phone := remove_forbidden_chars(shopify_address.phone):
+            index = len(contact_mechanisms)
+            for i, contact_mechanism in enumerate(contact_mechanisms):
+                if (contact_mechanism.type in ['phone', 'mobile']
+                        and contact_mechanism.address == address):
+                    index = min(i, index)
+                    if (contact_mechanism.value_compact
+                            == contact_mechanism.format_value_compact(
+                                phone, contact_mechanism.type)):
+                        contact_mechanisms.insert(
+                            index,
+                            contact_mechanisms.pop(i))
+                        break
+            else:
+                contact_mechanisms.insert(index, ContactMechanism(
+                        party=self, address=address,
+                        type='phone', value=phone))
+                ContactMechanism.save(sequence_reorder(
+                        contact_mechanisms))
         return address
 
 
diff -r 3a5be05ef75d -r 5b3e5b30db61 
modules/web_shop_shopify/tests/scenario_web_shop_shopify.rst
--- a/modules/web_shop_shopify/tests/scenario_web_shop_shopify.rst      Tue Sep 
23 16:15:57 2025 +0200
+++ b/modules/web_shop_shopify/tests/scenario_web_shop_shopify.rst      Tue Sep 
23 18:43:08 2025 +0200
@@ -438,10 +438,13 @@
     >>> customer_phone = '+32-495-555-' + (
     ...     ''.join(random.choice(string.digits) for _ in range(3)))
     >>> customer.phone = customer_phone
+    >>> customer_address_phone = '+32-495-555-' + (
+    ...     ''.join(random.choice(string.digits) for _ in range(3)))
     >>> customer.addresses = [{
     ...         'address1': "Street",
     ...         'city': "City",
     ...         'country': "Belgium",
+    ...         'phone': customer_address_phone,
     ...         }]
     >>> customer.save()
     True
@@ -517,8 +520,13 @@
     'Customer'
     >>> assertTrue(sale.party.email)
     >>> assertEqual(sale.party.phone.replace(' ', ''), 
customer_phone.replace('-', ''))
+    >>> address, = sale.party.addresses
+    >>> address_contact_mechanism, = address.contact_mechanisms
+    >>> assertEqual(
+    ...     address_contact_mechanism.value.replace(' ', ''),
+    ...     customer_address_phone.replace('-', ''))
     >>> len(sale.party.contact_mechanisms)
-    2
+    3
     >>> assertTrue(sale.web_status_url)
 
 Capture full amount::
@@ -543,7 +551,7 @@
     >>> len(sale.invoices)
     0
     >>> len(sale.party.contact_mechanisms)
-    2
+    3
 
 Make a partial shipment::
 

Reply via email to