Skip to content
Snippets Groups Projects
Commit 1d9fbda1 authored by Mahdi Cheikh Rouhou (macr)'s avatar Mahdi Cheikh Rouhou (macr)
Browse files

[FIX] loyalty : unarchive archived rules and rewards


When archive a loyalty program which have somes rules and rewards and the unarchinving it will not have the rules and
rewards that it had before.

Steps to reproduce the error :
1- install sales
2- activate Discounts, Loyalty & Gift Card in sales settings
3- go to sales/products/Discount&loaylty
4- select one of the default programs and try to archive it and unarchive it after
5- you will not get the rules that it had before

The problem was in the toggle_active function of the loyalty program we try to unarchive already unarchived items because
we do ```program.rule_ids``` so it will get only active items.

opw-3299295

closes odoo/odoo#120902

Signed-off-by: default avatarMahdi Cheikh Rouhou (macr) <macr@odoo.com>
parent b00633f1
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......
......@@ -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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment