[FIX] delivery: Fix ZeroDivisionError in shipping cost calculation
A `ZeroDivisionError` traceback that occurs in `delivery/DeliveryCarrier:_get_packages_from_order` was caught by Sentry Because in this part of the function https://github.com/odoo/odoo/blob/c18064d717312287f5acba2fabeb77b2e1c01fb9/addons/delivery/models/delivery_carrier.py#L326-L335 if `total_weight === 0.0` then `total_full_packages` and `last_package_weight` will be null too. And that will cause a `ZeroDivisionError` because of `total / len([])` opw-3086602 closes odoo/odoo#107820 X-original-commit: a362e14ee62a5d9d2bcb08c4431994a96796ce1e Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
@@ -994,6 +994,7 @@ msgstr ""
|
||||
#. module: delivery
|
||||
#. odoo-python
|
||||
#: code:addons/delivery/models/delivery_carrier.py:0
|
||||
#: code:addons/delivery/models/delivery_carrier.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"The package cannot be created because the total weight of the products in the"
|
||||
|
||||
@@ -328,6 +328,9 @@ class DeliveryCarrier(models.Model):
|
||||
total_cost += self._product_price_to_company_currency(line.product_qty, line.product_id, order.company_id)
|
||||
|
||||
total_weight = order._get_estimated_weight() + default_package_type.base_weight
|
||||
if total_weight == 0.0:
|
||||
weight_uom_name = self.env['product.template']._get_weight_uom_name_from_ir_config_parameter()
|
||||
raise UserError(_("The package cannot be created because the total weight of the products in the picking is 0.0 %s") % (weight_uom_name))
|
||||
# If max weight == 0 => division by 0. If this happens, we want to have
|
||||
# more in the max weight than in the total weight, so that it only
|
||||
# creates ONE package with everything.
|
||||
|
||||
Reference in New Issue
Block a user