Help

0

How can i customise shipping label, generated on Shipment Validation? Want to add a custom field to the pdf label.

Avatar
Gaurav Choudhary

In Odoo-10.0, When we validate shipment/delivery we get a shipping label generated in Attachments. I want to add a custom fields, I made on Sale order form view, on to the Shipping Label being genrated, looking at the shipping Label name that's coming from backend as well, I found this particular code:

labels = []
track_numbers = []
for track_number, label_binary_data in result.get('label_binary_data').iteritems():
logmessage = (_("Shipment created into UPS <br/> <b>Tracking Number : </b>%s") % (track_number))
picking.message_post(body=logmessage)
if self.ups_label_file_type == 'GIF':
labels.append(('LabelUPS-%s.pdf' % track_number, label_binary_data))
else:
labels.append(('LabelUPS-%s.%s' % (track_number, self.ups_label_file_type), label_binary_data))
track_numbers.append(track_number)
logmessage = (_("Shipping label for packages"))
picking.message_post(body=logmessage, attachments=labels)

above is specking block in the following function, in delivery_ups.py:

def ups_send_shipping(self, pickings):
res = []
superself = self.sudo()
srm = UPSRequest(superself.ups_username, superself.ups_passwd, superself.ups_shipper_number, superself.ups_access_number, self.prod_environment)
ResCurrency = self.env['res.currency']
for picking in pickings:

packages = []
total_qty = 0
if picking.package_ids:
# Create all packages
for package in picking.package_ids:
total_qty += sum(quant.qty for quant in package.quant_ids)
packages.append(Package(self, package.shipping_weight, quant_pack=package.packaging_id, name=package.name))
# Create one package with the rest (the content that is not in a package)
if picking.weight_bulk:
packages.append(Package(self, picking.weight_bulk))

invoice_line_total = 0
for move in picking.move_lines:
invoice_line_total += picking.company_id.currency_id.round(move.product_id.lst_price * move.product_qty)

shipment_info = {
'description': picking.origin,
'total_qty': total_qty,
'ilt_monetary_value': '%d' % invoice_line_total,
'itl_currency_code': self.env.user.company_id.currency_id.name,
}
srm.check_required_value(picking.company_id.partner_id, picking.picking_type_id.warehouse_id.partner_id, picking.partner_id, picking=picking)

package_type = picking.package_ids and picking.package_ids[0].packaging_id.shipper_package_code or self.ups_default_packaging_id.shipper_package_code
result = srm.send_shipping(
shipment_info=shipment_info, packages=packages, shipper=picking.company_id.partner_id, ship_from=picking.picking_type_id.warehouse_id.partner_id,
ship_to=picking.partner_id, packaging_type=package_type, service_type=self.ups_default_service_type, label_file_type=self.ups_label_file_type)

if result.get('error_message'):
raise ValidationError(result['error_message'])

currency_order = picking.sale_id.currency_id
if not currency_order:
currency_order = picking.company_id.currency_id

if currency_order.name == result['currency_code']:
price = float(result['price'])
else:
quote_currency = ResCurrency.search([('name', '=', result['currency_code'])], limit=1)
price = quote_currency.compute(float(result['price']), currency_order)
labels = []
track_numbers = []
for track_number, label_binary_data in result.get('label_binary_data').iteritems():
logmessage = (_("Shipment created into UPS <br/> <b>Tracking Number : </b>%s") % (track_number))
picking.message_post(body=logmessage)
if self.ups_label_file_type == 'GIF':
labels.append(('LabelUPS-%s.pdf' % track_number, label_binary_data))
else:
labels.append(('LabelUPS-%s.%s' % (track_number, self.ups_label_file_type), label_binary_data))
track_numbers.append(track_number)
logmessage = (_("Shipping label for packages"))
picking.message_post(body=logmessage, attachments=labels)

carrier_tracking_ref = "+".join(track_numbers)

shipping_data = {
'exact_price': price,
'tracking_number': carrier_tracking_ref}
res = res + [shipping_data]
return res

My confusion is:

1) I can't find any report.xml sort of file from where that pdf information is being defined

and

2) in code above, this line:

picking.message_post(body=logmessage, attachments=labels)

now while debugging I found that picking is a record of stock.picking, But I can't find relevant function "message_post", to drill down to find where shipping label is being generated from(i.e some report.xml, sort of thing).

Please provide any help or directives, if possible.

Thank you so much for your time and consideration.

- Gaurav


Avatar
Abbandona