[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) <arm@odoo.com>
This commit is contained in:
LSE
2023-02-21 15:53:11 +01:00
committed by Loan (LSE)
parent 5126c9b1d4
commit ef3bbc9293
+8 -1
View File
@@ -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):