From 861db8a5a766460bf6d37e36c0cec0af791a2abe Mon Sep 17 00:00:00 2001 From: Ahmad Khanalizadeh Date: Tue, 21 Mar 2023 15:12:17 +0000 Subject: [PATCH] [FIX] delivery: use correct unit price for commodities Steps to reproduce: Make a sale order with a product and quantity > 1, add FedEx international shipping and validate the delivery In the document you will see that the unit cost is equal to subtotal which is wrong. There is a discrepancy between `_get_commodities_from_order` and `_get_commodities_from_stock_move_lines`, that the former makes commodities with `monetary_value` equal to the unit price, while the latter uses subtotal. in the method `commodities` in `delivery_fedex`, `monetary_value` is treated as unit price, so the right way to fix it is to do it in `_get_commodities_from_stock_move_lines`. Note that when rating a delivery, commodities are made in `_get_commodities_from_order` and then passed to `commodities`, while for sending the shipping, commodities are made in `_get_commodities_from_stock_move_lines`. opw-3233369 closes odoo/odoo#117521 X-original-commit: 3beddbdd18937e1c69ec4fa6f523296c7c55528b Related: odoo/enterprise#39234 Signed-off-by: Tiffany Chang Signed-off-by: Khanalizadeh Ahmad (khah) --- addons/stock_delivery/models/delivery_carrier.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/stock_delivery/models/delivery_carrier.py b/addons/stock_delivery/models/delivery_carrier.py index cfebcac0183..f4d108445e2 100644 --- a/addons/stock_delivery/models/delivery_carrier.py +++ b/addons/stock_delivery/models/delivery_carrier.py @@ -210,8 +210,8 @@ class DeliveryCarrier(models.Model): for line in lines) rounded_qty = max(1, float_round(unit_quantity, precision_digits=0)) country_of_origin = product.country_of_origin.code or lines[0].picking_id.picking_type_id.warehouse_id.partner_id.country_id.code - sale_price = sum(line.sale_price for line in lines) - commodities.append(DeliveryCommodity(product, amount=rounded_qty, monetary_value=sale_price, country_of_origin=country_of_origin)) + unit_price = sum(line.sale_price for line in lines) / rounded_qty + commodities.append(DeliveryCommodity(product, amount=rounded_qty, monetary_value=unit_price, country_of_origin=country_of_origin)) return commodities