[MIG] delivery_easypost_hibou: to 15.0

This commit is contained in:
Jared Kipe
2022-05-13 21:22:54 +00:00
parent 464d0c85de
commit 19e00765e2
3 changed files with 24 additions and 24 deletions

View File

@@ -1,6 +1,6 @@
{ {
'name': 'Hibou EasyPost Shipping', 'name': 'Hibou EasyPost Shipping',
'version': '13.0.1.0.0', 'version': '15.0.1.0.0',
'category': 'Stock', 'category': 'Stock',
'author': "Hibou Corp.", 'author': "Hibou Corp.",
'license': 'AGPL-3', 'license': 'AGPL-3',

View File

@@ -20,12 +20,13 @@ class DeliveryCarrier(models.Model):
Once the order is purchased. It will post as message the tracking Once the order is purchased. It will post as message the tracking
links and the shipping labels. links and the shipping labels.
""" """
res = []
superself = self.sudo() superself = self.sudo()
res = []
ep = EasypostRequest(self.sudo().easypost_production_api_key if self.prod_environment else self.sudo().easypost_test_api_key, self.log_xml) ep = EasypostRequest(self.sudo().easypost_production_api_key if self.prod_environment else self.sudo().easypost_test_api_key, self.log_xml)
for picking in pickings: for picking in pickings:
# Call Hibou delivery method to get picking type # Call Hibou delivery method to get picking type
if superself.easypost_return_method == 'ep': if self.easypost_return_method == 'ep':
is_return = superself._classify_picking(picking) in ('in', 'dropship_in',) is_return = superself._classify_picking(picking) in ('in', 'dropship_in',)
result = ep.send_shipping(self, picking.partner_id, picking.picking_type_id.warehouse_id.partner_id, result = ep.send_shipping(self, picking.partner_id, picking.picking_type_id.warehouse_id.partner_id,
picking=picking, is_return=is_return) picking=picking, is_return=is_return)
@@ -33,8 +34,9 @@ class DeliveryCarrier(models.Model):
shipper = superself.get_shipper_warehouse(picking=picking) shipper = superself.get_shipper_warehouse(picking=picking)
recipient = superself.get_recipient(picking=picking) recipient = superself.get_recipient(picking=picking)
result = ep.send_shipping(self, recipient, shipper, picking=picking) result = ep.send_shipping(self, recipient, shipper, picking=picking)
if result.get('error_message'): if result.get('error_message'):
raise UserError(_(result['error_message'])) raise UserError(result['error_message'])
rate = result.get('rate') rate = result.get('rate')
if rate['currency'] == picking.company_id.currency_id.name: if rate['currency'] == picking.company_id.currency_id.name:
price = float(rate['rate']) price = float(rate['rate'])
@@ -56,16 +58,17 @@ class DeliveryCarrier(models.Model):
logmessage = _("Shipment created into Easypost<br/>" logmessage = _("Shipment created into Easypost<br/>"
"<b>Tracking Numbers:</b> %s<br/>") % (carrier_tracking_link) "<b>Tracking Numbers:</b> %s<br/>") % (carrier_tracking_link)
pickings.message_post(body=logmessage, attachments=labels) if picking.sale_id:
for pick in picking.sale_id.picking_ids:
pick.message_post(body=logmessage, attachments=labels)
else:
picking.message_post(body=logmessage, attachments=labels)
shipping_data = { shipping_data = {'exact_price': price,
'exact_price': price, 'tracking_number': carrier_tracking_ref}
'tracking_number': carrier_tracking_ref,
}
res = res + [shipping_data] res = res + [shipping_data]
# store order reference on picking # store order reference on picking
picking.ep_order_ref = result.get('id') picking.ep_order_ref = result.get('id')
if picking.carrier_id.return_label_on_delivery: if picking.carrier_id.return_label_on_delivery:
self.get_return_label(picking) self.get_return_label(picking)
return res return res

View File

@@ -1,5 +1,6 @@
from odoo.tools.float_utils import float_round, float_is_zero from odoo.tools.float_utils import float_round, float_is_zero
from odoo.addons.delivery_easypost.models.easypost_request import EasypostRequest from odoo.addons.delivery_easypost.models.easypost_request import EasypostRequest
from odoo.tools.float_utils import float_round, float_is_zero, float_repr
# Patches to add customs lines during SO rating. # Patches to add customs lines during SO rating.
@@ -15,10 +16,9 @@ def _prepare_order_shipments(self, carrier, order):
in different packages. It also ignores customs info. in different packages. It also ignores customs info.
""" """
# Max weight for carrier default package # Max weight for carrier default package
max_weight = carrier._easypost_convert_weight(carrier.easypost_default_packaging_id.max_weight) max_weight = carrier._easypost_convert_weight(carrier.easypost_default_package_type_id.max_weight)
# Order weight # Order weight
total_weight = carrier._easypost_convert_weight( total_weight = carrier._easypost_convert_weight(order._get_estimated_weight())
sum([(line.product_id.weight * line.product_uom_qty) for line in order.order_line if not line.display_type]))
# Create shipments # Create shipments
shipments = {} shipments = {}
@@ -28,19 +28,15 @@ def _prepare_order_shipments(self, carrier, order):
# Remainder for last package. # Remainder for last package.
last_shipment_weight = float_round(total_weight % max_weight, precision_digits=1) last_shipment_weight = float_round(total_weight % max_weight, precision_digits=1)
for shp_id in range(0, total_shipment): for shp_id in range(0, total_shipment):
shipments.update(self._prepare_parcel(shp_id, carrier.easypost_default_packaging_id, max_weight, shipments.update(self._prepare_parcel(shp_id, carrier.easypost_default_package_type_id, max_weight, carrier.easypost_label_file_type))
carrier.easypost_label_file_type))
shipments.update(self._customs_info_sale_order(shp_id, order.order_line)) shipments.update(self._customs_info_sale_order(shp_id, order.order_line))
shipments.update(self._options(shp_id, carrier)) shipments.update(self._options(shp_id, carrier))
if not float_is_zero(last_shipment_weight, precision_digits=1): if not float_is_zero(last_shipment_weight, precision_digits=1):
shipments.update( shipments.update(self._prepare_parcel(total_shipment, carrier.easypost_default_package_type_id, last_shipment_weight, carrier.easypost_label_file_type))
self._prepare_parcel(total_shipment, carrier.easypost_default_packaging_id, last_shipment_weight,
carrier.easypost_label_file_type))
shipments.update(self._customs_info_sale_order(shp_id, order.order_line)) shipments.update(self._customs_info_sale_order(shp_id, order.order_line))
shipments.update(self._options(total_shipment, carrier)) shipments.update(self._options(total_shipment, carrier))
else: else:
shipments.update(self._prepare_parcel(0, carrier.easypost_default_packaging_id, total_weight, shipments.update(self._prepare_parcel(0, carrier.easypost_default_package_type_id, total_weight, carrier.easypost_label_file_type))
carrier.easypost_label_file_type))
shipments.update(self._customs_info_sale_order(0, order.order_line)) shipments.update(self._customs_info_sale_order(0, order.order_line))
shipments.update(self._options(0, carrier)) shipments.update(self._options(0, carrier))
return shipments return shipments
@@ -114,12 +110,13 @@ def _customs_info(self, shipment_id, lines):
unit_quantity = line.product_uom_id._compute_quantity(line.product_qty, line.product_id.uom_id, rounding_method='HALF-UP') unit_quantity = line.product_uom_id._compute_quantity(line.product_qty, line.product_id.uom_id, rounding_method='HALF-UP')
else: else:
unit_quantity = line.product_uom_id._compute_quantity(line.qty_done, line.product_id.uom_id, rounding_method='HALF-UP') unit_quantity = line.product_uom_id._compute_quantity(line.qty_done, line.product_id.uom_id, rounding_method='HALF-UP')
rounded_qty = max(1, float_round(unit_quantity, precision_digits=0, rounding_method='HALF-UP'))
rounded_qty = float_repr(rounded_qty, precision_digits=0)
hs_code = line.product_id.hs_code or '' hs_code = line.product_id.hs_code or ''
price_unit = line.move_id.sale_line_id.price_reduce_taxinc if line.move_id.sale_line_id else line.product_id.list_price
customs_info.update({ customs_info.update({
'order[shipments][%d][customs_info][customs_items][%d][description]' % (shipment_id, customs_item_id): line.product_id.name, 'order[shipments][%d][customs_info][customs_items][%d][description]' % (shipment_id, customs_item_id): line.product_id.name,
'order[shipments][%d][customs_info][customs_items][%d][quantity]' % (shipment_id, customs_item_id): unit_quantity, 'order[shipments][%d][customs_info][customs_items][%d][quantity]' % (shipment_id, customs_item_id): rounded_qty,
'order[shipments][%d][customs_info][customs_items][%d][value]' % (shipment_id, customs_item_id): unit_quantity * price_unit, 'order[shipments][%d][customs_info][customs_items][%d][value]' % (shipment_id, customs_item_id): line.sale_price,
'order[shipments][%d][customs_info][customs_items][%d][currency]' % (shipment_id, customs_item_id): line.picking_id.company_id.currency_id.name, 'order[shipments][%d][customs_info][customs_items][%d][currency]' % (shipment_id, customs_item_id): line.picking_id.company_id.currency_id.name,
'order[shipments][%d][customs_info][customs_items][%d][weight]' % (shipment_id, customs_item_id): line.env['delivery.carrier']._easypost_convert_weight(line.product_id.weight * unit_quantity), 'order[shipments][%d][customs_info][customs_items][%d][weight]' % (shipment_id, customs_item_id): line.env['delivery.carrier']._easypost_convert_weight(line.product_id.weight * unit_quantity),
'order[shipments][%d][customs_info][customs_items][%d][origin_country]' % (shipment_id, customs_item_id): line.picking_id.picking_type_id.warehouse_id.partner_id.country_id.code, 'order[shipments][%d][customs_info][customs_items][%d][origin_country]' % (shipment_id, customs_item_id): line.picking_id.picking_type_id.warehouse_id.partner_id.country_id.code,