mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[MIG] delivery_easypost_hibou: to 15.0
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
'name': 'Hibou EasyPost Shipping',
|
||||
'version': '13.0.1.0.0',
|
||||
'version': '15.0.1.0.0',
|
||||
'category': 'Stock',
|
||||
'author': "Hibou Corp.",
|
||||
'license': 'AGPL-3',
|
||||
|
||||
@@ -20,12 +20,13 @@ class DeliveryCarrier(models.Model):
|
||||
Once the order is purchased. It will post as message the tracking
|
||||
links and the shipping labels.
|
||||
"""
|
||||
res = []
|
||||
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)
|
||||
for picking in pickings:
|
||||
# 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',)
|
||||
result = ep.send_shipping(self, picking.partner_id, picking.picking_type_id.warehouse_id.partner_id,
|
||||
picking=picking, is_return=is_return)
|
||||
@@ -33,8 +34,9 @@ class DeliveryCarrier(models.Model):
|
||||
shipper = superself.get_shipper_warehouse(picking=picking)
|
||||
recipient = superself.get_recipient(picking=picking)
|
||||
result = ep.send_shipping(self, recipient, shipper, picking=picking)
|
||||
|
||||
if result.get('error_message'):
|
||||
raise UserError(_(result['error_message']))
|
||||
raise UserError(result['error_message'])
|
||||
rate = result.get('rate')
|
||||
if rate['currency'] == picking.company_id.currency_id.name:
|
||||
price = float(rate['rate'])
|
||||
@@ -56,16 +58,17 @@ class DeliveryCarrier(models.Model):
|
||||
|
||||
logmessage = _("Shipment created into Easypost<br/>"
|
||||
"<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 = {
|
||||
'exact_price': price,
|
||||
'tracking_number': carrier_tracking_ref,
|
||||
}
|
||||
shipping_data = {'exact_price': price,
|
||||
'tracking_number': carrier_tracking_ref}
|
||||
res = res + [shipping_data]
|
||||
# store order reference on picking
|
||||
picking.ep_order_ref = result.get('id')
|
||||
if picking.carrier_id.return_label_on_delivery:
|
||||
self.get_return_label(picking)
|
||||
return res
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from odoo.tools.float_utils import float_round, float_is_zero
|
||||
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.
|
||||
|
||||
@@ -15,10 +16,9 @@ def _prepare_order_shipments(self, carrier, order):
|
||||
in different packages. It also ignores customs info.
|
||||
"""
|
||||
# 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
|
||||
total_weight = carrier._easypost_convert_weight(
|
||||
sum([(line.product_id.weight * line.product_uom_qty) for line in order.order_line if not line.display_type]))
|
||||
total_weight = carrier._easypost_convert_weight(order._get_estimated_weight())
|
||||
|
||||
# Create shipments
|
||||
shipments = {}
|
||||
@@ -28,19 +28,15 @@ def _prepare_order_shipments(self, carrier, order):
|
||||
# Remainder for last package.
|
||||
last_shipment_weight = float_round(total_weight % max_weight, precision_digits=1)
|
||||
for shp_id in range(0, total_shipment):
|
||||
shipments.update(self._prepare_parcel(shp_id, carrier.easypost_default_packaging_id, max_weight,
|
||||
carrier.easypost_label_file_type))
|
||||
shipments.update(self._prepare_parcel(shp_id, carrier.easypost_default_package_type_id, max_weight, carrier.easypost_label_file_type))
|
||||
shipments.update(self._customs_info_sale_order(shp_id, order.order_line))
|
||||
shipments.update(self._options(shp_id, carrier))
|
||||
if not float_is_zero(last_shipment_weight, precision_digits=1):
|
||||
shipments.update(
|
||||
self._prepare_parcel(total_shipment, carrier.easypost_default_packaging_id, last_shipment_weight,
|
||||
carrier.easypost_label_file_type))
|
||||
shipments.update(self._prepare_parcel(total_shipment, carrier.easypost_default_package_type_id, last_shipment_weight, carrier.easypost_label_file_type))
|
||||
shipments.update(self._customs_info_sale_order(shp_id, order.order_line))
|
||||
shipments.update(self._options(total_shipment, carrier))
|
||||
else:
|
||||
shipments.update(self._prepare_parcel(0, carrier.easypost_default_packaging_id, total_weight,
|
||||
carrier.easypost_label_file_type))
|
||||
shipments.update(self._prepare_parcel(0, carrier.easypost_default_package_type_id, total_weight, carrier.easypost_label_file_type))
|
||||
shipments.update(self._customs_info_sale_order(0, order.order_line))
|
||||
shipments.update(self._options(0, carrier))
|
||||
return shipments
|
||||
@@ -106,7 +102,7 @@ def _customs_info(self, shipment_id, lines):
|
||||
# only need early return if one line does this
|
||||
if line.picking_id.picking_type_id.warehouse_id.partner_id.country_id.code == line.picking_id.partner_id.country_id.code:
|
||||
return {}
|
||||
|
||||
|
||||
# skip service
|
||||
if line.product_id.type not in ['product', 'consu']:
|
||||
continue
|
||||
@@ -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')
|
||||
else:
|
||||
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 ''
|
||||
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({
|
||||
'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][value]' % (shipment_id, customs_item_id): unit_quantity * price_unit,
|
||||
'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): 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][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,
|
||||
|
||||
Reference in New Issue
Block a user