[IMP] sale: allow batch removal of discounts
This change allows to remove discounts from all sale order lines at once, by enabling 0% discounts in the discount wizard. task-3584450 closes odoo/odoo#144244 Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
committed by
Victor Feyens
parent
d8944533e3
commit
d91be06b81
@@ -1,5 +1,6 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.fields import Command
|
||||
from odoo.tests import tagged
|
||||
|
||||
@@ -83,3 +84,26 @@ class TestSaleOrderDiscount(SaleCommon):
|
||||
all(line.discount == 50 for line in self.sale_order.order_line)
|
||||
)
|
||||
self.assertAlmostEqual(self.sale_order.amount_untaxed, so_amount*0.5)
|
||||
|
||||
self.wizard.write({'discount_percentage': -0.5})
|
||||
self.wizard.action_apply_discount()
|
||||
|
||||
self.assertTrue(
|
||||
all(line.discount == -50 for line in self.sale_order.order_line)
|
||||
)
|
||||
self.assertAlmostEqual(self.sale_order.amount_untaxed, so_amount*1.5)
|
||||
|
||||
def test_sol_discount_removal(self):
|
||||
so_amount = self.sale_order.amount_untaxed
|
||||
self.wizard.write({'discount_percentage': 0.5, 'discount_type': 'sol_discount'})
|
||||
self.wizard.action_apply_discount()
|
||||
|
||||
self.wizard.write({'discount_percentage': 0})
|
||||
self.wizard.action_apply_discount()
|
||||
|
||||
self.assertFalse(self.sale_order.order_line.filtered('discount'))
|
||||
self.assertAlmostEqual(self.sale_order.amount_untaxed, so_amount)
|
||||
|
||||
def test_percent_discount_above_100(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
self.wizard.write({'discount_percentage': 1.1, 'discount_type': 'sol_discount'})
|
||||
|
||||
@@ -30,9 +30,9 @@ class SaleOrderDiscount(models.TransientModel):
|
||||
@api.constrains('discount_type', 'discount_percentage')
|
||||
def _check_discount_amount(self):
|
||||
for wizard in self:
|
||||
if wizard.discount_type in ('sol_discount', 'so_discount') and (
|
||||
wizard.discount_percentage <= 0.0
|
||||
or wizard.discount_percentage > 1.0
|
||||
if (
|
||||
wizard.discount_type in ('sol_discount', 'so_discount')
|
||||
and wizard.discount_percentage > 1.0
|
||||
):
|
||||
raise ValidationError(_("Invalid discount amount"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user