changeset d0375e0d8f15 in modules/stock_package_shipping_ups:default
details: 
https://hg.tryton.org/modules/stock_package_shipping_ups?cmd=changeset&node=d0375e0d8f15
description:
        Add notification service option

        issue11286
        review374971002
diffstat:

 CHANGELOG                       |   1 +
 carrier.py                      |  13 +++++++++++++
 stock.py                        |  37 ++++++++++++++++++++++++++++++++++++-
 tests/scenario_shipping_ups.rst |   5 +++++
 view/carrier_form.xml           |   3 +++
 5 files changed, 58 insertions(+), 1 deletions(-)

diffs (119 lines):

diff -r c0493e8ef01a -r d0375e0d8f15 CHANGELOG
--- a/CHANGELOG Sat Mar 26 12:10:34 2022 +0100
+++ b/CHANGELOG Sat Mar 26 12:12:36 2022 +0100
@@ -1,3 +1,4 @@
+* Add notification service option
 * Add support for Python 3.10
 * Remove support for Python 3.6
 
diff -r c0493e8ef01a -r d0375e0d8f15 carrier.py
--- a/carrier.py        Sat Mar 26 12:10:34 2022 +0100
+++ b/carrier.py        Sat Mar 26 12:12:36 2022 +0100
@@ -90,6 +90,19 @@
                 | (Eval('ups_label_image_format') == 'GIF')),
             },
         depends=['shipping_service', 'ups_label_image_format'])
+    ups_notifications = fields.MultiSelection([
+            ('5', "Quantum View In-transit"),
+            ('6', "Quantum View Shop"),
+            ('7', "Quantum View Exception"),
+            ('8', "Quantum View Delivery"),
+            ('2', "Return or Label Creation"),
+            ('012', "Alternate Delivery Location"),
+            ('013', "UPS Access Point Shipper"),
+            ], "Notifications", sort=False,
+        states={
+            'invisible': Eval('shipping_service') != 'ups',
+            },
+        depends=['shipping_service'])
 
     @classmethod
     def __setup__(cls):
diff -r c0493e8ef01a -r d0375e0d8f15 stock.py
--- a/stock.py  Sat Mar 26 12:10:34 2022 +0100
+++ b/stock.py  Sat Mar 26 12:12:36 2022 +0100
@@ -344,6 +344,38 @@
                 }
         return pkg
 
+    def get_service_options(self, shipment):
+        service_options = {}
+        notifications = list(self.get_notifications(shipment))
+        if notifications:
+            service_options['Notification'] = notifications
+        return service_options
+
+    def get_notifications(self, shipment):
+        for code in shipment.carrier.ups_notifications:
+            email = shipment.shipping_to.contact_mechanism_get('email')
+            if email and len(email.value) <= 50:
+                notification = {
+                    'NotificationCode': code,
+                    'EMail': {
+                        'EMailAddress': email.value,
+                        },
+                    }
+                if code in {'012', '013'}:
+                    phone = shipment.shipping_to.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')
+                    if mobile and len(mobile.value) <= 15:
+                        notification['TextMessage'] = {
+                            'PhoneNumber': phone.value,
+                            }
+                yield notification
+
     def get_request(self, shipment, packages, credential):
         shipper = self.get_shipping_party(
             shipment.company.party, shipment.shipping_warehouse.address)
@@ -354,7 +386,10 @@
 
         packages = [self.get_package(credential.use_metric, p)
             for p in packages]
-
+        options = self.get_service_options(shipment)
+        if options:
+            for pkg in packages:
+                pkg['ShipmentServiceOptions'] = options
         return {
             'UPSSecurity': self.get_security(credential),
             'ShipmentRequest': {
diff -r c0493e8ef01a -r d0375e0d8f15 tests/scenario_shipping_ups.rst
--- a/tests/scenario_shipping_ups.rst   Sat Mar 26 12:10:34 2022 +0100
+++ b/tests/scenario_shipping_ups.rst   Sat Mar 26 12:12:36 2022 +0100
@@ -68,6 +68,10 @@
     >>> customer_phone.type = 'phone'
     >>> customer_phone.value = '+44 151 260 6677'
     >>> customer_phone.save()
+    >>> customer_email = customer.contact_mechanisms.new()
+    >>> customer_email.type = 'email'
+    >>> customer_email.value = '[email protected]'
+    >>> customer_email.save()
 
 Set the warehouse address::
 
@@ -180,6 +184,7 @@
     >>> carrier.shipping_service = 'ups'
     >>> carrier.ups_service_type = '65'
     >>> carrier.ups_label_image_format = 'GIF'
+    >>> carrier.ups_notifications = ['5', '7', '012']
     >>> carrier.save()
 
     >>> catchall_selection = CarrierSelection(carrier=carrier)
diff -r c0493e8ef01a -r d0375e0d8f15 view/carrier_form.xml
--- a/view/carrier_form.xml     Sat Mar 26 12:10:34 2022 +0100
+++ b/view/carrier_form.xml     Sat Mar 26 12:12:36 2022 +0100
@@ -11,5 +11,8 @@
         <field name="ups_label_image_format"/>
         <label name="ups_label_height"/>
         <field name="ups_label_height"/>
+
+        <label name="ups_notifications"/>
+        <field name="ups_notifications" colspan="3"/>
     </xpath>
 </data>

Reply via email to