From 3c2a42085174f0aa0c0013f60073cc2cc7d2556e Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Thu, 14 Mar 2024 13:20:29 +0100 Subject: [PATCH] [IMP] sale: discount should not be recomputed on confirmation Add test to cover a problem fixed in `sale_subscription` opw-3740645 closes odoo/odoo#157699 Related: odoo/enterprise#58673 Signed-off-by: Victor Feyens (vfe) --- addons/sale/tests/test_sale_order.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/addons/sale/tests/test_sale_order.py b/addons/sale/tests/test_sale_order.py index 85ca248ae67..8648e9c88bf 100644 --- a/addons/sale/tests/test_sale_order.py +++ b/addons/sale/tests/test_sale_order.py @@ -1,16 +1,17 @@ -# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. + from datetime import timedelta +from unittest.mock import patch + from freezegun import freeze_time from odoo import fields -from odoo.fields import Command from odoo.exceptions import AccessError, UserError, ValidationError -from odoo.tests import tagged, Form -from odoo.tools import float_compare +from odoo.fields import Command +from odoo.tests import Form, tagged -from odoo.addons.sale.tests.common import SaleCommon from odoo.addons.account.tests.common import AccountTestInvoicingCommon +from odoo.addons.sale.tests.common import SaleCommon @tagged('post_install', '-at_install') @@ -466,6 +467,16 @@ class TestSaleOrder(SaleCommon): sale_order.action_confirm() self.assertTrue(sale_order.analytic_account_id, "An analytic account should be generated") + def test_so_discount_is_not_reset(self): + """ Discounts should not be recomputed on order confirmation """ + with patch( + 'odoo.addons.sale.models.sale_order_line.SaleOrderLine' + '._compute_discount' + ) as patched: + self.sale_order.action_confirm() + self.sale_order.order_line.flush_recordset(['discount']) + patched.assert_not_called() + @tagged('post_install', '-at_install') class TestSaleOrderInvoicing(AccountTestInvoicingCommon, SaleCommon):