Skip to content
Snippets Groups Projects
Commit 518c7e04 authored by kir-odoo's avatar kir-odoo
Browse files

[FIX] delivery: exclude neg qtys from shipping weight


This commit prevents inclusion of negative qty SO products from
the calculation of its estimated shipping weight. Negative qtys can
indicate a return, which would be a separate picking from the delivery
 => we shouldn't subtract their weight from the delivery. This
subtraction, may have resulted in shipping rates being calculated as
lower than they should have been within the SO.

Additionally fixes the following use case (requires Fedex connector):
- create a SO with 2 products with the same weight
- set 1st product qty = 1
- set 2nd product qty = -1
- add shipping => Shipping Method = Fedex US
- click on "Get Rate"

An error will occur because the SO._get_estimated_weight() = 0, and
you cannot have a rate for weight = 0

TaskId - 3028023

closes odoo/odoo#118164

X-original-commit: 4f5cfbd9
Signed-off-by: default avatarTiffany Chang <tic@odoo.com>
parent 4333a87f
No related branches found
No related tags found
No related merge requests found
......@@ -153,7 +153,7 @@ class SaleOrder(models.Model):
def _get_estimated_weight(self):
self.ensure_one()
weight = 0.0
for order_line in self.order_line.filtered(lambda l: l.product_id.type in ['product', 'consu'] and not l.is_delivery and not l.display_type):
for order_line in self.order_line.filtered(lambda l: l.product_id.type in ['product', 'consu'] and not l.is_delivery and not l.display_type and l.product_uom_qty > 0):
weight += order_line.product_qty * order_line.product_id.weight
return weight
......
......@@ -17,7 +17,7 @@ class TestDeliveryCost(common.TransactionCase):
self.partner_18 = self.env['res.partner'].create({'name': 'My Test Customer'})
self.pricelist = self.env.ref('product.list0')
self.product_4 = self.env['product.product'].create({'name': 'A product to deliver'})
self.product_4 = self.env['product.product'].create({'name': 'A product to deliver', 'weight': 1.0})
self.product_uom_unit = self.env.ref('uom.product_uom_unit')
self.product_delivery_normal = self.env['product.product'].create({
'name': 'Normal Delivery Charges',
......@@ -39,7 +39,7 @@ class TestDeliveryCost(common.TransactionCase):
self.product_uom_hour = self.env.ref('uom.product_uom_hour')
self.account_data = self.env.ref('account.data_account_type_revenue')
self.account_tag_operating = self.env.ref('account.account_tag_operating')
self.product_2 = self.env['product.product'].create({'name': 'Zizizaproduct'})
self.product_2 = self.env['product.product'].create({'name': 'Zizizaproduct', 'weight': 1.0})
self.product_category = self.env.ref('product.product_category_all')
self.free_delivery = self.env.ref('delivery.free_delivery_carrier')
# as the tests hereunder assume all the prices in USD, we must ensure
......@@ -381,3 +381,26 @@ class TestDeliveryCost(common.TransactionCase):
self.assertEqual(len(sale_normal_delivery_charges.order_line), 3)
self.assertEqual(sale_normal_delivery_charges.amount_untaxed, 80.0, "Delivery cost is not Added")
def test_estimated_weight(self):
"""
Test that negative qty SO lines are not included in the estimated weight calculation
of delivery carriers (since it's used when calculating their rates).
"""
sale_order = self.SaleOrder.create({
'partner_id': self.partner_18.id,
'name': 'SO - neg qty',
'order_line': [
(0, 0, {
'product_id': self.product_4.id,
'product_uom_qty': 1,
'product_uom': self.product_uom_unit.id,
}),
(0, 0, {
'product_id': self.product_2.id,
'product_uom_qty': -1,
'product_uom': self.product_uom_unit.id,
})],
})
shipping_weight = sale_order._get_estimated_weight()
self.assertEqual(shipping_weight, self.product_4.weight, "Only positive quantity products' weights should be included in estimated weight")
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