From 42f9a2c2da703ef01eaa7d4815e25083d5301f4d Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Tue, 29 Nov 2022 14:09:18 +0000 Subject: [PATCH] [FIX] delivery: avoid a traceback when calculating the shipping cost MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stpes to reproduce the bug: - Install delivery_ups - Go to shipping method > UPS BE > Package type - Set the max weight to 10 kg - Create a product “P1”: - Go to inventory tab > weight: 10 kg - Create a SO: - Add the product “P1” - Add shipping - Select UPS Be - Click on get rate Problem: Traceback is triggered, because we devise a number by an empty list: https://github.com/odoo/odoo/blob/6b0ab28791f4a29254d294f8a116545d4c124e8b/addons/delivery/models/delivery_carrier.py#L301 The `last_package_weight` is the result of the modulo of the weight of all the products by the maximum weight of a package, in this case it is: 0 -> 10% 10 We then use this result to calculate the weight of the package, but parenthesis have been forgotten and therefore an empty list is returned in the case where `last_package_weight` is 0 https://github.com/odoo/odoo/blob/6b0ab28791f4a29254d294f8a116545d4c124e8b/addons/delivery/models/delivery_carrier.py#L298-L300 opw-3075295 closes odoo/odoo#106863 X-original-commit: f173300f4f24d600693ab54c8db0995723a304e9 Signed-off-by: William Henrotin (whe) Signed-off-by: Djamel Touati (otd) --- addons/delivery/models/delivery_carrier.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/delivery/models/delivery_carrier.py b/addons/delivery/models/delivery_carrier.py index 82ce99190ba..6309a2b254c 100644 --- a/addons/delivery/models/delivery_carrier.py +++ b/addons/delivery/models/delivery_carrier.py @@ -331,7 +331,7 @@ class DeliveryCarrier(models.Model): total_full_packages = int(total_weight / max_weight) last_package_weight = total_weight % max_weight - package_weights = [max_weight] * total_full_packages + [last_package_weight] if last_package_weight else [] + 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 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))