Add notification preference
issue11738 review425741003
This commit is contained in:
1 parent
0acbd5a7ce
commit
3e5c8f9fca
5 files changed
+57
-4
No files matched your search
@@ -1,3 +1,4 @@
|
||||
* Add notification preference
|
||||
* Use contact mechanism from address
|
||||
|
||||
Version 6.4.0 - 2022-05-02
|
||||
|
||||
+11
@@ -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__()
|
||||
|
||||
@@ -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 {}
|
||||
@@ -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)
|
||||
|
||||
@@ -6,7 +6,9 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<separator string="DPD" colspan="4" id="dpd"/>
|
||||
<label name="dpd_product"/>
|
||||
<field name="dpd_product"/>
|
||||
<newline/>
|
||||
<label name="dpd_notification"/>
|
||||
<field name="dpd_notification"/>
|
||||
|
||||
<label name="dpd_printer_language"/>
|
||||
<field name="dpd_printer_language"/>
|
||||
<label name="dpd_paper_format"/>
|
||||
|
||||
Reference in new issue
Block a user