mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[FIX] delivery_fedex_hibou,delivery_hibou,delivery_ups_hibou,sale_planner: choose delivery packaging, warehouse specific fedex for 13
This commit is contained in:
@@ -38,6 +38,8 @@ class DeliveryFedex(models.Model):
|
||||
if not third_party_account.delivery_type == 'fedex':
|
||||
raise ValidationError('Non-FedEx Shipping Account indicated during FedEx shipment.')
|
||||
return third_party_account.name
|
||||
if picking and picking.picking_type_id.warehouse_id.fedex_account_number:
|
||||
return picking.picking_type_id.warehouse_id.fedex_account_number
|
||||
return self.fedex_account_number
|
||||
|
||||
def _get_fedex_account_number(self, order=None, picking=None):
|
||||
@@ -239,7 +241,7 @@ class DeliveryFedex(models.Model):
|
||||
recipient = superself.get_recipient(picking=picking)
|
||||
acc_number = superself._get_fedex_account_number(picking=picking)
|
||||
meter_number = superself._get_fedex_meter_number(picking=picking)
|
||||
payment_acc_number = superself._get_fedex_payment_account_number()
|
||||
payment_acc_number = superself._get_fedex_payment_account_number(picking=picking)
|
||||
order_name = superself.get_order_name(picking=picking)
|
||||
attn = superself.get_attn(picking=picking)
|
||||
residential = self._get_fedex_recipient_is_residential(recipient)
|
||||
@@ -711,3 +713,27 @@ class DeliveryFedex(models.Model):
|
||||
('fedex_service_type', '=', service_code)
|
||||
], limit=1)
|
||||
return carrier
|
||||
|
||||
def fedex_cancel_shipment(self, picking):
|
||||
request = FedexRequest(self.log_xml, request_type="shipping", prod_environment=self.prod_environment)
|
||||
superself = self.sudo()
|
||||
request.web_authentication_detail(superself.fedex_developer_key, superself.fedex_developer_password)
|
||||
acc_number = superself._get_fedex_account_number(picking=picking)
|
||||
meter_number = superself._get_fedex_meter_number(picking=picking)
|
||||
request.client_detail(acc_number, meter_number)
|
||||
request.transaction_detail(picking.id)
|
||||
|
||||
master_tracking_id = picking.carrier_tracking_ref.split(',')[0]
|
||||
request.set_deletion_details(master_tracking_id)
|
||||
result = request.delete_shipment()
|
||||
|
||||
warnings = result.get('warnings_message')
|
||||
if warnings:
|
||||
_logger.info(warnings)
|
||||
|
||||
if result.get('delete_success') and not result.get('errors_message'):
|
||||
picking.message_post(body=_(u'Shipment N° %s has been cancelled' % master_tracking_id))
|
||||
picking.write({'carrier_tracking_ref': '',
|
||||
'carrier_price': 0.0})
|
||||
else:
|
||||
raise UserError(result['errors_message'])
|
||||
|
||||
@@ -95,8 +95,8 @@ class FedexRequest(fedex_request.FedexRequest):
|
||||
insured.Currency = 'USD'
|
||||
package.InsuredValue = insured
|
||||
|
||||
special_service = self.client.factory.create("PackageSpecialServicesRequested")
|
||||
signature_detail = self.client.factory.create("SignatureOptionDetail")
|
||||
special_service = self.factory.PackageSpecialServicesRequested()
|
||||
signature_detail = self.factory.SignatureOptionDetail()
|
||||
signature_detail.OptionType = 'DIRECT' if signature_required else 'NO_SIGNATURE_REQUIRED'
|
||||
special_service.SignatureOptionDetail = signature_detail
|
||||
package.SpecialServicesRequested = special_service
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from odoo import api, fields, models
|
||||
from odoo.tools.float_utils import float_compare
|
||||
from odoo.addons.stock.models.stock_move import PROCUREMENT_PRIORITIES
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
@@ -23,7 +24,7 @@ class DeliveryCarrier(models.Model):
|
||||
value = 0.0
|
||||
if order:
|
||||
if order.order_line:
|
||||
value = sum(order.order_line.filtered(lambda l: l.type != 'service').mapped('price_subtotal'))
|
||||
value = sum(order.order_line.filtered(lambda l: l.product_id.type != 'service').mapped('price_subtotal'))
|
||||
else:
|
||||
return value
|
||||
if picking:
|
||||
@@ -272,27 +273,30 @@ class DeliveryCarrier(models.Model):
|
||||
class ChooseDeliveryPackage(models.TransientModel):
|
||||
_inherit = 'choose.delivery.package'
|
||||
|
||||
package_declared_value = fields.Float(string='Declared Value',
|
||||
default=lambda self: self._default_package_declared_value())
|
||||
package_declared_value = fields.Float(string='Declared Value')
|
||||
package_require_insurance = fields.Boolean(string='Require Insurance')
|
||||
package_require_signature = fields.Boolean(string='Require Signature')
|
||||
|
||||
def _default_package_declared_value(self):
|
||||
# guard for install
|
||||
if not self.env.context.get('active_id'):
|
||||
return 0.0
|
||||
if self.env.context.get('default_stock_quant_package_id'):
|
||||
stock_quant_package = self.env['stock.quant.package'].browse(self.env.context['default_stock_quant_package_id'])
|
||||
return stock_quant_package.package_declared_value
|
||||
else:
|
||||
picking_id = self.env['stock.picking'].browse(self.env.context['active_id'])
|
||||
move_line_ids = [po for po in picking_id.move_line_ids if po.qty_done > 0 and not po.result_package_id]
|
||||
total_value = sum([po.qty_done * po.product_id.standard_price for po in move_line_ids])
|
||||
return total_value
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
defaults = super().default_get(fields_list)
|
||||
if 'package_declared_value' in fields_list:
|
||||
picking_id = defaults.get('picking_id', self.env.context.get('default_picking_id'))
|
||||
picking = self.env['stock.picking'].browse(picking_id)
|
||||
move_line_ids = picking.move_line_ids.filtered(lambda m:
|
||||
float_compare(m.qty_done, 0.0, precision_rounding=m.product_uom_id.rounding) > 0
|
||||
and not m.result_package_id
|
||||
)
|
||||
total_value = 0.0
|
||||
for ml in move_line_ids:
|
||||
qty = ml.product_uom_id._compute_quantity(ml.qty_done, ml.product_id.uom_id)
|
||||
total_value += qty * ml.product_id.standard_price
|
||||
defaults['package_declared_value'] = total_value
|
||||
return defaults
|
||||
|
||||
@api.onchange('package_declared_value')
|
||||
def _onchange_package_declared_value(self):
|
||||
picking = self.env['stock.picking'].browse(self.env.context['active_id'])
|
||||
picking = self.picking_id
|
||||
value = self.package_declared_value
|
||||
if picking.require_insurance == 'auto':
|
||||
self.package_require_insurance = value and picking.carrier_id.automatic_insurance_value and value >= picking.carrier_id.automatic_insurance_value
|
||||
@@ -304,10 +308,29 @@ class ChooseDeliveryPackage(models.TransientModel):
|
||||
self.package_require_signature = picking.require_signature == 'yes'
|
||||
|
||||
def put_in_pack(self):
|
||||
super().put_in_pack()
|
||||
if self.stock_quant_package_id:
|
||||
self.stock_quant_package_id.write({
|
||||
'declared_value': self.package_declared_value,
|
||||
'require_insurance': self.package_require_insurance,
|
||||
'require_signature': self.package_require_signature,
|
||||
})
|
||||
# Copied because `delivery_package` is not retained by reference or returned...
|
||||
picking_move_lines = self.picking_id.move_line_ids
|
||||
if not self.picking_id.picking_type_id.show_reserved:
|
||||
picking_move_lines = self.picking_id.move_line_nosuggest_ids
|
||||
|
||||
move_line_ids = picking_move_lines.filtered(lambda ml:
|
||||
float_compare(ml.qty_done, 0.0, precision_rounding=ml.product_uom_id.rounding) > 0
|
||||
and not ml.result_package_id
|
||||
)
|
||||
if not move_line_ids:
|
||||
move_line_ids = picking_move_lines.filtered(lambda ml: float_compare(ml.product_uom_qty, 0.0,
|
||||
precision_rounding=ml.product_uom_id.rounding) > 0 and float_compare(ml.qty_done, 0.0,
|
||||
precision_rounding=ml.product_uom_id.rounding) == 0)
|
||||
|
||||
delivery_package = self.picking_id._put_in_pack(move_line_ids)
|
||||
# write shipping weight and product_packaging on 'stock_quant_package' if needed
|
||||
if self.delivery_packaging_id:
|
||||
delivery_package.packaging_id = self.delivery_packaging_id
|
||||
if self.shipping_weight:
|
||||
delivery_package.shipping_weight = self.shipping_weight
|
||||
# Hibou : Fill additional fields.
|
||||
delivery_package.write({
|
||||
'declared_value': self.package_declared_value,
|
||||
'require_insurance': self.package_require_insurance,
|
||||
'require_signature': self.package_require_signature,
|
||||
})
|
||||
|
||||
@@ -26,7 +26,7 @@ class ProviderUPS(models.Model):
|
||||
if not third_party_account.delivery_type == 'ups':
|
||||
raise ValidationError('Non-UPS Shipping Account indicated during UPS shipment.')
|
||||
return True
|
||||
if order and self.ups_bill_my_account and order.ups_carrier_account:
|
||||
if order and order.ups_bill_my_account and order.ups_carrier_account:
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -53,10 +53,10 @@ class ProviderUPS(models.Model):
|
||||
return third_party_account.name
|
||||
if order and order.ups_carrier_account:
|
||||
return order.ups_carrier_account
|
||||
if picking and picking.picking_type_id.warehouse_id.ups_shipper_number:
|
||||
return picking.picking_type_id.warehouse_id.ups_shipper_number
|
||||
if picking and picking.sale_id.ups_carrier_account:
|
||||
return picking.sale_id.ups_carrier_account
|
||||
if picking and picking.picking_type_id.warehouse_id.ups_shipper_number:
|
||||
return picking.picking_type_id.warehouse_id.ups_shipper_number
|
||||
return self.ups_shipper_number
|
||||
|
||||
def _get_ups_carrier_account(self, picking):
|
||||
|
||||
@@ -1,10 +1,48 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
import os
|
||||
from zeep import Client, Plugin
|
||||
from zeep.exceptions import Fault
|
||||
from odoo.addons.delivery_ups.models.ups_request import UPSRequest, Package
|
||||
from odoo.addons.delivery_ups.models.ups_request import UPSRequest, FixRequestNamespacePlug, LogPlugin, Package
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
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):
|
||||
# patch to add the relative url for tnt_wsdl
|
||||
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'
|
||||
self.tnt_wsdl = '../api/TNTWS.wsdl'
|
||||
self.ns = {'err': "http://www.ups.com/XMLSchema/XOLTWS/Error/v1.1"}
|
||||
|
||||
|
||||
def patched_set_client(self, wsdl, api, root):
|
||||
# because of WSDL relative path we must patch
|
||||
wsdl_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), wsdl)
|
||||
client = Client('file:///%s' % wsdl_path.lstrip('/'), plugins=[FixRequestNamespacePlug(root), LogPlugin(self.debug_logger)])
|
||||
self.factory_ns1 = client.type_factory('ns1')
|
||||
self.factory_ns2 = client.type_factory('ns2')
|
||||
self.factory_ns3 = client.type_factory('ns3')
|
||||
self._add_security_header(client, api)
|
||||
return client
|
||||
|
||||
|
||||
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):
|
||||
@@ -98,43 +136,92 @@ def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from
|
||||
return [error_message]
|
||||
return error_message
|
||||
|
||||
if not multi:
|
||||
rate = response.RatedShipment[0]
|
||||
charge = rate.TotalCharges
|
||||
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_service = self._set_service(tnt_client, 'TimeInTransit')
|
||||
tnt_request = self.factory_ns3.RequestType()
|
||||
tnt_request.RequestOption = 'TNT'
|
||||
|
||||
tnt_ship_from = self.factory_ns2.RequestShipFromType()
|
||||
tnt_ship_from.Address = self.factory_ns2.RequestShipFromAddressType()
|
||||
tnt_ship_from.AttentionName = (ship_from.name or '')[:35]
|
||||
tnt_ship_from.Name = (ship_from.parent_id.name or ship_from.name or '')[:35]
|
||||
tnt_ship_from.Address.AddressLine = [l for l in [ship_from.street or '', ship_from.street2 or ''] if l]
|
||||
tnt_ship_from.Address.City = ship_from.city or ''
|
||||
tnt_ship_from.Address.PostalCode = ship_from.zip or ''
|
||||
tnt_ship_from.Address.CountryCode = ship_from.country_id.code or ''
|
||||
if ship_from.country_id.code in ('US', 'CA', 'IE'):
|
||||
tnt_ship_from.Address.StateProvinceCode = ship_from.state_id.code or ''
|
||||
|
||||
tnt_ship_to = self.factory_ns2.RequestShipToType()
|
||||
tnt_ship_to.Address = self.factory_ns2.RequestShipToAddressType()
|
||||
tnt_ship_to.AttentionName = (ship_to.name or '')[:35]
|
||||
tnt_ship_to.Name = (ship_to.parent_id.name or ship_to.name or '')[:35]
|
||||
tnt_ship_to.Address.AddressLine = [l for l in [ship_to.street or '', ship_to.street2 or ''] if l]
|
||||
tnt_ship_to.Address.City = ship_to.city or ''
|
||||
tnt_ship_to.Address.PostalCode = ship_to.zip or ''
|
||||
tnt_ship_to.Address.CountryCode = ship_to.country_id.code or ''
|
||||
if ship_to.country_id.code in ('US', 'CA', 'IE'):
|
||||
tnt_ship_to.Address.StateProvinceCode = ship_to.state_id.code or ''
|
||||
if not ship_to.commercial_partner_id.is_company:
|
||||
tnt_ship_to.Address.ResidentialAddressIndicator = None
|
||||
|
||||
tnt_pickup = self.factory_ns2.PickupType()
|
||||
tnt_pickup.Date = date_planned.split(' ')[0].replace('-', '')
|
||||
tnt_pickup.Time = date_planned.split(' ')[1].replace(':', '')
|
||||
|
||||
tnt_response = tnt_service.ProcessTimeInTransit(Request=tnt_request,
|
||||
ShipFrom=tnt_ship_from,
|
||||
ShipTo=tnt_ship_to,
|
||||
Pickup=tnt_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))
|
||||
_logger.exception(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
|
||||
|
||||
# Some users are qualified to receive negotiated rates
|
||||
if 'NegotiatedRateCharges' in rate and rate.NegotiatedRateCharges and rate.NegotiatedRateCharges.TotalCharge.MonetaryValue:
|
||||
charge = rate.NegotiatedRateCharges.TotalCharge
|
||||
|
||||
result = {
|
||||
'currency_code': charge.CurrencyCode,
|
||||
'price': charge.MonetaryValue,
|
||||
}
|
||||
negotiated_rate = 'NegotiatedRateCharges' in response.RatedShipment[0] and response.RatedShipment[
|
||||
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 rate in response.RatedShipment:
|
||||
charge = rate.TotalCharges
|
||||
|
||||
# Some users are qualified to receive negotiated rates
|
||||
if 'NegotiatedRateCharges' in rate and rate.NegotiatedRateCharges and rate.NegotiatedRateCharges.TotalCharge.MonetaryValue:
|
||||
charge = rate.NegotiatedRateCharges.TotalCharge
|
||||
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')
|
||||
|
||||
rated_shipment = {
|
||||
'currency_code': charge.CurrencyCode,
|
||||
'price': charge.MonetaryValue,
|
||||
}
|
||||
|
||||
# Hibou Delivery
|
||||
if hasattr(rate, 'GuaranteedDelivery') and hasattr(rate.GuaranteedDelivery, 'BusinessDaysInTransit'):
|
||||
rated_shipment['transit_days'] = int(rate.GuaranteedDelivery.BusinessDaysInTransit)
|
||||
# End
|
||||
rated_shipment['service_code'] = rate.Service.Code
|
||||
result.append(rated_shipment)
|
||||
return result
|
||||
|
||||
except Fault as e:
|
||||
@@ -151,29 +238,31 @@ def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from
|
||||
return error_message
|
||||
|
||||
|
||||
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):
|
||||
def patched_send_shipping(self, shipment_info, packages, shipper, ship_from, ship_to, packaging_type, service_type, saturday_delivery, duty_payment, cod_info=None, label_file_type='GIF', ups_carrier_account=False):
|
||||
client = self._set_client(self.ship_wsdl, 'Ship', 'ShipmentRequest')
|
||||
|
||||
request = client.factory.create('ns0:RequestType')
|
||||
request = self.factory_ns3.RequestType()
|
||||
request.RequestOption = 'nonvalidate'
|
||||
|
||||
namespace = 'ns3'
|
||||
label = client.factory.create('{}:LabelSpecificationType'.format(namespace))
|
||||
|
||||
request_type = "shipping"
|
||||
label = self.factory_ns2.LabelSpecificationType()
|
||||
label.LabelImageFormat = self.factory_ns2.LabelImageFormatType()
|
||||
label.LabelImageFormat.Code = label_file_type
|
||||
label.LabelImageFormat.Description = label_file_type
|
||||
if label_file_type != 'GIF':
|
||||
label.LabelStockSize = self.factory_ns2.LabelStockSizeType()
|
||||
label.LabelStockSize.Height = '6'
|
||||
label.LabelStockSize.Width = '4'
|
||||
|
||||
shipment = client.factory.create('{}:ShipmentType'.format(namespace))
|
||||
shipment = self.factory_ns2.ShipmentType()
|
||||
shipment.Description = shipment_info.get('description')
|
||||
|
||||
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.Shipper.AttentionName = shipper.name or ''
|
||||
shipment.Shipper.Name = shipper.parent_id.name or shipper.name or ''
|
||||
shipment.Shipper = self.factory_ns2.ShipperType()
|
||||
shipment.Shipper.Address = self.factory_ns2.ShipAddressType()
|
||||
shipment.Shipper.AttentionName = (shipper.name or '')[:35]
|
||||
shipment.Shipper.Name = (shipper.parent_id.name or shipper.name or '')[:35]
|
||||
shipment.Shipper.Address.AddressLine = [l for l in [shipper.street or '', shipper.street2 or ''] if l]
|
||||
shipment.Shipper.Address.City = shipper.city or ''
|
||||
shipment.Shipper.Address.PostalCode = shipper.zip or ''
|
||||
@@ -181,128 +270,146 @@ def patched_send_shipping(self, shipment_info, packages, shipper, ship_from, shi
|
||||
if shipper.country_id.code in ('US', 'CA', 'IE'):
|
||||
shipment.Shipper.Address.StateProvinceCode = shipper.state_id.code or ''
|
||||
shipment.Shipper.ShipperNumber = self.shipper_number or ''
|
||||
shipment.Shipper.Phone = self.factory_ns2.ShipPhoneType()
|
||||
shipment.Shipper.Phone.Number = self._clean_phone_number(shipper.phone)
|
||||
|
||||
shipment.ShipFrom.AttentionName = ship_from.name or ''
|
||||
shipment.ShipFrom.Name = ship_from.parent_id.name or ship_from.name or ''
|
||||
shipment.ShipFrom = self.factory_ns2.ShipFromType()
|
||||
shipment.ShipFrom.Address = self.factory_ns2.ShipAddressType()
|
||||
shipment.ShipFrom.AttentionName = (ship_from.name or '')[:35]
|
||||
shipment.ShipFrom.Name = (ship_from.parent_id.name or ship_from.name or '')[:35]
|
||||
shipment.ShipFrom.Address.AddressLine = [l for l in [ship_from.street or '', ship_from.street2 or ''] if l]
|
||||
shipment.ShipFrom.Address.City = ship_from.city or ''
|
||||
shipment.ShipFrom.Address.PostalCode = ship_from.zip or ''
|
||||
shipment.ShipFrom.Address.CountryCode = ship_from.country_id.code or ''
|
||||
if ship_from.country_id.code in ('US', 'CA', 'IE'):
|
||||
shipment.ShipFrom.Address.StateProvinceCode = ship_from.state_id.code or ''
|
||||
shipment.ShipFrom.Phone = self.factory_ns2.ShipPhoneType()
|
||||
shipment.ShipFrom.Phone.Number = self._clean_phone_number(ship_from.phone)
|
||||
|
||||
shipment.ShipTo.AttentionName = ship_to.name or ''
|
||||
shipment.ShipTo.Name = ship_to.parent_id.name or ship_to.name or ''
|
||||
shipment.ShipTo = self.factory_ns2.ShipToType()
|
||||
shipment.ShipTo.Address = self.factory_ns2.ShipToAddressType()
|
||||
shipment.ShipTo.AttentionName = (ship_to.name or '')[:35]
|
||||
shipment.ShipTo.Name = (ship_to.parent_id.name or ship_to.name or '')[:35]
|
||||
shipment.ShipTo.Address.AddressLine = [l for l in [ship_to.street or '', ship_to.street2 or ''] if l]
|
||||
shipment.ShipTo.Address.City = ship_to.city or ''
|
||||
shipment.ShipTo.Address.PostalCode = ship_to.zip or ''
|
||||
shipment.ShipTo.Address.CountryCode = ship_to.country_id.code or ''
|
||||
if ship_to.country_id.code in ('US', 'CA', 'IE'):
|
||||
shipment.ShipTo.Address.StateProvinceCode = ship_to.state_id.code or ''
|
||||
shipment.ShipTo.Phone = self.factory_ns2.ShipPhoneType()
|
||||
shipment.ShipTo.Phone.Number = self._clean_phone_number(shipment_info['phone'])
|
||||
if not ship_to.commercial_partner_id.is_company:
|
||||
shipment.ShipTo.Address.ResidentialAddressIndicator = suds.null()
|
||||
shipment.ShipTo.Address.ResidentialAddressIndicator = None
|
||||
|
||||
shipment.Service = self.factory_ns2.ServiceType()
|
||||
shipment.Service.Code = service_type or ''
|
||||
shipment.Service.Description = 'Service Code'
|
||||
if service_type == "96":
|
||||
shipment.NumOfPiecesInShipment = int(shipment_info.get('total_qty'))
|
||||
shipment.ShipmentRatingOptions.NegotiatedRatesIndicator = '1'
|
||||
shipment.ShipmentRatingOptions = self.factory_ns2.RateInfoType()
|
||||
shipment.ShipmentRatingOptions.NegotiatedRatesIndicator = 1
|
||||
|
||||
# Shipments from US to CA or PR require extra info
|
||||
if ship_from.country_id.code == 'US' and ship_to.country_id.code in ['CA', 'PR']:
|
||||
shipment.InvoiceLineTotal = self.factory_ns2.CurrencyMonetaryType()
|
||||
shipment.InvoiceLineTotal.CurrencyCode = shipment_info.get('itl_currency_code')
|
||||
shipment.InvoiceLineTotal.MonetaryValue = shipment_info.get('ilt_monetary_value')
|
||||
|
||||
# set the default method for payment using shipper account
|
||||
payment_info = client.factory.create('ns3:PaymentInformation')
|
||||
shipcharge = client.factory.create('ns3:ShipmentCharge')
|
||||
payment_info = self.factory_ns2.PaymentInfoType()
|
||||
shipcharge = self.factory_ns2.ShipmentChargeType()
|
||||
shipcharge.Type = '01'
|
||||
|
||||
# Bill Recevier 'Bill My Account'
|
||||
if ups_carrier_account:
|
||||
shipcharge.BillReceiver = self.factory_ns2.BillReceiverType()
|
||||
shipcharge.BillReceiver.Address = self.factory_ns2.BillReceiverAddressType()
|
||||
shipcharge.BillReceiver.AccountNumber = ups_carrier_account
|
||||
shipcharge.BillReceiver.Address.PostalCode = ship_to.zip
|
||||
else:
|
||||
shipcharge.BillShipper = self.factory_ns2.BillShipperType()
|
||||
shipcharge.BillShipper.AccountNumber = self.shipper_number or ''
|
||||
|
||||
payment_info.ShipmentCharge = shipcharge
|
||||
payment_info.ShipmentCharge = [shipcharge]
|
||||
|
||||
if duty_payment == 'SENDER':
|
||||
duty_charge = self.factory_ns2.ShipmentChargeType()
|
||||
duty_charge.Type = '02'
|
||||
duty_charge.BillShipper = self.factory_ns2.BillShipperType()
|
||||
duty_charge.BillShipper.AccountNumber = self.shipper_number or ''
|
||||
payment_info.ShipmentCharge.append(duty_charge)
|
||||
|
||||
shipment.PaymentInformation = payment_info
|
||||
|
||||
if saturday_delivery:
|
||||
shipment.ShipmentServiceOptions = self.factory_ns2.ShipmentServiceOptionsType()
|
||||
shipment.ShipmentServiceOptions.SaturdayDeliveryIndicator = saturday_delivery
|
||||
else:
|
||||
shipment.ShipmentServiceOptions = ''
|
||||
|
||||
try:
|
||||
response = client.service.ProcessShipment(
|
||||
Request=request, Shipment=shipment,
|
||||
LabelSpecification=label)
|
||||
|
||||
# Check if shipment is not success then return reason for that
|
||||
if response.Response.ResponseStatus.Code != "1":
|
||||
return self.get_error_message(response.Response.ResponseStatus.Code, response.Response.ResponseStatus.Description)
|
||||
|
||||
result = {}
|
||||
result['label_binary_data'] = {}
|
||||
for package in response.ShipmentResults.PackageResults:
|
||||
result['label_binary_data'][package.TrackingNumber] = self.save_label(package.ShippingLabel.GraphicImage, label_file_type=label_file_type)
|
||||
result['tracking_ref'] = response.ShipmentResults.ShipmentIdentificationNumber
|
||||
result['currency_code'] = response.ShipmentResults.ShipmentCharges.TotalCharges.CurrencyCode
|
||||
|
||||
# Some users are qualified to receive negotiated rates
|
||||
negotiated_rate = 'NegotiatedRateCharges' in response.ShipmentResults and response.ShipmentResults.NegotiatedRateCharges.TotalCharge.MonetaryValue or None
|
||||
|
||||
result['price'] = negotiated_rate or response.ShipmentResults.ShipmentCharges.TotalCharges.MonetaryValue
|
||||
return result
|
||||
|
||||
except suds.WebFault as e:
|
||||
# childAtPath behaviour is changing at version 0.6
|
||||
prefix = ''
|
||||
if SUDS_VERSION >= "0.6":
|
||||
prefix = '/Envelope/Body/Fault'
|
||||
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())
|
||||
except IOError as e:
|
||||
return self.get_error_message('0', 'UPS Server Not Found:\n%s' % e)
|
||||
self.shipment = shipment
|
||||
self.label = label
|
||||
self.request = request
|
||||
self.label_file_type = label_file_type
|
||||
|
||||
|
||||
def patched_set_package_detail(self, client, packages, packaging_type, namespace, ship_from, ship_to, cod_info):
|
||||
def patched_set_package_detail(self, client, packages, packaging_type, ship_from, ship_to, cod_info, request_type):
|
||||
Packages = []
|
||||
if request_type == "rating":
|
||||
MeasurementType = self.factory_ns2.CodeDescriptionType
|
||||
elif request_type == "shipping":
|
||||
MeasurementType = self.factory_ns2.ShipUnitOfMeasurementType
|
||||
for i, p in enumerate(packages):
|
||||
package = client.factory.create('{}:PackageType'.format(namespace))
|
||||
package = self.factory_ns2.PackageType()
|
||||
if hasattr(package, 'Packaging'):
|
||||
package.Packaging = self.factory_ns2.PackagingType()
|
||||
package.Packaging.Code = p.packaging_type or packaging_type or ''
|
||||
elif hasattr(package, 'PackagingType'):
|
||||
package.PackagingType = self.factory_ns2.CodeDescriptionType()
|
||||
package.PackagingType.Code = p.packaging_type or packaging_type or ''
|
||||
|
||||
# Hibou Insurance & Signature Requirement
|
||||
if p.insurance_value:
|
||||
package.PackageServiceOptions.DeclaredValue.MonetaryValue = p.insurance_value
|
||||
package.PackageServiceOptions.DeclaredValue.CurrencyCode = p.insurance_currency_code
|
||||
if p.signature_required:
|
||||
package.PackageServiceOptions.DeliveryConfirmation.DCISType = p.signature_required
|
||||
|
||||
if p.dimension_unit and any(p.dimension.values()):
|
||||
package.Dimensions = self.factory_ns2.DimensionsType()
|
||||
package.Dimensions.UnitOfMeasurement = MeasurementType()
|
||||
package.Dimensions.UnitOfMeasurement.Code = p.dimension_unit or ''
|
||||
package.Dimensions.Length = p.dimension['length'] or ''
|
||||
package.Dimensions.Width = p.dimension['width'] or ''
|
||||
package.Dimensions.Height = p.dimension['height'] or ''
|
||||
|
||||
if cod_info:
|
||||
package.PackageServiceOptions = self.factory_ns2.PackageServiceOptionsType()
|
||||
package.PackageServiceOptions.COD = self.factory_ns2.CODType()
|
||||
package.PackageServiceOptions.COD.CODFundsCode = str(cod_info['funds_code'])
|
||||
package.PackageServiceOptions.COD.CODAmount = self.factory_ns2.CODAmountType() if request_type == 'rating' else self.factory_ns2.CurrencyMonetaryType()
|
||||
package.PackageServiceOptions.COD.CODAmount.MonetaryValue = cod_info['monetary_value']
|
||||
package.PackageServiceOptions.COD.CODAmount.CurrencyCode = cod_info['currency']
|
||||
|
||||
# Hibou Insurance & Signature Requirement
|
||||
if p.insurance_value:
|
||||
if not package.PackageServiceOptions:
|
||||
package.PackageServiceOptions = self.factory_ns2.PackageServiceOptionsType()
|
||||
if not package.PackageServiceOptions.DeclaredValue:
|
||||
if request_type == 'shipping':
|
||||
package.PackageServiceOptions.DeclaredValue = self.factory_ns2.PackageDeclaredValueType()
|
||||
else:
|
||||
package.PackageServiceOptions.DeclaredValue = self.factory_ns2.ShipperDeclaredValueType()
|
||||
package.PackageServiceOptions.DeclaredValue.MonetaryValue = p.insurance_value
|
||||
package.PackageServiceOptions.DeclaredValue.CurrencyCode = p.insurance_currency_code
|
||||
if p.signature_required:
|
||||
if not package.PackageServiceOptions:
|
||||
package.PackageServiceOptions = self.factory_ns2.PackageServiceOptionsType()
|
||||
if not package.PackageServiceOptions.DeliveryConfirmation:
|
||||
package.PackageServiceOptions.DeliveryConfirmation = self.factory_ns2.DeliveryConfirmationType()
|
||||
package.PackageServiceOptions.DeliveryConfirmation.DCISType = p.signature_required
|
||||
|
||||
package.PackageWeight = self.factory_ns2.PackageWeightType()
|
||||
package.PackageWeight.UnitOfMeasurement = MeasurementType()
|
||||
package.PackageWeight.UnitOfMeasurement.Code = p.weight_unit or ''
|
||||
package.PackageWeight.Weight = p.weight or ''
|
||||
|
||||
# Package and shipment reference text is only allowed for shipments within
|
||||
# the USA and within Puerto Rico. This is a UPS limitation.
|
||||
if (p.name and ship_from.country_id.code in ('US') and ship_to.country_id.code in ('US')):
|
||||
reference_number = client.factory.create('ns3:ReferenceNumberType')
|
||||
reference_number = self.factory_ns2.ReferenceNumberType()
|
||||
reference_number.Code = 'PM'
|
||||
reference_number.Value = p.name
|
||||
reference_number.BarCodeIndicator = p.name
|
||||
@@ -312,6 +419,8 @@ def patched_set_package_detail(self, client, packages, packaging_type, namespace
|
||||
return Packages
|
||||
|
||||
|
||||
UPSRequest.__init__ = patched__init__
|
||||
UPSRequest._set_client = patched_set_client
|
||||
UPSRequest.get_shipping_price = patched_get_shipping_price
|
||||
UPSRequest.send_shipping = patched_send_shipping
|
||||
UPSRequest.set_package_detail = patched_set_package_detail
|
||||
@@ -319,16 +428,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
|
||||
|
||||
@@ -28,7 +28,11 @@ class FakeCollection():
|
||||
yield v
|
||||
|
||||
def filtered(self, f):
|
||||
return filter(f, self.vals)
|
||||
return self.__class__([v for v in self.vals if f(v)])
|
||||
|
||||
def mapped(self, s):
|
||||
# note this only maps to one level and doesn't really support recordset
|
||||
return [v[s] for v in self.vals]
|
||||
|
||||
def sudo(self, *args, **kwargs):
|
||||
return self
|
||||
@@ -699,7 +703,7 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
if has_error:
|
||||
continue
|
||||
order_fake.warehouse_id = warehouses.filtered(lambda wh: wh.id == wh_id)
|
||||
order_fake.order_line = FakeCollection(filter(lambda line: line.product_id.id in wh_vals['product_ids'], original_order_fake_order_line))
|
||||
order_fake.order_line = FakeCollection(list(filter(lambda line: line.product_id.id in wh_vals['product_ids'], original_order_fake_order_line)))
|
||||
wh_carrier_options = self._generate_shipping_carrier_option(wh_vals, order_fake, carrier)
|
||||
if not wh_carrier_options:
|
||||
has_error = True
|
||||
|
||||
Reference in New Issue
Block a user