From ef3bbc9293bed881a1e7c99fed431ad2ee4a9f6b Mon Sep 17 00:00:00 2001 From: LSE Date: Mon, 26 Dec 2022 17:23:55 +0000 Subject: [PATCH] [FIX] delivery: add commodities for packages from order Before this commit: 1. Set up an EasyPost shipment setup, using "Canada Post" as the Carrier Type and "XpresspostUSA" as the Default Service Level. 2. Create a SO with a US customer (like Deco Addict) 3. "Add Shipping" using the button and choose the one created in 1. 4. When you try to "Get Rate" using the EasyPost shipment, the API does always return the same error: ``` Easypost returned an error: Unable to proceed, 'customs_info' is required for international shipments, shipments bound for US military bases, or US territories. Please see https://www.easypost.com/docs/api#customs for more information. ``` After this commit: As no commodities were set, `_customs_info` will return an empty dictionary. To solve that, we set the `DeliveryPackage` commodity value on its initialisation to compute the customs information the way it should. opw-3104305 closes odoo/odoo#112988 X-original-commit: 06beca4373743787ae629b2c7ea623bf0583727a Signed-off-by: Arnold Moyaux (arm) --- addons/delivery/models/delivery_carrier.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/delivery/models/delivery_carrier.py b/addons/delivery/models/delivery_carrier.py index 930ee851145..957bbf96d05 100644 --- a/addons/delivery/models/delivery_carrier.py +++ b/addons/delivery/models/delivery_carrier.py @@ -463,8 +463,15 @@ class DeliveryCarrier(models.Model): package_weights = [max_weight] * total_full_packages + ([last_package_weight] if last_package_weight else []) partial_cost = total_cost / len(package_weights) # separate the cost uniformly + order_commodities = self._get_commodities_from_order(order) + + # Split the commodities value uniformly as well + for commodity in order_commodities: + commodity.monetary_value /= len(package_weights) + commodity.qty = max(1, commodity.qty // len(package_weights)) + for weight in package_weights: - packages.append(DeliveryPackage(None, weight, default_package_type, total_cost=partial_cost, currency=order.company_id.currency_id, order=order)) + packages.append(DeliveryPackage(order_commodities, weight, default_package_type, total_cost=partial_cost, currency=order.company_id.currency_id, order=order)) return packages def _get_packages_from_picking(self, picking, default_package_type):