Skip to content
Snippets Groups Projects
Commit c18064d7 authored by Touati Djamel (otd)'s avatar Touati Djamel (otd)
Browse files

[FIX] delivery: raise a UserError if the total weight is 0

Steps to reproduce the bug:
- Install `delivery_dhl`
- Create a storable product “P1”:
    - make sure the weight of the product is equal to 0
- create a transfert:
    - Type: delivery orders
    - Add the product “P1”
    - Go to “Additional info” tab and select “DHL” in the carrier field
    - Mark as Todo
    - Validate

Problem:
A traceback is triggered, because in order to set the shipment details,
a package should be created, so the `_get_packages_from_picking`
function is called:
https://github.com/odoo/enterprise/blob/aed802ee17dba5ebe12b42594503732a2662be68/delivery_dhl/models/dhl_request.py#L166

But as the total weight of the products is equal to 0, the package is
not created:

https://github.com/odoo/odoo/blob/6b0ab28791f4a29254d294f8a116545d4c124e8b/addons/delivery/models/delivery_carrier.py#L324-L325

then, the result is used without checking if the package has been
created:
https://github.com/odoo/enterprise/blob/aed802ee17dba5ebe12b42594503732a2662be68/delivery_dhl/models/dhl_request.py#L185



Solution:
If the total products weight is equal to 0, raise a UserError

opw-3076826
opw-3075562

closes odoo/odoo#106809

Signed-off-by: default avatarWilliam Henrotin (whe) <whe@odoo.com>
parent f173300f
No related branches found
No related tags found
No related merge requests found
......@@ -982,6 +982,15 @@ msgstr ""
msgid "The Poste"
msgstr ""
#. module: delivery
#. odoo-python
#: 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"
" picking is 0.0 %s"
msgstr ""
#. module: delivery
#: model:ir.model.fields,help:delivery.field_delivery_carrier__get_return_label_from_portal
msgid ""
......
......@@ -5,6 +5,7 @@ import psycopg2
from odoo import api, fields, models, registry, SUPERUSER_ID, _
from odoo.tools.float_utils import float_round
from odoo.exceptions import UserError
from .delivery_request_objects import DeliveryCommodity, DeliveryPackage
......@@ -361,6 +362,8 @@ class DeliveryCarrier(models.Model):
for move_line in picking.move_line_ids:
package_total_cost += self._product_price_to_company_currency(move_line.qty_done, move_line.product_id, picking.company_id)
packages.append(DeliveryPackage(commodities, picking.weight_bulk, default_package_type, name='Bulk Content', total_cost=package_total_cost, currency=picking.company_id.currency_id, picking=picking))
elif not packages:
raise UserError(_("The package cannot be created because the total weight of the products in the picking is 0.0 %s") % (picking.weight_uom_name))
return packages
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment