[IMP] mail, mass_mailing, phone, survey: call toggle_active / action_(un)archive when possible
Purpose of this commit is to call toggle_active or archive / unarchive methods instead of manually writing on active field. Indeed this allows to trigger business code related to archive / unarchive which is normally located in toggle_archive (called by action_archive and action_unarchive). Task ID 2170708 Community PR odoo/odoo#46563
This commit is contained in:
@@ -73,7 +73,7 @@ class MailBlackList(models.Model):
|
||||
normalized = tools.email_normalize(email)
|
||||
record = self.env["mail.blacklist"].with_context(active_test=False).search([('email', '=', normalized)])
|
||||
if len(record) > 0:
|
||||
record.write({'active': True})
|
||||
record.action_unarchive()
|
||||
else:
|
||||
record = self.create({'email': email})
|
||||
return record
|
||||
@@ -89,7 +89,7 @@ class MailBlackList(models.Model):
|
||||
normalized = tools.email_normalize(email)
|
||||
record = self.env["mail.blacklist"].with_context(active_test=False).search([('email', '=', normalized)])
|
||||
if len(record) > 0:
|
||||
record.write({'active': False})
|
||||
record.action_archive()
|
||||
else:
|
||||
record = record.create({'email': email, 'active': False})
|
||||
return record
|
||||
|
||||
@@ -129,7 +129,7 @@ class MassMailingList(models.Model):
|
||||
self.flush()
|
||||
self.invalidate_cache()
|
||||
if archive:
|
||||
(src_lists - self).write({'active': False})
|
||||
(src_lists - self).action_archive()
|
||||
|
||||
def close_dialog(self):
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
@@ -89,7 +89,7 @@ class PhoneBlackList(models.Model):
|
||||
records = self.env["phone.blacklist"].with_context(active_test=False).search([('number', 'in', numbers)])
|
||||
todo = [n for n in numbers if n not in records.mapped('number')]
|
||||
if records:
|
||||
records.write({'active': True})
|
||||
records.action_unarchive()
|
||||
if todo:
|
||||
records += self.create([{'number': n} for n in todo])
|
||||
return records
|
||||
@@ -112,7 +112,7 @@ class PhoneBlackList(models.Model):
|
||||
records = self.env["phone.blacklist"].with_context(active_test=False).search([('number', 'in', numbers)])
|
||||
todo = [n for n in numbers if n not in records.mapped('number')]
|
||||
if records:
|
||||
records.write({'active': False})
|
||||
records.action_archive()
|
||||
if todo:
|
||||
records += self.create([{'number': n, 'active': False} for n in todo])
|
||||
return records
|
||||
|
||||
@@ -983,9 +983,8 @@ class Survey(models.Model):
|
||||
def _handle_certification_badges(self, vals):
|
||||
if vals.get('certification_give_badge'):
|
||||
# If badge already set on records, reactivate the ones that are not active.
|
||||
surveys_with_badge = self.filtered(lambda survey: survey.certification_badge_id
|
||||
and not survey.certification_badge_id.active)
|
||||
surveys_with_badge.mapped('certification_badge_id').write({'active': True})
|
||||
surveys_with_badge = self.filtered(lambda survey: survey.certification_badge_id and not survey.certification_badge_id.active)
|
||||
surveys_with_badge.mapped('certification_badge_id').action_unarchive()
|
||||
# (re-)create challenge and goal
|
||||
for survey in self:
|
||||
survey._create_certification_badge_trigger()
|
||||
@@ -994,7 +993,7 @@ class Survey(models.Model):
|
||||
badges = self.mapped('certification_badge_id')
|
||||
challenges_to_delete = self.env['gamification.challenge'].search([('reward_id', 'in', badges.ids)])
|
||||
goals_to_delete = challenges_to_delete.mapped('line_ids').mapped('definition_id')
|
||||
badges.write({'active': False})
|
||||
badges.action_archive()
|
||||
# delete all challenges and goals because not needed anymore (challenge lines are deleted in cascade)
|
||||
challenges_to_delete.unlink()
|
||||
goals_to_delete.unlink()
|
||||
|
||||
Reference in New Issue
Block a user