[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#118348 X-original-commit: ecf0262e3ef746c33a29c4f2de7868e3ab61cce2 Signed-off-by: Tiffany Chang <tic@odoo.com>
This commit is contained in:
@@ -147,6 +147,6 @@ class SaleOrder(models.Model):
|
||||
if self.delivery_set:
|
||||
return self.shipping_weight
|
||||
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
|
||||
|
||||
@@ -16,7 +16,7 @@ class TestDeliveryCost(common.TransactionCase):
|
||||
self.Product = self.env['product.product']
|
||||
|
||||
self.partner_18 = self.env['res.partner'].create({'name': 'My Test Customer'})
|
||||
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',
|
||||
@@ -37,7 +37,7 @@ class TestDeliveryCost(common.TransactionCase):
|
||||
})
|
||||
self.product_uom_hour = self.env.ref('uom.product_uom_hour')
|
||||
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
|
||||
@@ -296,3 +296,26 @@ class TestDeliveryCost(common.TransactionCase):
|
||||
])
|
||||
|
||||
self.assertRecordValues(line, [{'price_subtotal': 9.09, 'price_total': 10.45}])
|
||||
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user