[FIX] delivery: avoid a traceback when calculating the shipping cost

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) <whe@odoo.com>
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
This commit is contained in:
Touati Djamel (otd)
2022-12-01 13:31:02 +01:00
parent 8a170ddf2c
commit 42f9a2c2da
+1 -1
View File
@@ -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))