[IMP] delivery: print return label

We want to allow to print return labels on picking that contains retrun
moves and having a carrier that support return labels.

closes odoo/odoo#30886
This commit is contained in:
Pierre Masereel
2019-02-12 09:29:51 +00:00
parent b8a8c28554
commit 4a857060e1
3 changed files with 24 additions and 2 deletions
@@ -148,6 +148,11 @@ class DeliveryCarrier(models.Model):
if hasattr(self, '%s_send_shipping' % self.delivery_type):
return getattr(self, '%s_send_shipping' % self.delivery_type)(pickings)
def get_return_label(self,pickings):
self.ensure_one()
if hasattr(self, '%s_get_return_label' % self.delivery_type):
return getattr(self, '%s_get_return_label' % self.delivery_type)(pickings)
def get_tracking_link(self, picking):
''' Ask the tracking link to the service provider
+14 -1
View File
@@ -105,12 +105,20 @@ class StockPicking(models.Model):
package_ids = fields.Many2many('stock.quant.package', compute='_compute_packages', string='Packages')
weight_bulk = fields.Float('Bulk Weight', compute='_compute_bulk_weight')
shipping_weight = fields.Float("Weight for Shipping", compute='_compute_shipping_weight', help="Total weight of the packages and products which are not in a package. That's the weight used to compute the cost of the shipping.")
is_return_picking = fields.Boolean(compute='_compute_return_picking')
@api.depends('carrier_id', 'carrier_tracking_ref')
def _compute_carrier_tracking_url(self):
for picking in self:
picking.carrier_tracking_url = picking.carrier_id.get_tracking_link(picking) if picking.carrier_id and picking.carrier_tracking_ref else False
@api.depends('carrier_id', 'move_ids_without_package')
def _compute_return_picking(self):
for picking in self:
if picking.carrier_id and hasattr(picking.carrier_id, '%s_get_return_label' % picking.carrier_id.delivery_type):
picking.is_return_picking = any(m.origin_returned_move_id for m in picking.move_ids_without_package)
else:
picking.is_return_picking = False
@api.depends('move_lines')
def _cal_weight(self):
for picking in self:
@@ -121,7 +129,7 @@ class StockPicking(models.Model):
res = super(StockPicking, self).action_done()
for pick in self:
if pick.carrier_id:
if pick.carrier_id.integration_level == 'rate_and_ship':
if pick.carrier_id.integration_level == 'rate_and_ship' and pick.picking_type_code != 'incoming':
pick.send_to_shipper()
pick._add_delivery_cost_to_so()
return res
@@ -194,6 +202,11 @@ class StockPicking(models.Model):
else:
raise UserError(_("Unable to update the delivery price because of: ") + res['error_message'])
@api.multi
def print_return_label(self):
self.ensure_one()
res = self.carrier_id.get_return_label(self)
@api.multi
def _add_delivery_cost_to_so(self):
self.ensure_one()
+5 -1
View File
@@ -206,6 +206,7 @@
<data>
<xpath expr="//group[@name='other_infos']" position="before">
<group name='carrier_data' string="Shipping Information">
<field name="is_return_picking" invisible="1"/>
<field name="carrier_id" attrs="{'readonly': [('state', 'in', ('done', 'cancel'))]}" options="{'no_create': True, 'no_open': True}"/>
<field name="delivery_type" attrs="{'invisible':True}"/>
<label for="carrier_tracking_ref"/>
@@ -230,7 +231,10 @@
attrs="{'invisible': ['|','|',('carrier_tracking_ref','=',False),('carrier_id', '=', False),('delivery_type','=','grid')]}" />
</div>
<xpath expr="/form/header/button[last()]" position="after">
<button name="send_to_shipper" string="Send to Shipper" type="object" attrs="{'invisible':['|','|','|',('carrier_tracking_ref','!=',False),('delivery_type','in', ['fixed', 'base_on_rule']),('delivery_type','=',False),('state','not in',('done'))]}"/>
<button name="send_to_shipper" string="Send to Shipper" type="object" attrs="{'invisible':['|','|','|','|',('carrier_tracking_ref','!=',False),('delivery_type','in', ['fixed', 'base_on_rule']),('delivery_type','=',False),('state','not in',('done')),('picking_type_code', '=', 'incoming')]}"/>
</xpath>
<xpath expr="/form/header/button[last()]" position="after">
<button name="print_return_label" string="Print Return Label" type="object" attrs="{'invisible':['|', ('is_return_picking', '=', False),('state', '=', 'done')]}"/>
</xpath>
<xpath expr="//button[@name='do_print_picking']" position="after">
<button name="action_send_confirmation_email" string="Send Confirmation Email" type="object" attrs="{'invisible':['|', ('state', '!=', 'done'), ('carrier_id', '=', False)]}"/>