From 7633f963066c4962a5d722b7e755e8468b4c2b54 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Wed, 17 Oct 2018 11:17:16 +0200 Subject: [PATCH] [FIX] sale_coupon: promotion program with fixed amount Steps to reproduce the bug: - Create a promotion program P with a fixed amount discount - Set a customer tax T on the discount product generated for P - Create a SO with one line - Apply the promotion program by clicking on "Update promotions" Bug: The SO line with the discount product is generated but the tax T was missing. opw:1888484 --- models/sale_order.py | 1 + tests/test_program_numbers.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/models/sale_order.py b/models/sale_order.py index 48ea4f101fd..1c0731650e1 100644 --- a/models/sale_order.py +++ b/models/sale_order.py @@ -134,6 +134,7 @@ class SaleOrder(models.Model): 'product_uom_qty': 1.0, 'product_uom': program.discount_line_product_id.uom_id.id, 'is_reward_line': True, + 'tax_id': [(4, tax.id, False) for tax in program.discount_line_product_id.taxes_id], }] reward_dict = {} lines = self._get_paid_order_lines() diff --git a/tests/test_program_numbers.py b/tests/test_program_numbers.py index 01da22c1de4..8284cd1dad4 100644 --- a/tests/test_program_numbers.py +++ b/tests/test_program_numbers.py @@ -464,6 +464,12 @@ class TestSaleCouponProgramNumbers(TestSaleCouponCommon): 'discount_type': 'fixed_amount', 'discount_fixed_amount': 249.0, }) + self.tax_0pc_excl = self.env['account.tax'].create({ + 'name': "0% Tax excl", + 'amount_type': 'percent', + 'amount': 0, + }) + fixed_amount_program.discount_line_product_id.write({'taxes_id': [(4, self.tax_0pc_excl.id, False)]}) sol1 = self.env['sale.order.line'].create({ 'product_id': self.computerCase.id, 'name': 'Computer Case', @@ -477,6 +483,9 @@ class TestSaleCouponProgramNumbers(TestSaleCouponCommon): order.recompute_coupon_lines() self.assertEqual(order.amount_total, 176, "Fixed amount discount should be totally deduced") self.assertEqual(len(order.order_line.ids), 2, "Number of lines should be unchanged as we just recompute the reward line") + sol2 = order.order_line.filtered(lambda l: l.id != sol1.id) + self.assertEqual(len(sol2.tax_id.ids), 1, "One tax should be present on the reward line") + self.assertEqual(sol2.tax_id.id, self.tax_0pc_excl.id, "The tax should be 0% Tax excl") fixed_amount_program.write({'active': False}) # Check archived product will remove discount lines on recompute order.recompute_coupon_lines() self.assertEqual(len(order.order_line.ids), 1, "Archiving the program should remove the program reward line")