mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[IMP] delivery_gso: mechansims for per-package rating and shipping
This commit is contained in:
@@ -1 +1,3 @@
|
|||||||
|
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
'name': 'Golden State Overnight (gso.com) Shipping',
|
'name': 'Golden State Overnight (gso.com) Shipping',
|
||||||
'summary': 'Send your shippings through gso.com and track them online.',
|
'summary': 'Send your shippings through gso.com and track them online.',
|
||||||
'version': '14.0.1.0.0',
|
'version': '14.0.1.1.0',
|
||||||
'author': "Hibou Corp.",
|
'author': "Hibou Corp.",
|
||||||
'category': 'Warehouse',
|
'category': 'Warehouse',
|
||||||
'license': 'AGPL-3',
|
'license': 'OPL-1',
|
||||||
'images': [],
|
'images': [],
|
||||||
'website': "https://hibou.io",
|
'website': "https://hibou.io",
|
||||||
'description': """
|
'description': """
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
|
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||||
|
|
||||||
from . import delivery_gso
|
from . import delivery_gso
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
from math import ceil
|
from math import ceil
|
||||||
from base64 import b64decode
|
from base64 import b64decode
|
||||||
@@ -198,9 +200,15 @@ class ProviderGSO(models.Model):
|
|||||||
'thermal': [],
|
'thermal': [],
|
||||||
'paper': [],
|
'paper': [],
|
||||||
}
|
}
|
||||||
if picking.package_ids:
|
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 picking_packages:
|
||||||
# Every package will be a transaction
|
# Every package will be a transaction
|
||||||
for package in picking.package_ids:
|
for package in picking_packages:
|
||||||
request_body['Shipment']['Weight'] = self._gso_convert_weight(package.shipping_weight)
|
request_body['Shipment']['Weight'] = self._gso_convert_weight(package.shipping_weight)
|
||||||
request_body['Shipment'].update(self._gso_get_package_dimensions(package))
|
request_body['Shipment'].update(self._gso_get_package_dimensions(package))
|
||||||
request_body['Shipment']['ShipmentReference'] = package.name
|
request_body['Shipment']['ShipmentReference'] = package.name
|
||||||
@@ -217,7 +225,8 @@ class ProviderGSO(models.Model):
|
|||||||
cost += response['ShipmentCharges']['TotalCharge']
|
cost += response['ShipmentCharges']['TotalCharge']
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
raise ValidationError(e)
|
raise ValidationError(e)
|
||||||
else:
|
elif not package_carriers:
|
||||||
|
# ship the whole picking
|
||||||
request_body['Shipment']['Weight'] = self._gso_convert_weight(picking.shipping_weight)
|
request_body['Shipment']['Weight'] = self._gso_convert_weight(picking.shipping_weight)
|
||||||
request_body['Shipment'].update(self._gso_get_package_dimensions())
|
request_body['Shipment'].update(self._gso_get_package_dimensions())
|
||||||
request_body['Shipment']['ShipmentReference'] = picking.name
|
request_body['Shipment']['ShipmentReference'] = picking.name
|
||||||
@@ -234,6 +243,8 @@ class ProviderGSO(models.Model):
|
|||||||
cost += response['ShipmentCharges']['TotalCharge']
|
cost += response['ShipmentCharges']['TotalCharge']
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
raise ValidationError(e)
|
raise ValidationError(e)
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
# Handle results
|
# Handle results
|
||||||
trackings = [l[0] for l in labels['thermal']] + [l[0] for l in labels['paper']]
|
trackings = [l[0] for l in labels['thermal']] + [l[0] for l in labels['paper']]
|
||||||
@@ -331,18 +342,32 @@ class ProviderGSO(models.Model):
|
|||||||
res.append('https://www.gso.com/Tracking')
|
res.append('https://www.gso.com/Tracking')
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def gso_rate_shipment_multi(self, order=None, picking=None):
|
def gso_rate_shipment_multi(self, order=None, picking=None, packages=None):
|
||||||
|
if not packages:
|
||||||
|
return self._gso_rate_shipment_multi_package(order=order, picking=picking)
|
||||||
|
else:
|
||||||
|
rates = []
|
||||||
|
for package in packages:
|
||||||
|
rates += self._gso_rate_shipment_multi_package(order=order, picking=picking, package=package)
|
||||||
|
return rates
|
||||||
|
|
||||||
|
def _gso_rate_shipment_multi_package(self, order=None, picking=None, package=None):
|
||||||
sudoself = self.sudo()
|
sudoself = self.sudo()
|
||||||
service = sudoself._get_gso_service()
|
try:
|
||||||
|
service = sudoself._get_gso_service()
|
||||||
|
except HTTPError as e:
|
||||||
|
_logger.error(e)
|
||||||
|
return [{
|
||||||
|
'success': False,
|
||||||
|
'price': 0.0,
|
||||||
|
'error_message': _('GSO web service returned an error. ' + str(e)),
|
||||||
|
'warning_message': False,
|
||||||
|
}]
|
||||||
|
|
||||||
from_ = sudoself.get_shipper_warehouse(order=order, picking=picking)
|
from_ = sudoself.get_shipper_warehouse(order=order, picking=picking)
|
||||||
to = sudoself.get_recipient(order=order, picking=picking)
|
to = sudoself.get_recipient(order=order, picking=picking)
|
||||||
address_type = 'B' if bool(to.is_company or to.parent_id.is_company) else 'R'
|
address_type = 'B' if bool(to.is_company or to.parent_id.is_company) else 'R'
|
||||||
|
package_dimensions = self._gso_get_package_dimensions(package=package)
|
||||||
if order:
|
|
||||||
est_weight_value = self._gso_convert_weight(
|
|
||||||
sum([(line.product_id.weight * line.product_uom_qty) for line in order.order_line]) or 0.0)
|
|
||||||
else:
|
|
||||||
est_weight_value = self._gso_convert_weight(picking.shipping_weight)
|
|
||||||
|
|
||||||
date_planned = fields.Datetime.now()
|
date_planned = fields.Datetime.now()
|
||||||
if self.env.context.get('date_planned'):
|
if self.env.context.get('date_planned'):
|
||||||
@@ -353,10 +378,13 @@ class ProviderGSO(models.Model):
|
|||||||
ship_date_gso = ship_date_utc.astimezone(pytz.timezone(GSO_TZ))
|
ship_date_gso = ship_date_utc.astimezone(pytz.timezone(GSO_TZ))
|
||||||
ship_date_gso = fields.Datetime.to_string(ship_date_gso)
|
ship_date_gso = fields.Datetime.to_string(ship_date_gso)
|
||||||
|
|
||||||
if picking and picking.package_ids:
|
if order:
|
||||||
package_dimensions = self._gso_get_package_dimensions(package=picking.package_ids[0])
|
est_weight_value = self._gso_convert_weight(
|
||||||
|
sum([(line.product_id.weight * line.product_uom_qty) for line in order.order_line]) or 0.0)
|
||||||
|
elif not package:
|
||||||
|
est_weight_value = self._gso_convert_weight(picking.shipping_weight)
|
||||||
else:
|
else:
|
||||||
package_dimensions = self._gso_get_package_dimensions()
|
est_weight_value = package.shipping_weight or package.weight
|
||||||
|
|
||||||
request_body = {
|
request_body = {
|
||||||
'AccountNumber': sudoself.gso_account_number,
|
'AccountNumber': sudoself.gso_account_number,
|
||||||
@@ -395,6 +423,7 @@ class ProviderGSO(models.Model):
|
|||||||
if carrier:
|
if carrier:
|
||||||
rates.append({
|
rates.append({
|
||||||
'carrier': carrier,
|
'carrier': carrier,
|
||||||
|
'package': package or self.env['stock.quant.package'].browse(),
|
||||||
'success': True,
|
'success': True,
|
||||||
'price': price,
|
'price': price,
|
||||||
'error_message': False,
|
'error_message': False,
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from json import dumps
|
from json import dumps
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user