mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[MIG] delivery_ups_hibou: migrated from 12.0
This commit is contained in:
committed by
Jared Kipe
parent
8494686d0f
commit
55de0655c2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
'name': 'Hibou UPS Shipping',
|
'name': 'Hibou UPS Shipping',
|
||||||
'version': '12.0.1.0.0',
|
'version': '13.0.1.0.0',
|
||||||
'category': 'Stock',
|
'category': 'Stock',
|
||||||
'author': "Hibou Corp.",
|
'author': "Hibou Corp.",
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class ProviderUPS(models.Model):
|
|||||||
packages = []
|
packages = []
|
||||||
total_qty = 0
|
total_qty = 0
|
||||||
total_weight = 0
|
total_weight = 0
|
||||||
for line in order.order_line.filtered(lambda line: not line.is_delivery):
|
for line in order.order_line.filtered(lambda line: not line.is_delivery and not line.display_type):
|
||||||
total_qty += line.product_uom_qty
|
total_qty += line.product_uom_qty
|
||||||
total_weight += line.product_id.weight * line.product_qty
|
total_weight += line.product_id.weight * line.product_qty
|
||||||
|
|
||||||
@@ -180,15 +180,17 @@ class ProviderUPS(models.Model):
|
|||||||
raise UserError(check_value)
|
raise UserError(check_value)
|
||||||
|
|
||||||
package_type = picking.package_ids and picking.package_ids[0].packaging_id.shipper_package_code or self.ups_default_packaging_id.shipper_package_code
|
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(
|
srm.send_shipping(
|
||||||
shipment_info=shipment_info, packages=packages, shipper=shipper_company, ship_from=shipper_warehouse,
|
shipment_info=shipment_info, packages=packages, shipper=shipper_company, ship_from=shipper_warehouse,
|
||||||
ship_to=recipient, packaging_type=package_type, service_type=ups_service_type, label_file_type=self.ups_label_file_type, ups_carrier_account=ups_carrier_account,
|
ship_to=recipient, packaging_type=package_type, service_type=ups_service_type, duty_payment=picking.carrier_id.ups_duty_payment,
|
||||||
saturday_delivery=picking.carrier_id.ups_saturday_delivery, cod_info=cod_info)
|
label_file_type=self.ups_label_file_type, ups_carrier_account=ups_carrier_account, saturday_delivery=picking.carrier_id.ups_saturday_delivery,
|
||||||
|
cod_info=cod_info)
|
||||||
|
result = srm.process_shipment()
|
||||||
if result.get('error_message'):
|
if result.get('error_message'):
|
||||||
raise UserError(result['error_message'])
|
raise UserError(result['error_message'].__str__())
|
||||||
|
|
||||||
order = picking.sale_id
|
order = picking.sale_id
|
||||||
company = order.company_id or picking.company_id or self.env.user.company_id
|
company = order.company_id or picking.company_id or self.env.company
|
||||||
currency_order = picking.sale_id.currency_id
|
currency_order = picking.sale_id.currency_id
|
||||||
if not currency_order:
|
if not currency_order:
|
||||||
currency_order = picking.company_id.currency_id
|
currency_order = picking.company_id.currency_id
|
||||||
@@ -217,6 +219,8 @@ class ProviderUPS(models.Model):
|
|||||||
'exact_price': price,
|
'exact_price': price,
|
||||||
'tracking_number': carrier_tracking_ref}
|
'tracking_number': carrier_tracking_ref}
|
||||||
res = res + [shipping_data]
|
res = res + [shipping_data]
|
||||||
|
if self.return_label_on_delivery:
|
||||||
|
self.ups_get_return_label(picking)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def ups_rate_shipment_multi(self, order=None, picking=None):
|
def ups_rate_shipment_multi(self, order=None, picking=None):
|
||||||
|
|||||||
@@ -1,41 +1,41 @@
|
|||||||
import suds
|
from zeep.exceptions import Fault
|
||||||
from odoo.addons.delivery_ups.models.ups_request import UPSRequest
|
from odoo.addons.delivery_ups.models.ups_request import UPSRequest
|
||||||
import logging
|
import logging
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
SUDS_VERSION = suds.__version__
|
|
||||||
|
|
||||||
|
|
||||||
def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from, ship_to, packaging_type, service_type,
|
def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from, ship_to, packaging_type, service_type,
|
||||||
saturday_delivery, cod_info, date_planned=False, multi=False):
|
saturday_delivery, cod_info, date_planned=False, multi=False):
|
||||||
client = self._set_client(self.rate_wsdl, 'Rate', 'RateRequest')
|
client = self._set_client(self.rate_wsdl, 'Rate', 'RateRequest')
|
||||||
|
service = self._set_service(client, 'Rate')
|
||||||
request = client.factory.create('ns0:RequestType')
|
request = self.factory_ns3.RequestType()
|
||||||
if multi:
|
if multi:
|
||||||
request.RequestOption = 'Shop'
|
request.RequestOption = 'Shop'
|
||||||
else:
|
else:
|
||||||
request.RequestOption = 'Rate'
|
request.RequestOption = 'Rate'
|
||||||
|
|
||||||
classification = client.factory.create('ns2:CodeDescriptionType')
|
classification = self.factory_ns2.CodeDescriptionType()
|
||||||
classification.Code = '00' # Get rates for the shipper account
|
classification.Code = '00' # Get rates for the shipper account
|
||||||
classification.Description = 'Get rates for the shipper account'
|
classification.Description = 'Get rates for the shipper account'
|
||||||
|
|
||||||
namespace = 'ns2'
|
request_type = "rating"
|
||||||
shipment = client.factory.create('{}:ShipmentType'.format(namespace))
|
shipment = self.factory_ns2.ShipmentType()
|
||||||
|
|
||||||
# Hibou Delivery
|
# Hibou Delivery
|
||||||
if date_planned:
|
if date_planned:
|
||||||
if not isinstance(date_planned, str):
|
if not isinstance(date_planned, str):
|
||||||
date_planned = str(date_planned)
|
date_planned = str(date_planned)
|
||||||
shipment.DeliveryTimeInformation = client.factory.create('{}:TimeInTransitRequestType'.format(namespace))
|
shipment.DeliveryTimeInformation = self.factory_ns2.TimeInTransitRequestType()
|
||||||
shipment.DeliveryTimeInformation.Pickup = client.factory.create('{}:PickupType'.format(namespace))
|
shipment.DeliveryTimeInformation.Pickup = self.factory_ns2.PickupType()
|
||||||
shipment.DeliveryTimeInformation.Pickup.Date = date_planned.split(' ')[0]
|
shipment.DeliveryTimeInformation.Pickup.Date = date_planned.split(' ')[0]
|
||||||
# End
|
# End
|
||||||
|
|
||||||
for package in self.set_package_detail(client, packages, packaging_type, namespace, ship_from, ship_to, cod_info):
|
for package in self.set_package_detail(client, packages, packaging_type, ship_from, ship_to, cod_info, request_type):
|
||||||
shipment.Package.append(package)
|
shipment.Package.append(package)
|
||||||
|
|
||||||
|
shipment.Shipper = self.factory_ns2.ShipperType()
|
||||||
shipment.Shipper.Name = shipper.name or ''
|
shipment.Shipper.Name = shipper.name or ''
|
||||||
|
shipment.Shipper.Address = self.factory_ns2.AddressType()
|
||||||
shipment.Shipper.Address.AddressLine = [shipper.street or '', shipper.street2 or '']
|
shipment.Shipper.Address.AddressLine = [shipper.street or '', shipper.street2 or '']
|
||||||
shipment.Shipper.Address.City = shipper.city or ''
|
shipment.Shipper.Address.City = shipper.city or ''
|
||||||
shipment.Shipper.Address.PostalCode = shipper.zip or ''
|
shipment.Shipper.Address.PostalCode = shipper.zip or ''
|
||||||
@@ -45,7 +45,9 @@ def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from
|
|||||||
shipment.Shipper.ShipperNumber = self.shipper_number or ''
|
shipment.Shipper.ShipperNumber = self.shipper_number or ''
|
||||||
# shipment.Shipper.Phone.Number = shipper.phone or ''
|
# shipment.Shipper.Phone.Number = shipper.phone or ''
|
||||||
|
|
||||||
|
shipment.ShipFrom = self.factory_ns2.ShipFromType()
|
||||||
shipment.ShipFrom.Name = ship_from.name or ''
|
shipment.ShipFrom.Name = ship_from.name or ''
|
||||||
|
shipment.ShipFrom.Address = self.factory_ns2.AddressType()
|
||||||
shipment.ShipFrom.Address.AddressLine = [ship_from.street or '', ship_from.street2 or '']
|
shipment.ShipFrom.Address.AddressLine = [ship_from.street or '', ship_from.street2 or '']
|
||||||
shipment.ShipFrom.Address.City = ship_from.city or ''
|
shipment.ShipFrom.Address.City = ship_from.city or ''
|
||||||
shipment.ShipFrom.Address.PostalCode = ship_from.zip or ''
|
shipment.ShipFrom.Address.PostalCode = ship_from.zip or ''
|
||||||
@@ -54,7 +56,9 @@ def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from
|
|||||||
shipment.ShipFrom.Address.StateProvinceCode = ship_from.state_id.code or ''
|
shipment.ShipFrom.Address.StateProvinceCode = ship_from.state_id.code or ''
|
||||||
# shipment.ShipFrom.Phone.Number = ship_from.phone or ''
|
# shipment.ShipFrom.Phone.Number = ship_from.phone or ''
|
||||||
|
|
||||||
|
shipment.ShipTo = self.factory_ns2.ShipToType()
|
||||||
shipment.ShipTo.Name = ship_to.name or ''
|
shipment.ShipTo.Name = ship_to.name or ''
|
||||||
|
shipment.ShipTo.Address = self.factory_ns2.AddressType()
|
||||||
shipment.ShipTo.Address.AddressLine = [ship_to.street or '', ship_to.street2 or '']
|
shipment.ShipTo.Address.AddressLine = [ship_to.street or '', ship_to.street2 or '']
|
||||||
shipment.ShipTo.Address.City = ship_to.city or ''
|
shipment.ShipTo.Address.City = ship_to.city or ''
|
||||||
shipment.ShipTo.Address.PostalCode = ship_to.zip or ''
|
shipment.ShipTo.Address.PostalCode = ship_to.zip or ''
|
||||||
@@ -63,19 +67,22 @@ def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from
|
|||||||
shipment.ShipTo.Address.StateProvinceCode = ship_to.state_id.code or ''
|
shipment.ShipTo.Address.StateProvinceCode = ship_to.state_id.code or ''
|
||||||
# shipment.ShipTo.Phone.Number = ship_to.phone or ''
|
# shipment.ShipTo.Phone.Number = ship_to.phone or ''
|
||||||
if not ship_to.commercial_partner_id.is_company:
|
if not ship_to.commercial_partner_id.is_company:
|
||||||
shipment.ShipTo.Address.ResidentialAddressIndicator = suds.null()
|
shipment.ShipTo.Address.ResidentialAddressIndicator = None
|
||||||
|
|
||||||
if not multi:
|
if not multi:
|
||||||
|
shipment.Service = self.factory_ns2.CodeDescriptionType()
|
||||||
shipment.Service.Code = service_type or ''
|
shipment.Service.Code = service_type or ''
|
||||||
shipment.Service.Description = 'Service Code'
|
shipment.Service.Description = 'Service Code'
|
||||||
if service_type == "96":
|
if service_type == "96":
|
||||||
shipment.NumOfPieces = int(shipment_info.get('total_qty'))
|
shipment.NumOfPieces = int(shipment_info.get('total_qty'))
|
||||||
|
|
||||||
if saturday_delivery:
|
if saturday_delivery:
|
||||||
|
shipment.ShipmentServiceOptions = self.factory_ns2.ShipmentServiceOptionsType()
|
||||||
shipment.ShipmentServiceOptions.SaturdayDeliveryIndicator = saturday_delivery
|
shipment.ShipmentServiceOptions.SaturdayDeliveryIndicator = saturday_delivery
|
||||||
else:
|
else:
|
||||||
shipment.ShipmentServiceOptions = ''
|
shipment.ShipmentServiceOptions = ''
|
||||||
|
|
||||||
|
shipment.ShipmentRatingOptions = self.factory_ns2.ShipmentRatingOptionsType()
|
||||||
shipment.ShipmentRatingOptions.NegotiatedRatesIndicator = 1
|
shipment.ShipmentRatingOptions.NegotiatedRatesIndicator = 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -84,21 +91,23 @@ def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from
|
|||||||
|
|
||||||
# Check if ProcessRate is not success then return reason for that
|
# Check if ProcessRate is not success then return reason for that
|
||||||
if response.Response.ResponseStatus.Code != "1":
|
if response.Response.ResponseStatus.Code != "1":
|
||||||
error_message = self.get_error_message(response.Response.ResponseStatus.Code,
|
error_message = self.get_error_message(response.Response.ResponseStatus.Code, response.Response.ResponseStatus.Description)
|
||||||
response.Response.ResponseStatus.Description)
|
|
||||||
if multi:
|
if multi:
|
||||||
return [error_message]
|
return [error_message]
|
||||||
return error_message
|
return error_message
|
||||||
|
|
||||||
if not multi:
|
if not multi:
|
||||||
result = {}
|
rate = response.RatedShipment[0]
|
||||||
result['currency_code'] = response.RatedShipment[0].TotalCharges.CurrencyCode
|
charge = rate.TotalCharges
|
||||||
|
|
||||||
# Some users are qualified to receive negotiated rates
|
# Some users are qualified to receive negotiated rates
|
||||||
negotiated_rate = 'NegotiatedRateCharges' in response.RatedShipment[0] and response.RatedShipment[
|
if 'NegotiatedRateCharges' in rate and rate.NegotiatedRateCharges and rate.NegotiatedRateCharges.TotalCharge.MonetaryValue:
|
||||||
0].NegotiatedRateCharges.TotalCharge.MonetaryValue or None
|
charge = rate.NegotiatedRateCharges.TotalCharge
|
||||||
|
|
||||||
result['price'] = negotiated_rate or response.RatedShipment[0].TotalCharges.MonetaryValue
|
result = {
|
||||||
|
'currency_code': charge.CurrencyCode,
|
||||||
|
'price': charge.MonetaryValue,
|
||||||
|
}
|
||||||
|
|
||||||
# Hibou Delivery
|
# Hibou Delivery
|
||||||
if hasattr(response.RatedShipment[0], 'GuaranteedDelivery') and hasattr(response.RatedShipment[0].GuaranteedDelivery, 'BusinessDaysInTransit'):
|
if hasattr(response.RatedShipment[0], 'GuaranteedDelivery') and hasattr(response.RatedShipment[0].GuaranteedDelivery, 'BusinessDaysInTransit'):
|
||||||
@@ -106,33 +115,30 @@ def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from
|
|||||||
# End
|
# End
|
||||||
else:
|
else:
|
||||||
result = []
|
result = []
|
||||||
for rated_shipment in response.RatedShipment:
|
for rate in response.RatedShipment:
|
||||||
rate = {}
|
charge = rate.TotalCharges
|
||||||
rate['currency_code'] = rated_shipment.TotalCharges.CurrencyCode
|
|
||||||
|
|
||||||
# Some users are qualified to receive negotiated rates
|
# Some users are qualified to receive negotiated rates
|
||||||
negotiated_rate = 'NegotiatedRateCharges' in rated_shipment and response.RatedShipment[
|
if 'NegotiatedRateCharges' in rate and rate.NegotiatedRateCharges and rate.NegotiatedRateCharges.TotalCharge.MonetaryValue:
|
||||||
0].NegotiatedRateCharges.TotalCharge.MonetaryValue or None
|
charge = rate.NegotiatedRateCharges.TotalCharge
|
||||||
|
|
||||||
rate['price'] = negotiated_rate or rated_shipment.TotalCharges.MonetaryValue
|
rated_shipment = {
|
||||||
|
'currency_code': charge.CurrencyCode,
|
||||||
|
'price': charge.MonetaryValue,
|
||||||
|
}
|
||||||
|
|
||||||
# Hibou Delivery
|
# Hibou Delivery
|
||||||
if hasattr(rated_shipment, 'GuaranteedDelivery') and hasattr(
|
if hasattr(response.RatedShipment[0], 'GuaranteedDelivery') and hasattr(
|
||||||
rated_shipment.GuaranteedDelivery, 'BusinessDaysInTransit'):
|
response.RatedShipment[0].GuaranteedDelivery, 'BusinessDaysInTransit'):
|
||||||
rate['transit_days'] = int(rated_shipment.GuaranteedDelivery.BusinessDaysInTransit)
|
rated_shipment['transit_days'] = int(response.RatedShipment[0].GuaranteedDelivery.BusinessDaysInTransit)
|
||||||
# End
|
# End
|
||||||
rate['service_code'] = rated_shipment.Service.Code
|
result.append(rated_shipment)
|
||||||
result.append(rate)
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
except suds.WebFault as e:
|
except Fault as e:
|
||||||
# childAtPath behaviour is changing at version 0.6
|
code = e.detail.xpath("//err:PrimaryErrorCode/err:Code", namespaces=self.ns)[0].text
|
||||||
prefix = ''
|
description = e.detail.xpath("//err:PrimaryErrorCode/err:Description", namespaces=self.ns)[0].text
|
||||||
if SUDS_VERSION >= "0.6":
|
error_message = self.get_error_message(code, description)
|
||||||
prefix = '/Envelope/Body/Fault'
|
|
||||||
error_message = self.get_error_message(
|
|
||||||
e.document.childAtPath(prefix + '/detail/Errors/ErrorDetail/PrimaryErrorCode/Code').getText(),
|
|
||||||
e.document.childAtPath(prefix + '/detail/Errors/ErrorDetail/PrimaryErrorCode/Description').getText())
|
|
||||||
if multi:
|
if multi:
|
||||||
return [error_message]
|
return [error_message]
|
||||||
return error_message
|
return error_message
|
||||||
|
|||||||
Reference in New Issue
Block a user