mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[IMP] delivery_purolator: add tracking and cancel shipment
This commit is contained in:
@@ -339,5 +339,26 @@ class ProviderPurolator(models.Model):
|
||||
|
||||
return res
|
||||
|
||||
# TODO cancel shipment
|
||||
# TODO track shipment
|
||||
def purolator_get_tracking_link(self, pickings):
|
||||
res = []
|
||||
for picking in pickings:
|
||||
ref = picking.carrier_tracking_ref
|
||||
res = res + ['https://www.purolator.com/en/shipping/tracker?pins=%s' % ref]
|
||||
return res
|
||||
|
||||
def purolator_cancel_shipment(self, picking, packages=None):
|
||||
service = self._purolator_service()
|
||||
if packages:
|
||||
for package in packages:
|
||||
tracking_pin = package.carrier_tracking_ref
|
||||
void_res = service.shipment_void(tracking_pin)
|
||||
self._purolator_format_errors(void_res, raise_class=UserError)
|
||||
package.write({'carrier_tracking_ref': ''})
|
||||
picking.message_post(body=_('Package N° %s has been cancelled' % tracking_pin))
|
||||
else:
|
||||
tracking_pin = picking.carrier_tracking_ref
|
||||
void_res = service.shipment_void(tracking_pin)
|
||||
self._purolator_format_errors(void_res, raise_class=UserError)
|
||||
picking.message_post(body=_('Shipment N° %s has been cancelled' % tracking_pin))
|
||||
picking.write({'carrier_tracking_ref': '',
|
||||
'carrier_price': 0.0})
|
||||
|
||||
@@ -275,6 +275,12 @@ class PurolatorClient(object):
|
||||
)
|
||||
return response.body
|
||||
|
||||
def shipment_void(self, pin):
|
||||
response = self.shipping_client.service.VoidShipment(
|
||||
PIN={'Value': pin}
|
||||
)
|
||||
return response.body
|
||||
|
||||
def document_by_pin(self, pin, document_type='', output_type='ZPL'):
|
||||
# TODO document_type?
|
||||
document_criterium = self.shipping_documents_factory.ArrayOfDocumentCriteria()
|
||||
|
||||
@@ -132,3 +132,7 @@ class TestPurolator(TransactionCase):
|
||||
picking.send_to_shipper()
|
||||
self.assertTrue(picking.carrier_tracking_ref)
|
||||
self.assertEqual(picking.message_attachment_count, 1) # has tracking label now
|
||||
|
||||
# Void
|
||||
picking.cancel_shipment()
|
||||
self.assertFalse(picking.carrier_tracking_ref)
|
||||
|
||||
Reference in New Issue
Block a user