Add contact mechanism for the phone number from Shopify address
Closes #14253
This commit is contained in:
@@ -30,7 +30,8 @@ class Party(IdentifiersMixin, metaclass=PoolMeta):
|
||||
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 @@ class Party(IdentifiersMixin, metaclass=PoolMeta):
|
||||
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
|
||||
|
||||
|
||||
|
||||
@@ -438,10 +438,13 @@ Create an order on Shopify::
|
||||
>>> 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 @@ Run fetch order::
|
||||
'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 @@ Capture full amount::
|
||||
>>> len(sale.invoices)
|
||||
0
|
||||
>>> len(sale.party.contact_mechanisms)
|
||||
2
|
||||
3
|
||||
|
||||
Make a partial shipment::
|
||||
|
||||
|
||||
Reference in New Issue
Block a user