[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#121710 X-original-commit: 1d9fbda1c5ec69ba83968668ddecec6a7e1421bb Signed-off-by: Mahdi Cheikh Rouhou (macr) <macr@odoo.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user