-
-
Notifications
You must be signed in to change notification settings - Fork 355
base_delivery_carrier_label evolution
David Beal edited this page Nov 23, 2015
·
5 revisions
Here is common method I would like add to base_delivery_carrier_label, to have a common api
class StockQuantPackage(models.Model):
_inherit = 'stock.quant.package'
carrier_id = field.Many2one('delivery.carrier')
@api.multi
def _get_carrier_tracking_url(self):
""" In your own module:
res = super(StockQuantPackage, self)._get_carrier_tracking_url()
if self.carrier_id.type == 'my_carrier':
res = "http://my_carrier/%s" % self.parcel_tracking
return res
"""
raise UserError(_("No carrier tracking url for this package"))
# button in the interface
@api.multi
def open_tracking_url(self):
self.ensure_one()
if not self.parcel_tracking:
raise UserError(
_("Cannot open tracking URL for this carrier "
"because this package "
"doesn't have a tracking number."))
return {
'type': 'ir.actions.act_url',
'url': self._get_carrier_tracking_url(),
'target': 'new',
}
class StockPackOperation(models.Model):
_inherit = 'stock.pack.operation'
# button in the interface
@api.multi
def open_tracking_url(self):
self.ensure_one()
if self.result_package_id and self.result_package_id.parcel_tracking:
self.result_package_id.open_tracking_url()
class StockPicking(models.Model):
_inherit = "stock.picking"
carrier_tracking_ref = fields.Char(copy=False)