diff --git a/addons/loyalty/models/loyalty_program.py b/addons/loyalty/models/loyalty_program.py index d17f9057854..5a936d7ef57 100644 --- a/addons/loyalty/models/loyalty_program.py +++ b/addons/loyalty/models/loyalty_program.py @@ -372,13 +372,14 @@ class LoyaltyProgram(models.Model): raise UserError(_('You can not delete a program in an active state')) def toggle_active(self): - super().toggle_active() + res = super().toggle_active() # Propagate active state to children - for program in self: + for program in self.with_context(active_test=False): program.rule_ids.active = program.active program.reward_ids.active = program.active program.communication_plan_ids.active = program.active - program.reward_ids.discount_line_product_id.active = program.active + program.reward_ids.with_context(active_test=True).discount_line_product_id.active = program.active + return res def write(self, vals): # There is an issue when we change the program type, since we clear the rewards and create new ones. diff --git a/addons/loyalty/tests/test_loyalty.py b/addons/loyalty/tests/test_loyalty.py index eb1b566aa76..e3b5d791c3a 100644 --- a/addons/loyalty/tests/test_loyalty.py +++ b/addons/loyalty/tests/test_loyalty.py @@ -111,3 +111,17 @@ class TestLoyalty(TransactionCase): ], }) self.assertTrue(all(r.reward_type == 'product' for r in self.program.reward_ids)) + + def test_archiving_unarchiving(self): + self.program.write({ + 'reward_ids': [ + Command.create({ + 'description': 'Test Product', + }), + ], + }) + before_archived_reward_ids = self.program.reward_ids + self.program.toggle_active() + self.program.toggle_active() + after_archived_reward_ids = self.program.reward_ids + self.assertEqual(before_archived_reward_ids, after_archived_reward_ids)