Add tracking URL
issue10136 review341531002
This commit is contained in:
1 parent
091db50241
commit
b3f58f5b2f
3 files changed
+43
No files matched your search
@@ -11,6 +11,7 @@ def register():
|
||||
Pool.register(
|
||||
carrier.CredentialDPD,
|
||||
carrier.Carrier,
|
||||
stock.Package,
|
||||
stock.ShipmentOut,
|
||||
stock.ShipmentInReturn,
|
||||
module='stock_package_shipping_dpd', type_='model')
|
||||
|
||||
@@ -22,6 +22,44 @@ from trytond.modules.stock_package_shipping.exceptions import (
|
||||
from .configuration import get_client, SHIPMENT_SERVICE
|
||||
from .exceptions import DPDError
|
||||
|
||||
TRACKING_URL = 'https://tracking.dpd.de/status/%(code)s/parcel/%(reference)s'
|
||||
|
||||
|
||||
class Package(metaclass=PoolMeta):
|
||||
__name__ = 'stock.package'
|
||||
|
||||
def get_shipping_tracking_url(self, name):
|
||||
pool = Pool()
|
||||
ShipmentOut = pool.get('stock.shipment.out')
|
||||
ShipmentInReturn = pool.get('stock.shipment.in.return')
|
||||
url = super().get_shipping_tracking_url(name)
|
||||
if (self.shipping_reference
|
||||
and self.shipment
|
||||
and self.shipment.id >= 0
|
||||
and self.shipment.carrier
|
||||
and self.shipment.carrier.shipping_service == 'dpd'):
|
||||
party = address = None
|
||||
if isinstance(self.shipment, ShipmentOut):
|
||||
party = self.shipment.customer
|
||||
address = self.shipment.delivery_address
|
||||
elif isinstance(self.shipment, ShipmentInReturn):
|
||||
party = self.shipment.supplier
|
||||
address = self.shipment.delivery_address
|
||||
if party and party.lang:
|
||||
lang_code = party.lang.code
|
||||
else:
|
||||
lang_code = Transaction().language
|
||||
if address and address.country:
|
||||
code = '_'.join(
|
||||
(lang_code.split('_')[0], address.country.code))
|
||||
else:
|
||||
code = lang_code
|
||||
url = TRACKING_URL % {
|
||||
'code': code,
|
||||
'reference': self.shipping_reference,
|
||||
}
|
||||
return url
|
||||
|
||||
|
||||
class ShippingDPDMixin:
|
||||
|
||||
|
||||
@@ -222,3 +222,7 @@ Create the packs and ship the shipment::
|
||||
True
|
||||
>>> pack.shipping_reference is not None
|
||||
True
|
||||
>>> pack.shipping_tracking_url.startswith('https://tracking.dpd.de/status/')
|
||||
True
|
||||
>>> pack.shipping_tracking_url.endswith(pack.shipping_reference)
|
||||
True
|
||||
Reference in new issue
Block a user