diff --git a/CHANGELOG b/CHANGELOG
index c266e11163..0438d35c21 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,4 @@
+* Add notification preference
* Use contact mechanism from address
Version 6.4.0 - 2022-05-02
diff --git a/carrier.py b/carrier.py
index 1e5ad88d1f..a1025d5711 100644
--- a/carrier.py
+++ b/carrier.py
@@ -92,6 +92,17 @@ class Carrier(metaclass=PoolMeta):
'invisible': Eval('shipping_service') != 'dpd',
})
+ dpd_notification = fields.Selection([
+ (None, ""),
+ ('email', "E-Mail"),
+ ('sms', "SMS"),
+ ], "Notification",
+ states={
+ 'invisible': Eval('shipping_service') != 'dpd',
+ },
+ help="The preferred notification channel.\n"
+ "Leave empty for no notification.")
+
@classmethod
def __setup__(cls):
super(Carrier, cls).__setup__()
diff --git a/stock.py b/stock.py
index 08cfae3278..fd4c0bb843 100644
--- a/stock.py
+++ b/stock.py
@@ -276,5 +276,44 @@ class CreateDPDShipping(Wizard):
'parcels': [self.get_parcel(p) for p in packages],
'productAndServiceData': {
'orderType': 'consignment',
- }
+ **self.get_notification(shipment),
+ },
}
+
+ def get_notification(self, shipment, usage=None):
+ carrier = shipment.carrier
+ if not carrier.dpd_notification:
+ return {}
+ party = shipment.shipping_to
+ if party and party.lang:
+ lang_code = party.lang.code
+ else:
+ lang_code = Transaction().language
+ lang_code = lang_code.upper()
+ channel2type = {
+ 'sms': {'mobile'},
+ }
+
+ channels = [
+ (1, 'email'),
+ (3, 'sms'),
+ ]
+ if carrier.dpd_notification == 'sms':
+ channels = reversed(channels)
+
+ for channel_id, channel in channels:
+ mechanism = party.contact_mechanism_get(
+ channel2type.get(channel, channel), usage=usage)
+ if not mechanism:
+ continue
+ value = mechanism.value
+ if len(value) > 50:
+ continue
+ return {
+ 'predict': {
+ 'channel': channel_id,
+ 'value': value,
+ 'language': lang_code,
+ },
+ }
+ return {}
diff --git a/tests/scenario_shipping_dpd.rst b/tests/scenario_shipping_dpd.rst
index 0c14b120a4..f1179751cd 100644
--- a/tests/scenario_shipping_dpd.rst
+++ b/tests/scenario_shipping_dpd.rst
@@ -64,8 +64,7 @@ Create parties::
>>> customer_address.city = 'Paris'
>>> customer_address.country = france
>>> customer_address.save()
- >>> customer_phone = customer.contact_mechanisms.new()
- >>> customer_phone.type = 'phone'
+ >>> customer_phone = customer.contact_mechanisms.new(type='mobile')
>>> customer_phone.value = '+33 93 842 8862'
>>> customer_phone.save()
@@ -179,6 +178,7 @@ Create a DPD Carrier and the related credential::
>>> carrier.dpd_product = 'CL'
>>> carrier.dpd_printer_language = 'PDF'
>>> carrier.dpd_paper_format = 'A6'
+ >>> carrier.dpd_notification = 'sms'
>>> carrier.save()
>>> catchall_selection = CarrierSelection(carrier=carrier)
diff --git a/view/carrier_form.xml b/view/carrier_form.xml
index 3d3c9c205d..e0be4750eb 100644
--- a/view/carrier_form.xml
+++ b/view/carrier_form.xml
@@ -6,7 +6,9 @@ this repository contains the full copyright notices and license terms. -->
-
+
+
+