mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[IMP] delivery_fedex_hibou,delivery_hibou,delivery_ups_hibou,sale_planner: cancel warehouse specific tracking numbers, other fixes for 12
This commit is contained in:
@@ -1,11 +1,41 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from os import path as os_path
|
||||
import suds
|
||||
from odoo.addons.delivery_ups.models.ups_request import UPSRequest, Package
|
||||
|
||||
SUDS_VERSION = suds.__version__
|
||||
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
SUDS_VERSION = suds.__version__
|
||||
# If you're getting SOAP/suds errors
|
||||
# logging.getLogger('suds.client').setLevel(logging.DEBUG)
|
||||
|
||||
TNT_CODE_MAP = {
|
||||
'GND': '03',
|
||||
# TODO fill in the rest if needed....
|
||||
}
|
||||
|
||||
|
||||
def patched__init__(self, debug_logger, username, password, shipper_number, access_number, prod_environment):
|
||||
self.debug_logger = debug_logger
|
||||
# Product and Testing url
|
||||
self.endurl = "https://onlinetools.ups.com/webservices/"
|
||||
if not prod_environment:
|
||||
self.endurl = "https://wwwcie.ups.com/webservices/"
|
||||
|
||||
# Basic detail require to authenticate
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.shipper_number = shipper_number
|
||||
self.access_number = access_number
|
||||
|
||||
self.rate_wsdl = '../api/RateWS.wsdl'
|
||||
self.ship_wsdl = '../api/Ship.wsdl'
|
||||
self.void_wsdl = '../api/Void.wsdl'
|
||||
dirname = os_path.dirname(__file__)
|
||||
self.tnt_wsdl = os_path.join(dirname, '../api/TNTWS.wsdl')
|
||||
|
||||
|
||||
def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from, ship_to, packaging_type, service_type,
|
||||
@@ -13,10 +43,10 @@ def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from
|
||||
client = self._set_client(self.rate_wsdl, 'Rate', 'RateRequest')
|
||||
|
||||
request = client.factory.create('ns0:RequestType')
|
||||
|
||||
request.RequestOption = 'Rate'
|
||||
if multi:
|
||||
request.RequestOption = 'Shop'
|
||||
else:
|
||||
request.RequestOption = 'Rate'
|
||||
|
||||
classification = client.factory.create('ns2:CodeDescriptionType')
|
||||
classification.Code = '00' # Get rates for the shipper account
|
||||
@@ -67,11 +97,10 @@ def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from
|
||||
if not ship_to.commercial_partner_id.is_company:
|
||||
shipment.ShipTo.Address.ResidentialAddressIndicator = suds.null()
|
||||
|
||||
if not multi:
|
||||
shipment.Service.Code = service_type or ''
|
||||
shipment.Service.Description = 'Service Code'
|
||||
if service_type == "96":
|
||||
shipment.NumOfPieces = int(shipment_info.get('total_qty'))
|
||||
shipment.Service.Code = service_type or ''
|
||||
shipment.Service.Description = 'Service Code'
|
||||
if service_type == "96":
|
||||
shipment.NumOfPieces = int(shipment_info.get('total_qty'))
|
||||
|
||||
if saturday_delivery:
|
||||
shipment.ShipmentServiceOptions.SaturdayDeliveryIndicator = saturday_delivery
|
||||
@@ -86,13 +115,65 @@ def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from
|
||||
|
||||
# Check if ProcessRate is not success then return reason for that
|
||||
if response.Response.ResponseStatus.Code != "1":
|
||||
error_message = self.get_error_message(response.Response.ResponseStatus.Code,
|
||||
response.Response.ResponseStatus.Description)
|
||||
if multi:
|
||||
return [error_message]
|
||||
return error_message
|
||||
return self.get_error_message(response.Response.ResponseStatus.Code,
|
||||
response.Response.ResponseStatus.Description)
|
||||
|
||||
if not multi:
|
||||
if multi:
|
||||
result = []
|
||||
tnt_response = None
|
||||
tnt_ready = False
|
||||
for rated_shipment in response.RatedShipment:
|
||||
res = {}
|
||||
res['service_code'] = rated_shipment.Service.Code
|
||||
res['currency_code'] = rated_shipment.TotalCharges.CurrencyCode
|
||||
negotiated_rate = 'NegotiatedRateCharges' in rated_shipment and rated_shipment.NegotiatedRateCharges.TotalCharge.MonetaryValue or None
|
||||
|
||||
res['price'] = negotiated_rate or rated_shipment.TotalCharges.MonetaryValue
|
||||
# Hibou Delivery
|
||||
if hasattr(rated_shipment, 'GuaranteedDelivery') and hasattr(rated_shipment.GuaranteedDelivery, 'BusinessDaysInTransit'):
|
||||
res['transit_days'] = int(rated_shipment.GuaranteedDelivery.BusinessDaysInTransit)
|
||||
|
||||
if not res.get('transit_days') and date_planned:
|
||||
if not tnt_response:
|
||||
try:
|
||||
tnt_client = self._set_client(self.tnt_wsdl, 'TimeInTransit', 'TimeInTransitRequest')
|
||||
tnt_request = tnt_client.factory.create('tnt:TimeInTransitRequest')
|
||||
tnt_request.Request.RequestOption = 'TNT'
|
||||
|
||||
tnt_request.ShipFrom.Address.City = ship_from.city or ''
|
||||
tnt_request.ShipFrom.Address.CountryCode = ship_from.country_id.code or ''
|
||||
tnt_request.ShipFrom.Address.PostalCode = ship_from.zip or ''
|
||||
if ship_from.country_id.code in ('US', 'CA', 'IE'):
|
||||
tnt_request.ShipFrom.Address.StateProvinceCode = ship_from.state_id.code or ''
|
||||
|
||||
tnt_request.ShipTo.Address.City = ship_to.city or ''
|
||||
tnt_request.ShipTo.Address.CountryCode = ship_to.country_id.code or ''
|
||||
tnt_request.ShipTo.Address.PostalCode = ship_to.zip or ''
|
||||
if ship_to.country_id.code in ('US', 'CA', 'IE'):
|
||||
tnt_request.ShipTo.Address.StateProvinceCode = ship_to.state_id.code or ''
|
||||
|
||||
tnt_request.Pickup.Date = date_planned.split(' ')[0].replace('-', '')
|
||||
tnt_request.Pickup.Time = date_planned.split(' ')[1].replace(':', '')
|
||||
|
||||
# tnt_request_transit_from = tnt_client.factory.create('ns1:TransitFrom')
|
||||
tnt_response = tnt_client.service.ProcessTimeInTransit(Request=tnt_request.Request,
|
||||
ShipFrom=tnt_request.ShipFrom,
|
||||
ShipTo=tnt_request.ShipTo,
|
||||
Pickup=tnt_request.Pickup)
|
||||
tnt_ready = tnt_response.Response.ResponseStatus.Code == "1"
|
||||
except Exception as e:
|
||||
_logger.warning('exception during the UPS Time In Transit request. ' + str(e))
|
||||
tnt_ready = False
|
||||
tnt_response = '-1'
|
||||
if tnt_ready:
|
||||
for service in tnt_response.TransitResponse.ServiceSummary:
|
||||
if TNT_CODE_MAP.get(service.Service.Code) == service_type:
|
||||
if hasattr(service, 'EstimatedArrival') and hasattr(service.EstimatedArrival, 'BusinessDaysInTransit'):
|
||||
res['transit_days'] = int(service.EstimatedArrival.BusinessDaysInTransit)
|
||||
break
|
||||
# use TNT API to
|
||||
result.append(res)
|
||||
else:
|
||||
result = {}
|
||||
result['currency_code'] = response.RatedShipment[0].TotalCharges.CurrencyCode
|
||||
|
||||
@@ -101,30 +182,16 @@ def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from
|
||||
0].NegotiatedRateCharges.TotalCharge.MonetaryValue or None
|
||||
|
||||
result['price'] = negotiated_rate or response.RatedShipment[0].TotalCharges.MonetaryValue
|
||||
|
||||
# Hibou Delivery
|
||||
if hasattr(response.RatedShipment[0], 'GuaranteedDelivery') and hasattr(response.RatedShipment[0].GuaranteedDelivery, 'BusinessDaysInTransit'):
|
||||
result['transit_days'] = int(response.RatedShipment[0].GuaranteedDelivery.BusinessDaysInTransit)
|
||||
# End
|
||||
else:
|
||||
result = []
|
||||
for rated_shipment in response.RatedShipment:
|
||||
rate = {}
|
||||
rate['currency_code'] = rated_shipment.TotalCharges.CurrencyCode
|
||||
|
||||
# Some users are qualified to receive negotiated rates
|
||||
negotiated_rate = 'NegotiatedRateCharges' in rated_shipment and response.RatedShipment[
|
||||
0].NegotiatedRateCharges.TotalCharge.MonetaryValue or None
|
||||
if not result.get('transit_days') and date_planned:
|
||||
# use TNT API to
|
||||
_logger.warning(' We would now use the TNT service. But who would show the transit days? 2')
|
||||
|
||||
rate['price'] = negotiated_rate or rated_shipment.TotalCharges.MonetaryValue
|
||||
# End
|
||||
|
||||
# Hibou Delivery
|
||||
if hasattr(rated_shipment, 'GuaranteedDelivery') and hasattr(
|
||||
rated_shipment.GuaranteedDelivery, 'BusinessDaysInTransit'):
|
||||
rate['transit_days'] = int(rated_shipment.GuaranteedDelivery.BusinessDaysInTransit)
|
||||
# End
|
||||
rate['service_code'] = rated_shipment.Service.Code
|
||||
result.append(rate)
|
||||
return result
|
||||
|
||||
except suds.WebFault as e:
|
||||
@@ -132,17 +199,11 @@ def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from
|
||||
prefix = ''
|
||||
if SUDS_VERSION >= "0.6":
|
||||
prefix = '/Envelope/Body/Fault'
|
||||
error_message = self.get_error_message(
|
||||
return 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:
|
||||
return [error_message]
|
||||
return error_message
|
||||
except IOError as e:
|
||||
error_message = self.get_error_message('0', 'UPS Server Not Found:\n%s' % e)
|
||||
if multi:
|
||||
return [error_message]
|
||||
return error_message
|
||||
return self.get_error_message('0', 'UPS Server Not Found:\n%s' % e)
|
||||
|
||||
|
||||
def patched_send_shipping(self, shipment_info, packages, shipper, ship_from, ship_to, packaging_type, service_type, saturday_delivery, cod_info=None, label_file_type='GIF', ups_carrier_account=False):
|
||||
@@ -306,6 +367,7 @@ def patched_set_package_detail(self, client, packages, packaging_type, namespace
|
||||
return Packages
|
||||
|
||||
|
||||
UPSRequest.__init__ = patched__init__
|
||||
UPSRequest.get_shipping_price = patched_get_shipping_price
|
||||
UPSRequest.send_shipping = patched_send_shipping
|
||||
UPSRequest.set_package_detail = patched_set_package_detail
|
||||
@@ -313,16 +375,14 @@ UPSRequest.set_package_detail = patched_set_package_detail
|
||||
|
||||
def patched__init__2(self, carrier, weight, quant_pack=False, name='',
|
||||
insurance_value=False, insurance_currency_code=False, signature_required=False):
|
||||
self.weight = self._convert_weight(weight, carrier.ups_package_weight_unit)
|
||||
self.weight = carrier._ups_convert_weight(weight, carrier.ups_package_weight_unit)
|
||||
self.weight_unit = carrier.ups_package_weight_unit
|
||||
self.name = name
|
||||
self.dimension_unit = carrier.ups_package_dimension_unit
|
||||
if quant_pack:
|
||||
self.dimension = {'length': quant_pack.length, 'width': quant_pack.width, 'height': quant_pack.height}
|
||||
else:
|
||||
self.dimension = {'length': carrier.ups_default_packaging_id.length,
|
||||
'width': carrier.ups_default_packaging_id.width,
|
||||
'height': carrier.ups_default_packaging_id.height}
|
||||
self.dimension = {'length': carrier.ups_default_packaging_id.length, 'width': carrier.ups_default_packaging_id.width, 'height': carrier.ups_default_packaging_id.height}
|
||||
self.packaging_type = quant_pack and quant_pack.shipper_package_code or False
|
||||
self.insurance_value = insurance_value
|
||||
self.insurance_currency_code = insurance_currency_code
|
||||
|
||||
Reference in New Issue
Block a user