[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 <tic@odoo.com>
Signed-off-by: Khanalizadeh Ahmad (khah) <khah@odoo.com>
This commit is contained in:
Ahmad Khanalizadeh
2023-04-03 22:55:48 +02:00
parent 915dcda565
commit 861db8a5a7
@@ -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