From 669bb4ca419ca7bb8180b9d7d440e1ddf6da996b Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Thu, 6 Feb 2020 10:39:18 +0000 Subject: [PATCH] [FIX] sale_management: No discount displayed in option products [FIRST ISSUE] Steps to reproduce the bug: - Create a pricelist PL with 50% reduction on all products. - Create a SO with PL - Add an optional product P Bug: The price is correct for P but the discount displayed was 0%. [SECOND ISSUE] Steps to reproduce the bug: - Add the option line to the order Bug: A new line was create for P in the SO with the correct price but the discount was not displayed PS: The discount field on the model sale.order.option has been implemented to add a new discount to the displayed price unit of the option. But it has not been implemented to show the discount computed with the pricelist. opw:2186470 closes odoo/odoo#45056 X-original-commit: bcb304bbad3d10ca5efc7411fff4c9efff8fa6b3 Signed-off-by: Simon Goffin (sig) --- addons/sale_management/models/sale_order.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/sale_management/models/sale_order.py b/addons/sale_management/models/sale_order.py index 54c8ab0a530..35c5eda5756 100644 --- a/addons/sale_management/models/sale_order.py +++ b/addons/sale_management/models/sale_order.py @@ -202,13 +202,14 @@ class SaleOrderOption(models.Model): if not self.product_id: return product = self.product_id.with_context(lang=self.order_id.partner_id.lang) - self.price_unit = product.list_price self.name = product.get_product_multiline_description_sale() self.uom_id = self.uom_id or product.uom_id - pricelist = self.order_id.pricelist_id - if pricelist and product: - partner_id = self.order_id.partner_id.id - self.price_unit = pricelist.with_context(uom=self.uom_id.id).get_product_price(product, self.quantity, partner_id) + # To compute the dicount a so line is created in cache + values = self._get_values_to_add_to_order() + new_sol = self.env['sale.order.line'].new(values) + new_sol._onchange_discount() + self.discount = new_sol.discount + self.price_unit = new_sol._get_display_price(product) def button_add_to_order(self): self.add_option_to_order()