[IMP] delivery: handle multiple trackers
Easypost return multiple tracker links for a single picking. Currently it returns one link per package. *_get_tracking_link instead of returning a simple string, it could return a list of list with data [[tracker number, tracker_puclic_url], ...] stored as a json dump. This commit add a check on carrier_tracking_url in order to check if it has a json format. In this case it will log a note and will not use the url action.
This commit is contained in:
committed by
Simon Lejeune
parent
a19236205a
commit
6892cc8322
@@ -1,6 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import json
|
||||
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
@@ -181,12 +183,26 @@ class StockPicking(models.Model):
|
||||
if not self.carrier_tracking_url:
|
||||
raise UserError(_("Your delivery method has no redirect on courier provider's website to track this order."))
|
||||
|
||||
client_action = {'type': 'ir.actions.act_url',
|
||||
'name': "Shipment Tracking Page",
|
||||
'target': 'new',
|
||||
'url': self.carrier_tracking_url,
|
||||
}
|
||||
return client_action
|
||||
carrier_trackers = []
|
||||
try:
|
||||
carrier_trackers = json.loads(self.carrier_tracking_url)
|
||||
except ValueError:
|
||||
carrier_trackers = self.carrier_tracking_url
|
||||
|
||||
if len(carrier_trackers) > 1:
|
||||
msg = "Tracking links for shipment: <br/>"
|
||||
for tracker in carrier_trackers:
|
||||
msg += '<a href=' + tracker[1] + '>' + tracker[0] + '</a><br/>'
|
||||
self.message_post(body=msg)
|
||||
return self.env.ref('delivery.act_delivery_trackers_url').read()[0]
|
||||
else:
|
||||
client_action = {
|
||||
'type': 'ir.actions.act_url',
|
||||
'name': "Shipment Tracking Page",
|
||||
'target': 'new',
|
||||
'url': self.carrier_tracking_url,
|
||||
}
|
||||
return client_action
|
||||
|
||||
@api.one
|
||||
def cancel_shipment(self):
|
||||
|
||||
@@ -298,4 +298,30 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="delivery_tracking_url_warning_form" model="ir.ui.view">
|
||||
<field name="name">delivery.carrier.warning.url.form</field>
|
||||
<field name="model">stock.picking</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Trackers URL">
|
||||
<group>
|
||||
<div class="alert alert-info">
|
||||
<p>You have multiple URL, they should be available in the chatter.</p>
|
||||
</div>
|
||||
</group>
|
||||
<footer>
|
||||
<button string="OK" special="cancel" class="oe_highlight"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="act_delivery_trackers_url" model="ir.actions.act_window">
|
||||
<field name="name">Display tracking links</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">stock.picking</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_id" ref="delivery.delivery_tracking_url_warning_form"/>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user