diff --git a/delivery_fedex_hibou/models/delivery_fedex.py b/delivery_fedex_hibou/models/delivery_fedex.py
index 45103795..521bea81 100644
--- a/delivery_fedex_hibou/models/delivery_fedex.py
+++ b/delivery_fedex_hibou/models/delivery_fedex.py
@@ -245,7 +245,6 @@ class DeliveryFedex(models.Model):
payment_acc_number = superself._get_fedex_payment_account_number()
order_name = superself.get_order_name(picking=picking)
attn = superself.get_attn(picking=picking)
- insurance_value = superself.get_insurance_value(picking=picking)
residential = self._get_fedex_recipient_is_residential(recipient)
srm.web_authentication_detail(superself.fedex_developer_key, superself.fedex_developer_password)
@@ -341,7 +340,8 @@ class DeliveryFedex(models.Model):
po_number=po_number,
dept_number=dept_number,
ref=('%s-%d' % (order_name, sequence)),
- insurance=insurance_value
+ insurance=superself.get_insurance_value(picking=picking, package=package),
+ signature_required=superself.get_signature_required(picking=picking, package=package)
)
srm.set_master_package(net_weight, package_count, master_tracking_id=master_tracking_id)
request = srm.process_shipment()
@@ -421,7 +421,8 @@ class DeliveryFedex(models.Model):
po_number=po_number,
dept_number=dept_number,
ref=order_name,
- insurance=insurance_value
+ insurance=superself.get_insurance_value(picking=picking, package=picking_packages[:1]),
+ signature_required=superself.get_signature_required(picking=picking, package=picking_packages[:1])
)
srm.set_master_package(net_weight, 1)
@@ -516,7 +517,8 @@ class DeliveryFedex(models.Model):
acc_number = superself._get_fedex_account_number(order=order, picking=picking)
meter_number = superself._get_fedex_meter_number(order=order, picking=picking)
order_name = superself.get_order_name(order=order, picking=picking)
- insurance_value = superself.get_insurance_value(order=order, picking=picking)
+ insurance_value = superself.get_insurance_value(order=order, picking=picking, package=package)
+ signature_required = superself.get_signature_required(order=order, picking=picking, package=package)
residential = self._get_fedex_recipient_is_residential(recipient)
date_planned = fields.Datetime.now()
if self.env.context.get('date_planned'):
@@ -600,7 +602,8 @@ class DeliveryFedex(models.Model):
# po_number=po_number,
# dept_number=dept_number,
ref=('%s-%d' % (order_name, 1)),
- insurance=insurance_value
+ insurance=insurance_value,
+ signature_required=signature_required
)
else:
# deliver all together...
@@ -618,7 +621,8 @@ class DeliveryFedex(models.Model):
# po_number=po_number,
# dept_number=dept_number,
ref=('%s-%d' % (order_name, 1)),
- insurance=insurance_value
+ insurance=insurance_value,
+ signature_required=signature_required
)
diff --git a/delivery_fedex_hibou/models/fedex_request.py b/delivery_fedex_hibou/models/fedex_request.py
index ca8c230c..df32800d 100644
--- a/delivery_fedex_hibou/models/fedex_request.py
+++ b/delivery_fedex_hibou/models/fedex_request.py
@@ -32,6 +32,7 @@ class FedexRequest(fedex_request.FedexRequest):
_service_transit_days = {
'FEDEX_2_DAY': 2,
'FEDEX_2_DAY_AM': 2,
+ 'FEDEX_3_DAY_FREIGHT': 3,
'FIRST_OVERNIGHT': 1,
'PRIORITY_OVERNIGHT': 1,
'STANDARD_OVERNIGHT': 1,
@@ -74,12 +75,12 @@ class FedexRequest(fedex_request.FedexRequest):
self.RequestedShipment.Recipient.Contact = Contact
self.RequestedShipment.Recipient.Address = Address
- def add_package(self, weight_value, package_code=False, package_height=0, package_width=0, package_length=0, sequence_number=False, mode='shipping', ref=False, insurance=False):
+ def add_package(self, weight_value, package_code=False, package_height=0, package_width=0, package_length=0, sequence_number=False, mode='shipping', ref=False, insurance=False, signature_required=False):
# TODO remove in master and change the signature of a public method
return self._add_package(weight_value=weight_value, package_code=package_code, package_height=package_height, package_width=package_width,
- package_length=package_length, sequence_number=sequence_number, mode=mode, po_number=False, dept_number=False, ref=ref, insurance=insurance)
+ package_length=package_length, sequence_number=sequence_number, mode=mode, po_number=False, dept_number=False, ref=ref, insurance=insurance, signature_required=signature_required)
- def _add_package(self, weight_value, package_code=False, package_height=0, package_width=0, package_length=0, sequence_number=False, mode='shipping', po_number=False, dept_number=False, ref=False, insurance=False):
+ def _add_package(self, weight_value, package_code=False, package_height=0, package_width=0, package_length=0, sequence_number=False, mode='shipping', po_number=False, dept_number=False, ref=False, insurance=False, signature_required=False):
package = self.client.factory.create('RequestedPackageLineItem')
package_weight = self.client.factory.create('Weight')
package_weight.Value = weight_value
@@ -98,6 +99,12 @@ 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")
+ signature_detail.OptionType = 'DIRECT' if signature_required else 'NO_SIGNATURE_REQUIRED'
+ special_service.SignatureOptionDetail = signature_detail
+ package.SpecialServicesRequested = special_service
+
package.PhysicalPackaging = 'BOX'
if package_code == 'YOUR_PACKAGING':
package.Dimensions.Height = package_height
@@ -202,6 +209,10 @@ class FedexRequest(fedex_request.FedexRequest):
# Hibou Delivery Planning
if hasattr(self.response.RateReplyDetails[0], 'DeliveryTimestamp') and self.response.RateReplyDetails[0].DeliveryTimestamp:
formatted_response['date_delivered'] = self.response.RateReplyDetails[0].DeliveryTimestamp
+ if hasattr(self.response.RateReplyDetails[0].CommitDetails[0], 'TransitTime'):
+ transit_days = self.response.RateReplyDetails[0].CommitDetails[0].TransitTime
+ transit_days = self._transit_days.get(transit_days, 0)
+ formatted_response['transit_days'] = transit_days
elif hasattr(self.response.RateReplyDetails[0], 'CommitDetails') and hasattr(self.response.RateReplyDetails[0].CommitDetails[0], 'CommitTimestamp'):
formatted_response['date_delivered'] = self.response.RateReplyDetails[0].CommitDetails[0].CommitTimestamp
formatted_response['transit_days'] = self._service_transit_days.get(self.response.RateReplyDetails[0].CommitDetails[0].ServiceType, 0)
@@ -221,9 +232,14 @@ class FedexRequest(fedex_request.FedexRequest):
# Hibou Delivery Planning
if hasattr(rate_reply_detail, 'DeliveryTimestamp') and rate_reply_detail.DeliveryTimestamp:
res['date_delivered'] = rate_reply_detail.DeliveryTimestamp
+ res['transit_days'] = self._service_transit_days.get(rate_reply_detail.ServiceType, 0)
+ if not res['transit_days'] and hasattr(rate_reply_detail.CommitDetails[0], 'TransitTime'):
+ transit_days = rate_reply_detail.CommitDetails[0].TransitTime
+ transit_days = self._transit_days.get(transit_days, 0)
+ res['transit_days'] = transit_days
elif hasattr(rate_reply_detail, 'CommitDetails') and hasattr(rate_reply_detail.CommitDetails[0], 'CommitTimestamp'):
res['date_delivered'] = rate_reply_detail.CommitDetails[0].CommitTimestamp
- res['transit_days'] = self._service_transit_days.get(rate_reply_detail.CommitDetails[0].ServiceType, 0)
+ res['transit_days'] = self._service_transit_days.get(rate_reply_detail.ServiceType, 0)
elif hasattr(rate_reply_detail, 'CommitDetails') and hasattr(rate_reply_detail.CommitDetails[0], 'TransitTime'):
transit_days = rate_reply_detail.CommitDetails[0].TransitTime
transit_days = self._transit_days.get(transit_days, 0)
diff --git a/delivery_gso/models/delivery_gso.py b/delivery_gso/models/delivery_gso.py
index 4c7f7864..be06ace0 100644
--- a/delivery_gso/models/delivery_gso.py
+++ b/delivery_gso/models/delivery_gso.py
@@ -187,14 +187,6 @@ class ProviderGSO(models.Model):
request_body['Shipment'].update(self._gso_make_shipper_address(from_, company))
request_body['Shipment'].update(self._gso_make_ship_address(to))
- # Automatic insurance at $100.0
- insurance_value = sudoself.get_insurance_value(picking=picking)
- if insurance_value:
- request_body['Shipment']['SignatureCode'] = 'SIG_REQD'
- if insurance_value > 100.0:
- # Documentation says to set DeclaredValue ONLY if over $100.00
- request_body['Shipment']['DeclaredValue'] = insurance_value
-
cost = 0.0
labels = {
'thermal': [],
@@ -209,6 +201,20 @@ class ProviderGSO(models.Model):
if picking_packages:
# Every package will be a transaction
for package in picking_packages:
+ # Use Sale Order Number or fall back to Picking
+ shipment_ref = (picking.sale_id.name if picking.sale_id else picking.name) + '-' + package.name
+ insurance_value = sudoself.get_insurance_value(picking=picking, package=package)
+ if insurance_value > 100.0:
+ # Documentation says to set DeclaredValue ONLY if over $100.00
+ request_body['Shipment']['DeclaredValue'] = insurance_value
+ elif 'DeclaredValue' in request_body['Shipment']:
+ del request_body['Shipment']['DeclaredValue']
+
+ if sudoself.get_signature_required(picking=picking, package=package):
+ request_body['Shipment']['SignatureCode'] = 'SIG_REQD'
+ else:
+ request_body['Shipment']['SignatureCode'] = 'SIG_NOT_REQD'
+
request_body['Shipment']['Weight'] = self._gso_convert_weight(package.shipping_weight)
request_body['Shipment'].update(self._gso_get_package_dimensions(package))
request_body['Shipment']['ShipmentReference'] = package.name
@@ -227,9 +233,10 @@ class ProviderGSO(models.Model):
raise ValidationError(e)
elif not package_carriers:
# ship the whole picking
+ shipment_ref = picking.sale_id.name if picking.sale_id else picking.name
request_body['Shipment']['Weight'] = self._gso_convert_weight(picking.shipping_weight)
request_body['Shipment'].update(self._gso_get_package_dimensions())
- request_body['Shipment']['ShipmentReference'] = picking.name
+ request_body['Shipment']['ShipmentReference'] = shipment_ref
request_body['Shipment']['TrackingNumber'] = self._gso_create_tracking_number(picking.name)
try:
response = service.post_shipment(request_body)
@@ -356,7 +363,7 @@ class ProviderGSO(models.Model):
try:
service = sudoself._get_gso_service()
except HTTPError as e:
- _logger.error(e)
+ # _logger.error(e)
return [{
'success': False,
'price': 0.0,
@@ -400,7 +407,7 @@ class ProviderGSO(models.Model):
result = service.get_rates_and_transit_time(request_body)
# _logger.warn('GSO result:\n%s' % result)
except HTTPError as e:
- _logger.error(e)
+ # _logger.error(e)
return [{
'success': False,
'price': 0.0,
diff --git a/delivery_hibou/__manifest__.py b/delivery_hibou/__manifest__.py
index 72f0f3bb..95ffb712 100644
--- a/delivery_hibou/__manifest__.py
+++ b/delivery_hibou/__manifest__.py
@@ -1,7 +1,7 @@
{
'name': 'Delivery Hibou',
'summary': 'Adds underlying pinnings for things like "RMA Return Labels"',
- 'version': '12.0.1.1.0',
+ 'version': '12.0.1.2.0',
'author': "Hibou Corp.",
'category': 'Stock',
'license': 'AGPL-3',
diff --git a/delivery_hibou/models/delivery.py b/delivery_hibou/models/delivery.py
index 8eefb7e9..dcfb90df 100644
--- a/delivery_hibou/models/delivery.py
+++ b/delivery_hibou/models/delivery.py
@@ -9,6 +9,9 @@ class DeliveryCarrier(models.Model):
automatic_insurance_value = fields.Float(string='Automatic Insurance Value',
help='Will be used during shipping to determine if the '
'picking\'s value warrants insurance being added.')
+ automatic_sig_req_value = fields.Float(string='Automatic Signature Required Value',
+ help='Will be used during shipping to determine if the '
+ 'picking\'s value warrants signature required being added.')
procurement_priority = fields.Selection(PROCUREMENT_PRIORITIES,
string='Procurement Priority',
help='Priority for this carrier. Will affect pickings '
@@ -16,7 +19,7 @@ class DeliveryCarrier(models.Model):
# Utility
- def get_insurance_value(self, order=None, picking=None):
+ def get_insurance_value(self, order=None, picking=None, package=None):
value = 0.0
if order:
if order.order_line:
@@ -24,13 +27,34 @@ class DeliveryCarrier(models.Model):
else:
return value
if picking:
- value = picking.declared_value()
- if picking.require_insurance == 'no':
- value = 0.0
- elif picking.require_insurance == 'auto' and self.automatic_insurance_value and self.automatic_insurance_value > value:
+ value = picking.declared_value(package=package)
+ if package and not package.require_insurance:
value = 0.0
+ else:
+ if picking.require_insurance == 'no':
+ value = 0.0
+ elif picking.require_insurance == 'auto' and self.automatic_insurance_value and self.automatic_insurance_value > value:
+ value = 0.0
return value
+ def get_signature_required(self, order=None, picking=None, package=None):
+ value = 0.0
+ if order:
+ if order.order_line:
+ value = sum(order.order_line.filtered(lambda l: l.product_id.type != 'service').mapped('price_subtotal'))
+ else:
+ return False
+ if picking:
+ value = picking.declared_value(package=package)
+ if package:
+ return package.require_signature
+ else:
+ if picking.require_signature == 'no':
+ return False
+ elif picking.require_signature == 'yes':
+ return True
+ return self.automatic_sig_req_value and value >= self.automatic_sig_req_value
+
def get_third_party_account(self, order=None, picking=None):
if order and order.shipping_account_id:
return order.shipping_account_id
@@ -203,9 +227,9 @@ class DeliveryCarrier(models.Model):
res = []
for carrier in self:
- carrier_packages = packages.filtered(lambda p: not p.carrier_tracking_ref and
- (not p.carrier_id or p.carrier_id == carrier) and
- p.packaging_id.package_carrier_type in (False, '', 'none', carrier.delivery_type))
+ carrier_packages = packages and packages.filtered(lambda p: not p.carrier_tracking_ref and
+ (not p.carrier_id or p.carrier_id == carrier) and
+ p.packaging_id.package_carrier_type in (False, '', 'none', carrier.delivery_type))
if packages and not carrier_packages:
continue
if hasattr(carrier, '%s_rate_shipment_multi' % self.delivery_type):
@@ -244,3 +268,47 @@ class DeliveryCarrier(models.Model):
})
return getattr(self, '%s_cancel_shipment' % self.delivery_type)(pickings)
+
+
+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_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.onchange('package_declared_value')
+ def _onchange_package_declared_value(self):
+ picking = self.env['stock.picking'].browse(self.env.context['active_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
+ else:
+ self.package_require_insurance = picking.require_insurance == 'yes'
+ if picking.require_signature == 'auto':
+ self.package_require_signature = value and picking.carrier_id.automatic_sig_req_value and value >= picking.carrier_id.automatic_sig_req_value
+ else:
+ 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,
+ })
diff --git a/delivery_hibou/models/stock.py b/delivery_hibou/models/stock.py
index 52e9c670..1a620b32 100644
--- a/delivery_hibou/models/stock.py
+++ b/delivery_hibou/models/stock.py
@@ -7,6 +7,9 @@ class StockQuantPackage(models.Model):
carrier_id = fields.Many2one('delivery.carrier', string='Carrier')
carrier_tracking_ref = fields.Char(string='Tracking Reference')
+ require_insurance = fields.Boolean(string='Require Insurance')
+ require_signature = fields.Boolean(string='Require Signature')
+ declared_value = fields.Float(string='Declared Value')
def _get_active_picking(self):
picking_id = self._context.get('active_id')
@@ -39,6 +42,12 @@ class StockPicking(models.Model):
('no', 'No'),
], string='Require Insurance', default='auto',
help='If your carrier supports it, auto should be calculated off of the "Automatic Insurance Value" field.')
+ require_signature = fields.Selection([
+ ('auto', 'Automatic'),
+ ('yes', 'Yes'),
+ ('no', 'No'),
+ ], string='Require Signature', default='auto',
+ help='If your carrier supports it, auto should be calculated off of the "Automatic Signature Required Value" field.')
package_carrier_tracking_ref = fields.Char(string='Package Tracking Numbers', compute='_compute_package_carrier_tracking_ref')
@api.depends('package_ids.carrier_tracking_ref')
@@ -84,8 +93,10 @@ class StockPicking(models.Model):
res = super(StockPicking, self).create(values)
return res
- def declared_value(self):
+ def declared_value(self, package=None):
self.ensure_one()
+ if package:
+ return package.declared_value
cost = sum([(l.product_id.standard_price * l.qty_done) for l in self.move_line_ids] or [0.0])
if not cost:
# Assume Full Value
@@ -129,6 +140,8 @@ class StockPicking(models.Model):
tracking_numbers.append(tracking_number)
# Try to add tracking to the individual packages.
potential_tracking_numbers = tracking_number.split(',')
+ if len(potential_tracking_numbers) == 1:
+ potential_tracking_numbers = tracking_number.split('+') # UPS for example...
if len(potential_tracking_numbers) >= len(carrier_packages):
for t, p in zip(potential_tracking_numbers, carrier_packages):
p.carrier_tracking_ref = t
diff --git a/delivery_hibou/tests/test_delivery_hibou.py b/delivery_hibou/tests/test_delivery_hibou.py
index 95a9e26a..49f49d0f 100644
--- a/delivery_hibou/tests/test_delivery_hibou.py
+++ b/delivery_hibou/tests/test_delivery_hibou.py
@@ -28,8 +28,10 @@ class TestDeliveryHibou(common.TransactionCase):
# Assign values to new Carrier
test_insurance_value = 600
+ test_sig_req_value = 300
test_procurement_priority = '1'
self.carrier.automatic_insurance_value = test_insurance_value
+ self.carrier.automatic_sig_req_value = test_sig_req_value
self.carrier.procurement_priority = test_procurement_priority
@@ -71,7 +73,9 @@ class TestDeliveryHibou(common.TransactionCase):
def test_carrier_hibou_out(self):
test_insurance_value = 4000
+ test_sig_req_value = 4000
self.carrier.automatic_insurance_value = test_insurance_value
+ self.carrier.automatic_sig_req_value = test_sig_req_value
picking_out = self.env.ref('stock.outgoing_shipment_main_warehouse')
picking_out.action_assign()
@@ -88,21 +92,29 @@ class TestDeliveryHibou(common.TransactionCase):
# The 'value' is assumed to be all of the product value from the initial demand.
self.assertEqual(picking_out.declared_value(), 15.0 * 3300.0)
self.assertEqual(picking_out.carrier_id.get_insurance_value(picking=picking_out), picking_out.declared_value())
+ self.assertTrue(picking_out.carrier_id.get_signature_required(picking=picking_out))
# Workflow where user explicitly opts out of insurance on the picking level.
picking_out.require_insurance = 'no'
+ picking_out.require_signature = 'no'
self.assertEqual(picking_out.carrier_id.get_insurance_value(picking=picking_out), 0.0)
+ self.assertFalse(picking_out.carrier_id.get_signature_required(picking=picking_out))
picking_out.require_insurance = 'auto'
+ picking_out.require_signature = 'auto'
# Lets choose to only delivery one piece at the moment.
# This does not meet the minimum on the carrier to have insurance value.
picking_out.move_line_ids.qty_done = 1.0
self.assertEqual(picking_out.declared_value(), 3300.0)
self.assertEqual(picking_out.carrier_id.get_insurance_value(picking=picking_out), 0.0)
+ self.assertFalse(picking_out.carrier_id.get_signature_required(picking=picking_out))
# Workflow where user opts in to insurance.
picking_out.require_insurance = 'yes'
+ picking_out.require_signature = 'yes'
self.assertEqual(picking_out.carrier_id.get_insurance_value(picking=picking_out), 3300.0)
+ self.assertTrue(picking_out.carrier_id.get_signature_required(picking=picking_out))
picking_out.require_insurance = 'auto'
+ picking_out.require_signature = 'auto'
# Test with picking having 3rd party account.
self.assertEqual(picking_out.carrier_id.get_third_party_account(picking=picking_out), None)
@@ -129,9 +141,9 @@ class TestDeliveryHibou(common.TransactionCase):
picking_in.carrier_id = self.carrier
# This relies heavily on the 'stock' demo data.
# Should only have a single move_line_ids and it should not be done at all.
- self.assertEqual(picking_in.move_line_ids.mapped('qty_done'), [0.0, 0.0, 0.0])
- self.assertEqual(picking_in.move_line_ids.mapped('product_uom_qty'), [35.0, 10.0, 12.0])
- self.assertEqual(picking_in.move_line_ids.mapped('product_id.standard_price'), [55.0, 35.0, 1700.0])
+ self.assertEqual(picking_in.move_line_ids.mapped('qty_done'), [0.0])
+ self.assertEqual(picking_in.move_line_ids.mapped('product_uom_qty'), [35.0])
+ self.assertEqual(picking_in.move_line_ids.mapped('product_id.standard_price'), [55.0])
self.assertEqual(picking_in.carrier_id._classify_picking(picking=picking_in), 'in')
self.assertEqual(picking_in.carrier_id.get_shipper_company(picking=picking_in),
diff --git a/delivery_hibou/views/delivery_views.xml b/delivery_hibou/views/delivery_views.xml
index 638ef921..a1e4015f 100644
--- a/delivery_hibou/views/delivery_views.xml
+++ b/delivery_hibou/views/delivery_views.xml
@@ -7,6 +7,7 @@
+
@@ -20,6 +21,11 @@
[('product_id', '=', False)]
+
+
+
+
+
diff --git a/delivery_hibou/views/stock_views.xml b/delivery_hibou/views/stock_views.xml
index f806127d..a1a53b30 100644
--- a/delivery_hibou/views/stock_views.xml
+++ b/delivery_hibou/views/stock_views.xml
@@ -17,6 +17,9 @@
+
+
+
@@ -29,6 +32,7 @@
+
diff --git a/delivery_ups_hibou/__manifest__.py b/delivery_ups_hibou/__manifest__.py
index fdaf3477..3b93b171 100644
--- a/delivery_ups_hibou/__manifest__.py
+++ b/delivery_ups_hibou/__manifest__.py
@@ -1,6 +1,6 @@
{
'name': 'Hibou UPS Shipping',
- 'version': '12.0.1.1.0',
+ 'version': '12.0.1.2.0',
'category': 'Stock',
'author': "Hibou Corp.",
'license': 'OPL-1',
@@ -10,6 +10,7 @@
'delivery_hibou',
],
'data': [
+ 'views/stock_views.xml',
],
'demo': [
],
diff --git a/delivery_ups_hibou/api/Error1.1.xsd b/delivery_ups_hibou/api/Error1.1.xsd
new file mode 100644
index 00000000..c720608a
--- /dev/null
+++ b/delivery_ups_hibou/api/Error1.1.xsd
@@ -0,0 +1,59 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/delivery_ups_hibou/api/IFWS.xsd b/delivery_ups_hibou/api/IFWS.xsd
new file mode 100644
index 00000000..c36e5b33
--- /dev/null
+++ b/delivery_ups_hibou/api/IFWS.xsd
@@ -0,0 +1,318 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/delivery_ups_hibou/api/LBRecovery.xsd b/delivery_ups_hibou/api/LBRecovery.xsd
new file mode 100644
index 00000000..05588c56
--- /dev/null
+++ b/delivery_ups_hibou/api/LBRecovery.xsd
@@ -0,0 +1,166 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/delivery_ups_hibou/api/LabelRecoveryWS.wsdl b/delivery_ups_hibou/api/LabelRecoveryWS.wsdl
new file mode 100644
index 00000000..fe895eba
--- /dev/null
+++ b/delivery_ups_hibou/api/LabelRecoveryWS.wsdl
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/delivery_ups_hibou/api/RateWS.wsdl b/delivery_ups_hibou/api/RateWS.wsdl
new file mode 100644
index 00000000..7aeb7555
--- /dev/null
+++ b/delivery_ups_hibou/api/RateWS.wsdl
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/delivery_ups_hibou/api/RateWebServiceSchema.xsd b/delivery_ups_hibou/api/RateWebServiceSchema.xsd
new file mode 100644
index 00000000..951ab3a1
--- /dev/null
+++ b/delivery_ups_hibou/api/RateWebServiceSchema.xsd
@@ -0,0 +1,644 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/delivery_ups_hibou/api/Ship.wsdl b/delivery_ups_hibou/api/Ship.wsdl
new file mode 100644
index 00000000..2c0b081d
--- /dev/null
+++ b/delivery_ups_hibou/api/Ship.wsdl
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/delivery_ups_hibou/api/ShipWebServiceSchema.xsd b/delivery_ups_hibou/api/ShipWebServiceSchema.xsd
new file mode 100644
index 00000000..cd1c1236
--- /dev/null
+++ b/delivery_ups_hibou/api/ShipWebServiceSchema.xsd
@@ -0,0 +1,933 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/delivery_ups_hibou/api/TNTWS.wsdl b/delivery_ups_hibou/api/TNTWS.wsdl
new file mode 100644
index 00000000..5e69403f
--- /dev/null
+++ b/delivery_ups_hibou/api/TNTWS.wsdl
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/delivery_ups_hibou/api/TimeInTransitWebServiceSchema.xsd b/delivery_ups_hibou/api/TimeInTransitWebServiceSchema.xsd
new file mode 100644
index 00000000..1c6928e0
--- /dev/null
+++ b/delivery_ups_hibou/api/TimeInTransitWebServiceSchema.xsd
@@ -0,0 +1,193 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/delivery_ups_hibou/api/UPSSecurity.xsd b/delivery_ups_hibou/api/UPSSecurity.xsd
new file mode 100644
index 00000000..63378ec4
--- /dev/null
+++ b/delivery_ups_hibou/api/UPSSecurity.xsd
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/delivery_ups_hibou/api/Void.wsdl b/delivery_ups_hibou/api/Void.wsdl
new file mode 100644
index 00000000..caee6a1e
--- /dev/null
+++ b/delivery_ups_hibou/api/Void.wsdl
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/delivery_ups_hibou/api/VoidWebServiceSchema.xsd b/delivery_ups_hibou/api/VoidWebServiceSchema.xsd
new file mode 100644
index 00000000..7b69d7c0
--- /dev/null
+++ b/delivery_ups_hibou/api/VoidWebServiceSchema.xsd
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/delivery_ups_hibou/api/common.xsd b/delivery_ups_hibou/api/common.xsd
new file mode 100644
index 00000000..ddb84840
--- /dev/null
+++ b/delivery_ups_hibou/api/common.xsd
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/delivery_ups_hibou/models/__init__.py b/delivery_ups_hibou/models/__init__.py
index 102ebacd..ddfac4e5 100644
--- a/delivery_ups_hibou/models/__init__.py
+++ b/delivery_ups_hibou/models/__init__.py
@@ -1,4 +1,5 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from . import delivery_ups
+from . import stock
from . import ups_request_patch
diff --git a/delivery_ups_hibou/models/delivery_ups.py b/delivery_ups_hibou/models/delivery_ups.py
index 9331eebb..73f7a381 100644
--- a/delivery_ups_hibou/models/delivery_ups.py
+++ b/delivery_ups_hibou/models/delivery_ups.py
@@ -11,6 +11,15 @@ _logger = logging.getLogger(__name__)
class ProviderUPS(models.Model):
_inherit = 'delivery.carrier'
+ def _get_ups_signature_required_type(self, order=None, picking=None, package=None):
+ # '3' for Adult Sig.
+ return '2'
+
+ def _get_ups_signature_required(self, order=None, picking=None, package=None):
+ if self.get_signature_required(order=order, picking=picking, package=package):
+ return self._get_ups_signature_required_type(order=order, picking=picking, package=package)
+ return False
+
def _get_ups_is_third_party(self, order=None, picking=None):
third_party_account = self.get_third_party_account(order=order, picking=picking)
if third_party_account:
@@ -21,6 +30,16 @@ class ProviderUPS(models.Model):
return True
return False
+ def _get_main_ups_account_number(self, order=None, picking=None):
+ wh = None
+ if order:
+ wh = order.warehouse_id
+ if picking:
+ wh = picking.picking_type_id.warehouse_id
+ if wh and wh.ups_shipper_number:
+ return wh.ups_shipper_number
+ return self.ups_shipper_number
+
def _get_ups_account_number(self, order=None, picking=None):
"""
Common hook to customize what UPS Account number to use.
@@ -34,6 +53,8 @@ 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
return self.ups_shipper_number
@@ -41,14 +62,20 @@ class ProviderUPS(models.Model):
def _get_ups_carrier_account(self, picking):
# 3rd party billing should return False if not used.
account = self._get_ups_account_number(picking=picking)
- return account if account != self.ups_shipper_number else False
+ return account if account not in (self.ups_shipper_number, picking.picking_type_id.warehouse_id.ups_shipper_number) else False
"""
Overrides to use Hibou Delivery methods to get shipper etc. and to add 'transit_days' to result.
"""
def ups_rate_shipment(self, order):
superself = self.sudo()
- srm = UPSRequest(self.log_xml, superself.ups_username, superself.ups_passwd, superself.ups_shipper_number, superself.ups_access_number, self.prod_environment)
+ # Hibou Shipping
+ signature_required = superself._get_ups_signature_required(order=order)
+ insurance_value = superself.get_insurance_value(order=order)
+ currency = order.currency_id or order.company_id.currency_id
+ insurance_currency_code = currency.name
+
+ srm = UPSRequest(self.log_xml, superself.ups_username, superself.ups_passwd, superself._get_main_ups_account_number(order=order), superself.ups_access_number, self.prod_environment)
ResCurrency = self.env['res.currency']
max_weight = self.ups_default_packaging_id.max_weight
packages = []
@@ -63,11 +90,14 @@ class ProviderUPS(models.Model):
last_package_weight = total_weight % max_weight
for seq in range(total_package):
- packages.append(Package(self, max_weight))
+ packages.append(Package(self, max_weight,
+ insurance_value=insurance_value, insurance_currency_code=insurance_currency_code, signature_required=signature_required))
if last_package_weight:
- packages.append(Package(self, last_package_weight))
+ packages.append(Package(self, last_package_weight,
+ insurance_value=insurance_value, insurance_currency_code=insurance_currency_code, signature_required=signature_required))
else:
- packages.append(Package(self, total_weight))
+ packages.append(Package(self, total_weight,
+ insurance_value=insurance_value, insurance_currency_code=insurance_currency_code, signature_required=signature_required))
shipment_info = {
'total_qty': total_qty # required when service type = 'UPS Worldwide Express Freight'
@@ -130,24 +160,38 @@ class ProviderUPS(models.Model):
def ups_send_shipping(self, pickings):
res = []
superself = self.sudo()
- srm = UPSRequest(self.log_xml, superself.ups_username, superself.ups_passwd, superself.ups_shipper_number, superself.ups_access_number, self.prod_environment)
ResCurrency = self.env['res.currency']
for picking in pickings:
+ srm = UPSRequest(self.log_xml, superself.ups_username, superself.ups_passwd, superself._get_main_ups_account_number(picking=picking), superself.ups_access_number, self.prod_environment)
# Hibou Delivery
shipper_company = superself.get_shipper_company(picking=picking)
shipper_warehouse = superself.get_shipper_warehouse(picking=picking)
recipient = superself.get_recipient(picking=picking)
+ currency = picking.sale_id.currency_id if picking.sale_id else picking.company_id.currency_id
+ insurance_currency_code = currency.name
+
+ picking_packages = picking.package_ids
+ package_carriers = picking_packages.mapped('carrier_id')
+ if package_carriers:
+ # only ship ours
+ picking_packages = picking_packages.filtered(lambda p: p.carrier_id == self and not p.carrier_tracking_ref)
+
+ if not picking_packages:
+ continue
packages = []
package_names = []
- if picking.package_ids:
+ if picking_packages:
# Create all packages
- for package in picking.package_ids:
- packages.append(Package(self, package.shipping_weight, quant_pack=package.packaging_id, name=package.name))
+ for package in picking_packages:
+ packages.append(Package(self, package.shipping_weight, quant_pack=package.packaging_id, name=package.name,
+ insurance_value=superself.get_insurance_value(picking=picking, package=package), insurance_currency_code=insurance_currency_code, signature_required=superself._get_ups_signature_required(picking=picking, package=package)))
package_names.append(package.name)
+
+ # what is the point of weight_bulk?
# Create one package with the rest (the content that is not in a package)
- if picking.weight_bulk:
- packages.append(Package(self, picking.weight_bulk))
+ # if picking.weight_bulk:
+ # packages.append(Package(self, picking.weight_bulk))
invoice_line_total = 0
for move in picking.move_lines:
@@ -181,7 +225,7 @@ class ProviderUPS(models.Model):
if 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_packages and picking_packages[0].packaging_id.shipper_package_code or self.ups_default_packaging_id.shipper_package_code
result = srm.send_shipping(
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,
@@ -231,14 +275,16 @@ class ProviderUPS(models.Model):
return rates
def _ups_rate_shipment_multi_package(self, order=None, picking=None, package=None):
- # TODO package here is ignored, it should not be (UPS is not multi-rating capable until we can get rates for a single package)
superself = self.sudo()
- srm = UPSRequest(self.log_xml, superself.ups_username, superself.ups_passwd, superself.ups_shipper_number, superself.ups_access_number, self.prod_environment)
+ srm = UPSRequest(self.log_xml, superself.ups_username, superself.ups_passwd, superself._get_main_ups_account_number(order=order, picking=picking), superself.ups_access_number, self.prod_environment)
ResCurrency = self.env['res.currency']
max_weight = self.ups_default_packaging_id.max_weight
packages = []
if order:
+ insurance_value = superself.get_insurance_value(order=order)
+ signature_required = superself._get_ups_signature_required(order=order)
currency = order.currency_id
+ insurance_currency_code = currency.name
company = order.company_id
date_order = order.date_order or fields.Date.today()
total_qty = 0
@@ -252,19 +298,27 @@ class ProviderUPS(models.Model):
last_package_weight = total_weight % max_weight
for seq in range(total_package):
- packages.append(Package(self, max_weight))
+ packages.append(Package(self, max_weight, insurance_value=insurance_value, insurance_currency_code=insurance_currency_code, signature_required=signature_required))
if last_package_weight:
- packages.append(Package(self, last_package_weight))
+ packages.append(Package(self, last_package_weight, insurance_value=insurance_value, insurance_currency_code=insurance_currency_code, signature_required=signature_required))
else:
- packages.append(Package(self, total_weight))
+ packages.append(Package(self, total_weight, insurance_value=insurance_value, insurance_currency_code=insurance_currency_code, signature_required=signature_required))
else:
currency = picking.sale_id.currency_id if picking.sale_id else picking.company_id.currency_id
+ insurance_currency_code = currency.name
company = picking.company_id
date_order = picking.sale_id.date_order or fields.Date.today() if picking.sale_id else fields.Date.today()
# Is total quantity the number of packages or the number of items being shipped?
- total_qty = len(picking.package_ids)
- packages = [Package(self, package.shipping_weight) for package in picking.package_ids]
-
+ if package:
+ total_qty = 1
+ packages = [Package(self, package.shipping_weight, insurance_value=superself.get_insurance_value(picking=picking, package=package), insurance_currency_code=insurance_currency_code, signature_required=superself._get_ups_signature_required(picking=picking, package=package))]
+ elif picking.package_ids:
+ # all packages....
+ total_qty = len(picking.package_ids)
+ packages = [Package(self, package.shipping_weight, insurance_value=superself.get_insurance_value(picking=picking, package=package), insurance_currency_code=insurance_currency_code, signature_required=superself._get_ups_signature_required(picking=picking, package=package)) for package in picking.package_ids.filtered(lambda p: not p.carrier_id)]
+ else:
+ total_qty = 1
+ packages.append(Package(self, picking.shipping_weight or picking.weight, insurance_value=superself.get_insurance_value(picking=picking), insurance_currency_code=insurance_currency_code, signature_required=superself._get_ups_signature_required(picking=picking)))
shipment_info = {
'total_qty': total_qty # required when service type = 'UPS Worldwide Express Freight'
@@ -294,9 +348,8 @@ class ProviderUPS(models.Model):
'error_message': check_value,
'warning_message': False,
}]
-
- #ups_service_type = order.ups_service_type or self.ups_default_service_type
- ups_service_type = None # See if this gets us all service types
+ # We now use Shop if we send multi=True
+ ups_service_type = (order.ups_service_type or self.ups_default_service_type) if order else self.ups_default_service_type
result = srm.get_shipping_price(
shipment_info=shipment_info, packages=packages, shipper=shipper_company, ship_from=shipper_warehouse,
ship_to=recipient, packaging_type=self.ups_default_packaging_id.shipper_package_code, service_type=ups_service_type,
@@ -306,7 +359,14 @@ class ProviderUPS(models.Model):
response = []
for rate in result:
- if rate.get('error_message'):
+ if isinstance(rate, str):
+ # assume error
+ response.append({
+ 'success': False, 'price': 0.0,
+ 'error_message': _('Error:\n%s') % rate,
+ 'warning_message': False,
+ })
+ elif rate.get('error_message'):
_logger.error('UPS error: %s' % rate['error_message'])
response.append({
'success': False, 'price': 0.0,
@@ -330,6 +390,7 @@ class ProviderUPS(models.Model):
if carrier:
response.append({
'carrier': carrier,
+ 'package': package or self.env['stock.quant.package'].browse(),
'success': True,
'price': price,
'error_message': False,
diff --git a/delivery_ups_hibou/models/stock.py b/delivery_ups_hibou/models/stock.py
new file mode 100644
index 00000000..2c06bfed
--- /dev/null
+++ b/delivery_ups_hibou/models/stock.py
@@ -0,0 +1,9 @@
+# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
+
+from odoo import fields, models
+
+
+class StockWarehouse(models.Model):
+ _inherit = 'stock.warehouse'
+
+ ups_shipper_number = fields.Char(string='UPS Shipper Number')
diff --git a/delivery_ups_hibou/models/ups_request_patch.py b/delivery_ups_hibou/models/ups_request_patch.py
index a845ed82..86cbf337 100644
--- a/delivery_ups_hibou/models/ups_request_patch.py
+++ b/delivery_ups_hibou/models/ups_request_patch.py
@@ -1,7 +1,7 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
import suds
-from odoo.addons.delivery_ups.models.ups_request import UPSRequest
+from odoo.addons.delivery_ups.models.ups_request import UPSRequest, Package
import logging
_logger = logging.getLogger(__name__)
@@ -78,7 +78,7 @@ def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from
else:
shipment.ShipmentServiceOptions = ''
- shipment.ShipmentRatingOptions.NegotiatedRatesIndicator = 1
+ shipment.ShipmentRatingOptions.NegotiatedRatesIndicator = '1'
try:
# Get rate using for provided detail
@@ -145,4 +145,188 @@ 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):
+ client = self._set_client(self.ship_wsdl, 'Ship', 'ShipmentRequest')
+
+ request = client.factory.create('ns0:RequestType')
+ request.RequestOption = 'nonvalidate'
+
+ namespace = 'ns3'
+ label = client.factory.create('{}:LabelSpecificationType'.format(namespace))
+
+ label.LabelImageFormat.Code = label_file_type
+ label.LabelImageFormat.Description = label_file_type
+ if label_file_type != 'GIF':
+ label.LabelStockSize.Height = '6'
+ label.LabelStockSize.Width = '4'
+
+ shipment = client.factory.create('{}:ShipmentType'.format(namespace))
+ shipment.Description = shipment_info.get('description')
+
+ for package in self.set_package_detail(client, packages, packaging_type, namespace, ship_from, ship_to, cod_info):
+ shipment.Package.append(package)
+
+ shipment.Shipper.AttentionName = shipper.name or ''
+ shipment.Shipper.Name = shipper.parent_id.name or shipper.name or ''
+ 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 ''
+ shipment.Shipper.Address.CountryCode = shipper.country_id.code or ''
+ 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.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.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.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.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.Number = self._clean_phone_number(shipment_info['phone'])
+ if not ship_to.commercial_partner_id.is_company:
+ shipment.ShipTo.Address.ResidentialAddressIndicator = suds.null()
+
+ 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
+
+ # 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.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')
+ shipcharge.Type = '01'
+
+ # Bill Recevier 'Bill My Account'
+ if ups_carrier_account:
+ shipcharge.BillReceiver.AccountNumber = ups_carrier_account
+ shipcharge.BillReceiver.Address.PostalCode = ship_to.zip
+ else:
+ shipcharge.BillShipper.AccountNumber = self.shipper_number or ''
+
+ payment_info.ShipmentCharge = shipcharge
+ shipment.PaymentInformation = payment_info
+
+ if saturday_delivery:
+ 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)
+
+
+def patched_set_package_detail(self, client, packages, packaging_type, namespace, ship_from, ship_to, cod_info):
+ Packages = []
+ for i, p in enumerate(packages):
+ package = client.factory.create('{}:PackageType'.format(namespace))
+ if hasattr(package, 'Packaging'):
+ package.Packaging.Code = p.packaging_type or packaging_type or ''
+ elif hasattr(package, 'PackagingType'):
+ 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.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.COD.CODFundsCode = str(cod_info['funds_code'])
+ package.PackageServiceOptions.COD.CODAmount.MonetaryValue = cod_info['monetary_value']
+ package.PackageServiceOptions.COD.CODAmount.CurrencyCode = cod_info['currency']
+
+ 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.Code = 'PM'
+ reference_number.Value = p.name
+ reference_number.BarCodeIndicator = p.name
+ package.ReferenceNumber = reference_number
+
+ Packages.append(package)
+ return Packages
+
+
UPSRequest.get_shipping_price = patched_get_shipping_price
+UPSRequest.send_shipping = patched_send_shipping
+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_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.packaging_type = quant_pack and quant_pack.shipper_package_code or False
+ self.insurance_value = insurance_value
+ self.insurance_currency_code = insurance_currency_code
+ self.signature_required = signature_required
+
+
+Package.__init__ = patched__init__2
diff --git a/delivery_ups_hibou/views/stock_views.xml b/delivery_ups_hibou/views/stock_views.xml
new file mode 100644
index 00000000..e74ebd99
--- /dev/null
+++ b/delivery_ups_hibou/views/stock_views.xml
@@ -0,0 +1,15 @@
+
+
+
+
+ stock.warehouse
+ stock.warehouse
+
+
+
+
+
+
+
+
+
diff --git a/sale_planner/__init__.py b/sale_planner/__init__.py
index 134df274..b0eafef5 100644
--- a/sale_planner/__init__.py
+++ b/sale_planner/__init__.py
@@ -1,2 +1,4 @@
+# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
+
from . import wizard
from . import models
diff --git a/sale_planner/__manifest__.py b/sale_planner/__manifest__.py
index 680a4538..3f88bde6 100644
--- a/sale_planner/__manifest__.py
+++ b/sale_planner/__manifest__.py
@@ -1,10 +1,10 @@
{
'name': 'Sale Order Planner',
'summary': 'Plans order dates and warehouses.',
- 'version': '12.0.1.0.0',
+ 'version': '12.0.2.0.0',
'author': "Hibou Corp.",
'category': 'Sale',
- 'license': 'AGPL-3',
+ 'license': 'OPL-1',
'complexity': 'expert',
'images': [],
'website': "https://hibou.io",
@@ -37,6 +37,7 @@ on the specific method's characteristics. (e.g. Do they deliver on Saturday?)
'views/stock.xml',
'views/delivery.xml',
'views/product.xml',
+ 'views/res_config_settings_views.xml',
],
'auto_install': False,
'installable': True,
diff --git a/sale_planner/models/__init__.py b/sale_planner/models/__init__.py
index ff524f40..95b4955a 100644
--- a/sale_planner/models/__init__.py
+++ b/sale_planner/models/__init__.py
@@ -1,3 +1,5 @@
+# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
+
from . import delivery
from . import partner
from . import planning
@@ -5,3 +7,4 @@ from . import product
from . import resource
from . import sale
from . import stock
+from . import res_config_settings
diff --git a/sale_planner/models/delivery.py b/sale_planner/models/delivery.py
index c8526c34..dc66ab81 100644
--- a/sale_planner/models/delivery.py
+++ b/sale_planner/models/delivery.py
@@ -1,3 +1,5 @@
+# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
+
from datetime import timedelta
from odoo import api, fields, models
@@ -61,6 +63,9 @@ class DeliveryCarrier(models.Model):
def calculate_transit_days(self, date_planned, date_delivered):
self.ensure_one()
+ if not self.delivery_calendar_id:
+ return 0
+
if isinstance(date_planned, str):
date_planned = fields.Datetime.from_string(date_planned)
if isinstance(date_delivered, str):
diff --git a/sale_planner/models/partner.py b/sale_planner/models/partner.py
index 23e258d3..fdf5780b 100644
--- a/sale_planner/models/partner.py
+++ b/sale_planner/models/partner.py
@@ -1,3 +1,5 @@
+# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
+
from odoo import api, fields, models
try:
diff --git a/sale_planner/models/planning.py b/sale_planner/models/planning.py
index 47d645af..54969669 100644
--- a/sale_planner/models/planning.py
+++ b/sale_planner/models/planning.py
@@ -1,3 +1,5 @@
+# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
+
from odoo import api, fields, models
diff --git a/sale_planner/models/product.py b/sale_planner/models/product.py
index 8c666a60..950ec2d2 100644
--- a/sale_planner/models/product.py
+++ b/sale_planner/models/product.py
@@ -1,3 +1,5 @@
+# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
+
from odoo import api, fields, models
diff --git a/sale_planner/models/res_config_settings.py b/sale_planner/models/res_config_settings.py
new file mode 100644
index 00000000..06e2f899
--- /dev/null
+++ b/sale_planner/models/res_config_settings.py
@@ -0,0 +1,79 @@
+# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
+
+from odoo import api, fields, models
+
+
+def sale_planner_warehouse_ids(env, company):
+ get_param = env['ir.config_parameter'].sudo().get_param
+ warehouse_ids = get_param('sale.planner.warehouse_ids.%s' % (company.id, )) or []
+ if warehouse_ids and isinstance(warehouse_ids, str):
+ try:
+ warehouse_ids = [int(i) for i in warehouse_ids.split(',')]
+ except:
+ warehouse_ids = []
+ return warehouse_ids
+
+
+def sale_planner_carrier_ids(env, company):
+ get_param = env['ir.config_parameter'].sudo().get_param
+ carrier_ids = get_param('sale.planner.carrier_ids.%s' % (company.id, )) or []
+ if carrier_ids and isinstance(carrier_ids, str):
+ try:
+ carrier_ids = [int(c) for c in carrier_ids.split(',')]
+ except:
+ carrier_ids = []
+ return carrier_ids
+
+
+class ResConfigSettings(models.TransientModel):
+ _inherit = 'res.config.settings'
+
+ sale_planner_warehouse_ids = fields.Many2many('stock.warehouse',
+ string='Sale Order Planner Warehouses',
+ compute='_compute_sale_planner_warehouse_ids',
+ inverse='_inverse_sale_planner_warehouse_ids')
+ sale_planner_carrier_ids = fields.Many2many('delivery.carrier',
+ string='Sale Order Planner Carriers',
+ compute='_compute_sale_planner_carrier_ids',
+ inverse='_inverse_sale_planner_carrier_ids')
+
+ def _compute_sale_planner_warehouse_ids_ids(self):
+ company = self.company_id or self.env.user.company_id
+ return sale_planner_warehouse_ids(self.env, company)
+
+ def _compute_sale_planner_carrier_ids_ids(self):
+ company = self.company_id or self.env.user.company_id
+ return sale_planner_carrier_ids(self.env, company)
+
+ def _compute_sale_planner_warehouse_ids(self):
+ for settings in self:
+ warehouse_ids = settings._compute_sale_planner_warehouse_ids_ids()
+ warehouses = self.env['stock.warehouse'].browse(warehouse_ids)
+ settings.sale_planner_warehouse_ids = warehouses
+
+ def _compute_sale_planner_carrier_ids(self):
+ for settings in self:
+ carrier_ids = settings._compute_sale_planner_carrier_ids_ids()
+ carriers = self.env['delivery.carrier'].browse(carrier_ids)
+ settings.sale_planner_carrier_ids = carriers
+
+ def _inverse_sale_planner_warehouse_ids(self):
+ set_param = self.env['ir.config_parameter'].sudo().set_param
+ company_id = self.company_id.id or self.env.user.company_id.id
+ for settings in self:
+ warehouse_ids = ','.join(str(i) for i in settings.sale_planner_warehouse_ids.ids)
+ set_param('sale.planner.warehouse_ids.%s' % (company_id, ), warehouse_ids)
+
+ def _inverse_sale_planner_carrier_ids(self):
+ set_param = self.env['ir.config_parameter'].sudo().set_param
+ company_id = self.company_id.id or self.env.user.company_id.id
+ for settings in self:
+ carrier_ids = ','.join(str(i) for i in settings.sale_planner_carrier_ids.ids)
+ set_param('sale.planner.carrier_ids.%s' % (company_id, ), carrier_ids)
+
+ @api.model
+ def get_values(self):
+ res = super(ResConfigSettings, self).get_values()
+ res['sale_planner_warehouse_ids'] = [(6, 0, self._compute_sale_planner_warehouse_ids_ids())]
+ res['sale_planner_carrier_ids'] = [(6, 0, self._compute_sale_planner_carrier_ids_ids())]
+ return res
diff --git a/sale_planner/models/sale.py b/sale_planner/models/sale.py
index 6d5e46b0..c2878bdb 100644
--- a/sale_planner/models/sale.py
+++ b/sale_planner/models/sale.py
@@ -1,3 +1,5 @@
+# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
+
from odoo import api, fields, models
diff --git a/sale_planner/models/stock.py b/sale_planner/models/stock.py
index 4d72f4f4..10011e6c 100644
--- a/sale_planner/models/stock.py
+++ b/sale_planner/models/stock.py
@@ -1,3 +1,5 @@
+# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
+
from odoo import api, fields, models
@@ -7,3 +9,7 @@ class Warehouse(models.Model):
shipping_calendar_id = fields.Many2one(
'resource.calendar', 'Shipping Calendar',
help="This calendar represents shipping availability from the warehouse.")
+ sale_planner_carrier_ids = fields.Many2many('delivery.carrier',
+ relation='sale_planner_carrier_wh_rel',
+ string='Sale Order Planner Base Carriers',
+ help='Overrides the global carriers.')
diff --git a/sale_planner/tests/__init__.py b/sale_planner/tests/__init__.py
index 25366b57..8208aa7b 100644
--- a/sale_planner/tests/__init__.py
+++ b/sale_planner/tests/__init__.py
@@ -1 +1,3 @@
+# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
+
from . import test_planner
diff --git a/sale_planner/tests/test_planner.py b/sale_planner/tests/test_planner.py
index 9f5e3f16..d896c9d4 100644
--- a/sale_planner/tests/test_planner.py
+++ b/sale_planner/tests/test_planner.py
@@ -1,3 +1,5 @@
+# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
+
from odoo.tests import common
from datetime import datetime, timedelta
from json import loads as json_decode
diff --git a/sale_planner/views/res_config_settings_views.xml b/sale_planner/views/res_config_settings_views.xml
new file mode 100644
index 00000000..ca5f5511
--- /dev/null
+++ b/sale_planner/views/res_config_settings_views.xml
@@ -0,0 +1,39 @@
+
+
+
+
+ res.config.settings.view.form.inherit
+ res.config.settings
+
+
+
+
+
Sale Order Planner
+
+
+
+
+
+ Add a carrier that represents the 'base rate' for a carrier's type.
+ For example, you should add 1 FedEx carrier here and let us build up the
+ rates for your other FedEx shipping methods.
+
+
+
+
+
+
+
+
+
+ Warehouses you typically ship inventory out of that you want to
+ include in the planning of sale orders.
+
+
+
+
+
+
+
+
+
diff --git a/sale_planner/views/stock.xml b/sale_planner/views/stock.xml
index d0195d86..81d0f78e 100644
--- a/sale_planner/views/stock.xml
+++ b/sale_planner/views/stock.xml
@@ -7,6 +7,7 @@
+
diff --git a/sale_planner/wizard/__init__.py b/sale_planner/wizard/__init__.py
index 235b12a8..48b8dc48 100644
--- a/sale_planner/wizard/__init__.py
+++ b/sale_planner/wizard/__init__.py
@@ -1 +1,3 @@
+# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
+
from . import order_planner
diff --git a/sale_planner/wizard/order_planner.py b/sale_planner/wizard/order_planner.py
index 179f8617..28e1a73a 100644
--- a/sale_planner/wizard/order_planner.py
+++ b/sale_planner/wizard/order_planner.py
@@ -1,3 +1,5 @@
+# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
+
from math import sin, cos, sqrt, atan2, radians
from json import dumps, loads
from copy import deepcopy
@@ -15,6 +17,7 @@ except ImportError:
from odoo import api, fields, models, tools
from odoo.addons.base_geolocalize.models.res_partner import geo_find, geo_query_address
+from ..models.res_config_settings import sale_planner_warehouse_ids, sale_planner_carrier_ids
class FakeCollection():
@@ -302,19 +305,18 @@ class SaleOrderMakePlan(models.TransientModel):
if domain:
if not isinstance(domain, (list, tuple)):
domain = tools.safe_eval(domain)
- else:
- domain = []
-
if self.env.context.get('warehouse_domain'):
+ if not domain:
+ domain = []
domain.extend(self.env.context.get('warehouse_domain'))
+ if domain:
+ return warehouse.search(domain)
- irconfig_parameter = self.env['ir.config_parameter'].sudo()
- if irconfig_parameter.get_param('sale.order.planner.warehouse_domain'):
- domain.extend(tools.safe_eval(irconfig_parameter.get_param('sale.order.planner.warehouse_domain')))
+ # no domain, use global
+ warehouse_ids = sale_planner_warehouse_ids(self.env, self.env.user.company_id)
+ return warehouse.browse(warehouse_ids)
- return warehouse.search(domain)
-
- def get_shipping_carriers(self, carrier_id=None, domain=None):
+ def get_shipping_carriers(self, carrier_id=None, domain=None, warehouse_id=None):
Carrier = self.env['delivery.carrier'].sudo()
if carrier_id:
return Carrier.browse(carrier_id)
@@ -614,6 +616,8 @@ class SaleOrderMakePlan(models.TransientModel):
return self._find_closest_warehouse(warehouses, partner.partner_latitude, partner.partner_longitude)
def _find_closest_warehouse(self, warehouses, latitude, longitude):
+ if not warehouses:
+ return warehouses
distances = {distance(latitude, longitude, wh.partner_id.partner_latitude, wh.partner_id.partner_longitude): wh.id for wh in warehouses}
wh_id = distances[min(distances)]
return warehouses.filtered(lambda wh: wh.id == wh_id)
@@ -658,19 +662,19 @@ class SaleOrderMakePlan(models.TransientModel):
policy = line.product_id.product_tmpl_id.get_planning_policy()
if policy and policy.carrier_filter_id:
domain.extend(tools.safe_eval(policy.carrier_filter_id.domain))
- carriers = self.get_shipping_carriers(base_option.get('carrier_id'), domain=domain)
- _logger.info('generate_shipping_options:: base_optoin: ' + str(base_option) + ' order_fake: ' + str(order_fake) + ' carriers: ' + str(carriers))
+ carriers = self.get_shipping_carriers(base_option.get('carrier_id'), domain=domain, warehouse_id=base_option.get('warehouse_id'))
+ _logger.info('generate_shipping_options:: base_option: ' + str(base_option) + ' order_fake: ' + str(order_fake) + ' carriers: ' + str(carriers))
if not carriers:
- return base_option
+ return [base_option]
if not base_option.get('sub_options'):
options = []
# this locic comes from "delivery.models.sale_order.SaleOrder"
for carrier in carriers:
- option = self._generate_shipping_carrier_option(base_option, order_fake, carrier)
- if option:
- options.append(option)
+ carrier_options = self._generate_shipping_carrier_option(base_option, order_fake, carrier)
+ if carrier_options:
+ options += carrier_options
if options:
return options
return [base_option]
@@ -682,26 +686,40 @@ class SaleOrderMakePlan(models.TransientModel):
for carrier in carriers:
new_base_option = deepcopy(base_option)
has_error = False
+ found_carrier_ids = set()
for wh_id, wh_vals in base_option['sub_options'].items():
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))
- wh_option = self._generate_shipping_carrier_option(wh_vals, order_fake, carrier)
- if not wh_option:
+ wh_carrier_options = self._generate_shipping_carrier_option(wh_vals, order_fake, carrier)
+ if not wh_carrier_options:
has_error = True
else:
- new_base_option['sub_options'][wh_id] = wh_option
+ for _option in wh_carrier_options:
+ if _option.get('carrier_id'):
+ found_carrier_ids.add(_option['carrier_id'])
+ new_base_option['sub_options'][wh_id] = wh_carrier_options
if has_error:
continue
- # now that we've collected, we can roll up some details.
- new_base_option['carrier_id'] = carrier.id
- new_base_option['shipping_price'] = self._get_shipping_price_for_options(new_base_option['sub_options'])
- new_base_option['requested_date'] = self._get_max_requested_date(new_base_option['sub_options'])
- new_base_option['transit_days'] = self._get_max_transit_days(new_base_option['sub_options'])
- options.append(new_base_option)
+ # now that we've collected details for this carrier, we likely have more than one carrier's rates
+ _logger.info(' from ' + str(carrier) + ' found ' + str(found_carrier_ids))
+ for carrier_id in found_carrier_ids:
+ carrier_option = deepcopy(base_option)
+ carrier_option['carrier_id'] = False
+ for wh_id, wh_vals in base_option['sub_options'].items():
+ for co in new_base_option['sub_options'].get(wh_id, []):
+ if co.get('carrier_id') == carrier_id:
+ # we have found the rate!
+ carrier_option['carrier_id'] = carrier_id
+ carrier_option['sub_options'][wh_id] = co
+ if carrier_option['carrier_id']:
+ carrier_option['shipping_price'] = self._get_shipping_price_for_options(carrier_option['sub_options'])
+ carrier_option['requested_date'] = self._get_max_requested_date(carrier_option['sub_options'])
+ carrier_option['transit_days'] = self._get_max_transit_days(carrier_option['sub_options'])
+ options.append(carrier_option)
#restore values in case more processing occurs
order_fake.warehouse_id = original_order_fake_warehouse_id
@@ -730,6 +748,8 @@ class SaleOrderMakePlan(models.TransientModel):
def _generate_shipping_carrier_option(self, base_option, order_fake, carrier):
# some carriers look at the order carrier_id
order_fake.carrier_id = carrier
+ date_planned = base_option.get('date_planned')
+ order_fake.date_planned = date_planned
# this logic comes from "delivery.models.sale_order.SaleOrder"
try:
@@ -737,7 +757,9 @@ class SaleOrderMakePlan(models.TransientModel):
date_delivered = None
transit_days = 0
if carrier.delivery_type not in ['fixed', 'base_on_rule']:
- if hasattr(carrier, 'rate_shipment_date_planned'):
+ if hasattr(carrier, 'rate_shipment_multi'):
+ result = carrier.rate_shipment_multi(order=order_fake)
+ elif hasattr(carrier, 'rate_shipment_date_planned'):
# New API
result = carrier.rate_shipment_date_planned(order_fake, base_option.get('date_planned'))
if result:
@@ -747,7 +769,8 @@ class SaleOrderMakePlan(models.TransientModel):
elif hasattr(carrier, 'get_shipping_price_for_plan'):
# Old API
result = carrier.get_shipping_price_for_plan(order_fake, base_option.get('date_planned'))
- if result and isinstance(result, list):
+ if result and isinstance(result, list) and not isinstance(result[0], dict):
+ # this detects the above only if it isn't a list of dictionaries (aka multi-rating result)
price_unit, transit_days, date_delivered = result[0]
elif not result:
rate = carrier.rate_shipment(order_fake)
@@ -769,13 +792,38 @@ class SaleOrderMakePlan(models.TransientModel):
if order_fake.company_id.currency_id.id != order_fake.pricelist_id.currency_id.id:
price_unit = order_fake.company_id.currency_id.with_context(date=order_fake.date_order).compute(price_unit, order_fake.pricelist_id.currency_id)
- final_price = float(price_unit) * (1.0 + (float(carrier.margin) / 100.0))
- option = deepcopy(base_option)
- option['carrier_id'] = carrier.id
- option['shipping_price'] = final_price
- option['requested_date'] = date_delivered
- option['transit_days'] = transit_days
- return option
+ if result and isinstance(result, list):
+ res = []
+ for rate in result:
+ rate_carrier = rate.get('carrier')
+ if not rate_carrier:
+ continue
+ price_unit = rate['price']
+ date_delivered = rate.get('date_delivered')
+ transit_days = rate.get('transit_days')
+
+ if date_planned and transit_days and not date_delivered:
+ # compute from planned date anc current rate carrier
+ date_delivered = rate_carrier.calculate_date_delivered(date_planned, transit_days)
+ elif date_planned and date_delivered and not transit_days:
+ transit_days = rate_carrier.calculate_transit_days(date_planned, date_delivered)
+
+ final_price = float(price_unit) * (1.0 + (float(rate_carrier.margin) / 100.0))
+ option = deepcopy(base_option)
+ option['carrier_id'] = rate_carrier.id
+ option['shipping_price'] = final_price
+ option['requested_date'] = fields.Datetime.to_string(date_delivered) if (date_delivered and isinstance(date_delivered, datetime)) else date_delivered
+ option['transit_days'] = transit_days
+ res.append(option)
+ return res
+ else:
+ final_price = float(price_unit) * (1.0 + (float(carrier.margin) / 100.0))
+ option = deepcopy(base_option)
+ option['carrier_id'] = carrier.id
+ option['shipping_price'] = final_price
+ option['requested_date'] = fields.Datetime.to_string(date_delivered) if (date_delivered and isinstance(date_delivered, datetime)) else date_delivered
+ option['transit_days'] = transit_days
+ return option
except Exception as e:
_logger.info("Exception collecting carrier rates: " + str(e))
# Want to see more?
diff --git a/stock_delivery_planner/models/stock.py b/stock_delivery_planner/models/stock.py
index 3f7fd6ea..0cb10dce 100644
--- a/stock_delivery_planner/models/stock.py
+++ b/stock_delivery_planner/models/stock.py
@@ -48,3 +48,12 @@ class StockPicking(models.Model):
domain.extend(tools.safe_eval(irconfig_parameter.get_param('sale.order.planner.carrier_domain')))
return Carrier.search(domain)
+
+
+class Warehouse(models.Model):
+ _inherit = 'stock.warehouse'
+
+ delivery_planner_carrier_ids = fields.Many2many('delivery.carrier',
+ relation='delivery_planner_carrier_wh_rel',
+ string='Delivery Planner Base Carriers',
+ help='Overrides the global carriers.')
diff --git a/stock_delivery_planner/views/res_config_settings_views.xml b/stock_delivery_planner/views/res_config_settings_views.xml
index bc8f2557..c6645fc7 100644
--- a/stock_delivery_planner/views/res_config_settings_views.xml
+++ b/stock_delivery_planner/views/res_config_settings_views.xml
@@ -18,7 +18,7 @@
For example, you should add 1 FedEx carrier here and let us build up the
rates for your other FedEx shipping methods.
-
+
diff --git a/stock_delivery_planner/views/stock_views.xml b/stock_delivery_planner/views/stock_views.xml
index a65334dd..137477e2 100644
--- a/stock_delivery_planner/views/stock_views.xml
+++ b/stock_delivery_planner/views/stock_views.xml
@@ -1,5 +1,6 @@
+
stock.picking.form.inherit.delivery.plannerstock.picking
@@ -10,4 +11,16 @@
+
+
+ stock.warehouse.delivery.carriers
+ stock.warehouse
+
+
+
+
+
+
+
+
diff --git a/stock_delivery_planner/wizard/stock_delivery_planner.py b/stock_delivery_planner/wizard/stock_delivery_planner.py
index b245f708..9f628bd5 100644
--- a/stock_delivery_planner/wizard/stock_delivery_planner.py
+++ b/stock_delivery_planner/wizard/stock_delivery_planner.py
@@ -1,7 +1,7 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from odoo import api, fields, models, _
-from odoo.tools import safe_eval
+from odoo.exceptions import UserError, ValidationError
import logging
_logger = logging.getLogger(__name__)
@@ -26,32 +26,37 @@ class StockDeliveryPlanner(models.TransientModel):
def create(self, values):
planner = super(StockDeliveryPlanner, self).create(values)
- base_carriers = self.env['delivery.carrier']
- carrier_ids = self.env['ir.config_parameter'].sudo().get_param('stock.delivery.planner.carrier_ids.%s' % (self.env.user.company_id.id, ))
- if carrier_ids:
- try:
- carrier_ids = [int(c) for c in carrier_ids.split(',')]
- base_carriers = base_carriers.browse(carrier_ids)
- except:
- pass
+ base_carriers = planner.picking_id.picking_type_id.warehouse_id.delivery_planner_carrier_ids
+ if not base_carriers:
+ carrier_ids = self.env['ir.config_parameter'].sudo().get_param('stock.delivery.planner.carrier_ids.%s' % (self.env.user.company_id.id, ))
+ if carrier_ids:
+ try:
+ carrier_ids = [int(c) for c in carrier_ids.split(',')]
+ base_carriers = base_carriers.browse(carrier_ids)
+ except:
+ pass
+ base_carriers = base_carriers.sudo()
for carrier in base_carriers:
- rates = carrier.rate_shipment_multi(picking=planner.picking_id)
- for rate in filter(lambda r: not r.get('success'), rates):
- _logger.warning(rate.get('error_message'))
- for rate in filter(lambda r: r.get('success'), rates):
- rate = self.calculate_delivery_window(rate)
- # added late in API dev cycle
- package = rate.get('package') or self.env['stock.quant.package'].browse()
- planner.plan_option_ids |= planner.plan_option_ids.create({
- 'plan_id': self.id,
- 'carrier_id': rate['carrier'].id,
- 'package_id': package.id,
- 'price': rate['price'],
- 'date_planned': rate['date_planned'],
- 'requested_date': rate['date_delivered'],
- 'transit_days': rate['transit_days'],
- })
+ try:
+ rates = carrier.rate_shipment_multi(picking=planner.picking_id)
+ for rate in filter(lambda r: not r.get('success'), rates):
+ _logger.warning(rate.get('error_message'))
+ for rate in filter(lambda r: r.get('success'), rates):
+ rate = self.calculate_delivery_window(rate)
+ # added late in API dev cycle
+ package = rate.get('package') or self.env['stock.quant.package'].browse()
+ planner.plan_option_ids |= planner.plan_option_ids.create({
+ 'plan_id': self.id,
+ 'carrier_id': rate['carrier'].id,
+ 'package_id': package.id,
+ 'price': rate['price'],
+ 'date_planned': rate['date_planned'],
+ 'requested_date': rate.get('date_delivered', False),
+ 'transit_days': rate.get('transit_days', 0),
+ })
+ except (UserError, ValidationError) as e:
+ _logger.warning('Exception during delivery planning. %s' % str(e))
return planner
@api.model
diff --git a/stock_delivery_planner/wizard/stock_delivery_planner_views.xml b/stock_delivery_planner/wizard/stock_delivery_planner_views.xml
index ac373043..06e9ac5c 100644
--- a/stock_delivery_planner/wizard/stock_delivery_planner_views.xml
+++ b/stock_delivery_planner/wizard/stock_delivery_planner_views.xml
@@ -11,6 +11,7 @@