From 8f5e48c74cb38c933b1cd22ae85e784f2d7d5159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 1 Oct 2022 14:52:06 +0200 Subject: [PATCH] Add optional address to contact mechanism issue11705 review421691006 --- CHANGELOG | 1 + message.xml | 2 +- stock.py | 17 +++++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 489b4b98ab..00fd7bc6ab 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Use contact mechanism from address * Update service types Version 6.4.0 - 2022-05-02 diff --git a/message.xml b/message.xml index 77799055e9..2bb8d0487c 100644 --- a/message.xml +++ b/message.xml @@ -11,7 +11,7 @@ this repository contains the full copyright notices and license terms. --> To validate shipment "%(shipment)s" you must set an address on warehouse "%(warehouse)s". - To validate shipment "%(shipment)s" you must add phone number to party "%(party)s". + To validate shipment "%(shipment)s" you must add phone number for address "%(address)s". To validate shipment "%(shipment)s" you must fill its shipping description. diff --git a/stock.py b/stock.py index 9eb010ab27..dee7e5d230 100644 --- a/stock.py +++ b/stock.py @@ -110,14 +110,14 @@ class ShippingUPSMixin: shipment=self.rec_name, warehouse=warehouse.rec_name)) if warehouse.address.country != self.delivery_address.country: - for party in {self.shipping_to, self.company.party}: - if not party.contact_mechanism_get( + for address in [self.shipping_to_address, warehouse.address]: + if not address.contact_mechanism_get( {'phone', 'mobile'}, usage=usage): raise PackingValidationError( gettext('stock_package_shipping_ups' '.msg_phone_required', shipment=self.rec_name, - party=party.rec_name)) + address=address.rec_name)) if not self.shipping_description: if (any(p.type.ups_code != '01' for p in self.root_packages) and self.carrier.ups_service_type != '11'): @@ -282,12 +282,12 @@ class CreateShippingUPS(Wizard): 'CountryCode': address.country.code if address.country else '', }, } - phone = party.contact_mechanism_get({'phone', 'mobile'}, usage=usage) + phone = address.contact_mechanism_get({'phone', 'mobile'}, usage=usage) if phone: shipping_party['Phone'] = { 'Number': re.sub('[() .-]', '', phone.value)[:15] } - email = party.contact_mechanism_get('email') + email = address.contact_mechanism_get('email') if email and len(email.value) <= 50: shipping_party['EMailAddress'] = email.value @@ -353,7 +353,8 @@ class CreateShippingUPS(Wizard): def get_notifications(self, shipment): for code in shipment.carrier.ups_notifications: - email = shipment.shipping_to.contact_mechanism_get('email') + shipping_to_address = shipment.shipping_to_address + email = shipping_to_address.contact_mechanism_get('email') if email and len(email.value) <= 50: notification = { 'NotificationCode': code, @@ -362,13 +363,13 @@ class CreateShippingUPS(Wizard): }, } if code in {'012', '013'}: - phone = shipment.shipping_to.contact_mechanism_get( + phone = shipping_to_address.contact_mechanism_get( {'phone', 'mobile'}) if phone and len(phone.value) <= 15: notification['VoiceMessage'] = { 'PhoneNumber': phone.value, } - mobile = shipment.shipping_to.contact_mechanism_get( + mobile = shipping_to_address.contact_mechanism_get( 'mobile') if mobile and len(mobile.value) <= 15: notification['TextMessage'] = {