From da4ddd5ae70c83ecdadc5336fdad1e2cbcc3cbb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 26 Sep 2021 23:07:57 +0200 Subject: [PATCH] Use contact_mechanism_get to get phone and email issue10752 review336931002 --- stock.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/stock.py b/stock.py index 0e60dca5dc..54cdaea03d 100644 --- a/stock.py +++ b/stock.py @@ -110,10 +110,7 @@ class ShippingUPSMixin: warehouse=warehouse.rec_name)) if warehouse.address.country != self.delivery_address.country: for party in {self.shipping_to, self.company.party}: - for mechanism in party.contact_mechanisms: - if mechanism.type in ('phone', 'mobile'): - break - else: + if not party.contact_mechanism_get({'phone', 'mobile'}): raise PackingValidationError( gettext('stock_package_shipping_ups' '.msg_phone_required', @@ -280,15 +277,10 @@ class CreateShippingUPS(Wizard): 'CountryCode': address.country.code if address.country else '', }, } - - phone = '' - for mechanism in party.contact_mechanisms: - if mechanism.type in {'phone', 'mobile'}: - phone = mechanism.value - break + phone = party.contact_mechanism_get({'phone', 'mobile'}) if phone: shipping_party['Phone'] = { - 'Number': re.sub('[() .-]', '', phone)[:15] + 'Number': re.sub('[() .-]', '', phone.value)[:15] } return shipping_party