From d34f7d38d82ffcfc84fd2f4dd4cc1e5071012b62 Mon Sep 17 00:00:00 2001 From: Florian Damhaut Date: Thu, 17 Mar 2022 14:52:58 +0000 Subject: [PATCH] [FIX] sale_management: options_lines have correct discount Step to reproduce: - Create a pricelist with 20% discount and Show discount to the user - In a SO with public pricelist, add option line OL - Change pricelist to the one created earlier Current behaviour: - OL unit price is 80% of list price - OL discount is 0% Behaviour after PR: - OL unit price is 100% of list price - OL discount is 20% opw-2761252 closes odoo/odoo#87640 X-original-commit: 0d4293da09821016d9db56ec1f36fbeff3bf8ef2 Signed-off-by: Damhaut Florian (flda) Signed-off-by: Victor Feyens (vfe) --- .../sale_management/tests/test_sale_order.py | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/addons/sale_management/tests/test_sale_order.py b/addons/sale_management/tests/test_sale_order.py index c18dedf0a90..7fa30cd2906 100644 --- a/addons/sale_management/tests/test_sale_order.py +++ b/addons/sale_management/tests/test_sale_order.py @@ -280,3 +280,61 @@ class TestSaleOrder(TestSaleCommon): "If a pricelist is set without discount included, the discount " "shall be computed according to the price unit and the subtotal." "price") + + def test_04_update_pricelist_option_line(self): + """ + This test checks that option line's values are correctly + updated after a pricelist update + """ + + # Necessary for _onchange_discount() check + self.env.user.write({ + 'groups_id': [(4, self.env.ref('product.group_discount_per_so_line').id)], + }) + + self.sale_order.write({ + 'sale_order_template_id': self.quotation_template_no_discount.id + }) + self.sale_order._onchange_sale_order_template_id() + + self.assertEqual( + self.sale_order.sale_order_option_ids[0].price_unit, + self.pub_option_price, + "If no pricelist is set, the unit price shall be the option's product price.") + + self.assertEqual( + self.sale_order.sale_order_option_ids[0].discount, 0, + "If no pricelist is set, the discount should be 0.") + + self.sale_order.write({ + 'pricelist_id': self.discount_included_price_list.id, + }) + self.sale_order.update_prices() + + self.assertEqual( + self.sale_order.sale_order_option_ids[0].price_unit, + self.pl_option_price, + "If a pricelist is set with discount included," + " the unit price shall be the option's product discounted price.") + + self.assertEqual( + self.sale_order.sale_order_option_ids[0].discount, 0, + "If a pricelist is set with discount included," + " the discount should be 0.") + + self.sale_order.write({ + 'pricelist_id': self.discount_excluded_price_list.id, + }) + self.sale_order.update_prices() + + self.assertEqual( + self.sale_order.sale_order_option_ids[0].price_unit, + self.pub_option_price, + "If a pricelist is set without discount included," + " the unit price shall be the option's product sale price.") + + self.assertEqual( + self.sale_order.sale_order_option_ids[0].discount, + self.pl_option_discount, + "If a pricelist is set without discount included," + " the discount should be correctly computed.")