From f8cac8d38424ffb15e65e3b1894634e0642883c8 Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Thu, 16 Feb 2023 14:59:16 +0000 Subject: [PATCH] [FIX] delivery: wrong delivery price for real cost in so MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Install FedEx delivery - Go to the shipping method > FedEx: - Select Real cost and margin on rate 10% - Create a storable Product “P1” and update its qty - Create a SO: - Add the product “P1” - Click on add shipping - Select FedEx and get the rate - Imagine the price is $10 and with margin it's $11 - Confirm the SO and process the delivery Probelm: The shipping price will be $12 instead of $11 in the SO Because the estimated price is calculated the first time with margin and added in the picking when sending to the shipper: https://github.com/odoo/odoo/blob/afed7db30042e2ea91cdae292dadb7b6f742e33d/addons/delivery/models/stock_picking.py#L226 Then, the delivery cost is added to the SO, but the margin is applied a second time: https://github.com/odoo/odoo/blob/afed7db30042e2ea91cdae292dadb7b6f742e33d/addons/delivery/models/stock_picking.py#L246 https://github.com/odoo/odoo/blob/afed7db30042e2ea91cdae292dadb7b6f742e33d/addons/delivery/models/stock_picking.py#L262 so this commit is useless: https://github.com/odoo/odoo/commit/632767d83e0f42acc5b486bde02dd1d9c2533911 because the `_add_delivery_cost_to_so` function is called only when sending to the shipper opw-3184482 closes odoo/odoo#113064 X-original-commit: b8c4fcbc1cba369dce8296b800565dfd181957a4 Signed-off-by: William Henrotin (whe) Signed-off-by: Djamel Touati (otd) --- addons/delivery/models/stock_picking.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/delivery/models/stock_picking.py b/addons/delivery/models/stock_picking.py index 30fec3eb0ac..c3842eb2d58 100644 --- a/addons/delivery/models/stock_picking.py +++ b/addons/delivery/models/stock_picking.py @@ -213,13 +213,12 @@ class StockPicking(models.Model): sale_order = self.sale_id if sale_order and self.carrier_id.invoice_policy == 'real' and self.carrier_price: delivery_lines = sale_order.order_line.filtered(lambda l: l.is_delivery and l.currency_id.is_zero(l.price_unit) and l.product_id == self.carrier_id.product_id) - carrier_price = self.carrier_price * (1.0 + (float(self.carrier_id.margin) / 100.0)) if not delivery_lines: - sale_order._create_delivery_line(self.carrier_id, carrier_price) + sale_order._create_delivery_line(self.carrier_id, self.carrier_price) else: delivery_line = delivery_lines[0] delivery_line[0].write({ - 'price_unit': carrier_price, + 'price_unit': self.carrier_price, # remove the estimated price from the description 'name': self.carrier_id.with_context(lang=self.partner_id.lang).name, })