summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-02-28 13:42:30 +0000
committerThibault Delavallée <tde@odoo.com>2020-04-03 12:59:28 +0000
commitbea9bc3d6c51bfc1c4eaad2378caba83b7a5142a (patch)
treef96cc8c9b1cdce0823e95078b0b46cbea534ecc7
parent9b76c6b7f1eec4057289de90d62b8a7a266b0aac (diff)
[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
-rw-r--r--addons/mail/models/mail_blacklist.py4
-rw-r--r--addons/mass_mailing/models/mailing_list.py2
-rw-r--r--addons/phone_validation/models/phone_blacklist.py4
-rw-r--r--addons/survey/models/survey_survey.py7
4 files changed, 8 insertions, 9 deletions
diff --git a/addons/mail/models/mail_blacklist.py b/addons/mail/models/mail_blacklist.py
index b2d27238a2c..4c686c2a045 100644
--- a/addons/mail/models/mail_blacklist.py
+++ b/addons/mail/models/mail_blacklist.py
@@ -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
diff --git a/addons/mass_mailing/models/mailing_list.py b/addons/mass_mailing/models/mailing_list.py
index b10d7cab06e..57173bdbdfb 100644
--- a/addons/mass_mailing/models/mailing_list.py
+++ b/addons/mass_mailing/models/mailing_list.py
@@ -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'}
diff --git a/addons/phone_validation/models/phone_blacklist.py b/addons/phone_validation/models/phone_blacklist.py
index 3fd1c4b4bcc..17f59b7fc38 100644
--- a/addons/phone_validation/models/phone_blacklist.py
+++ b/addons/phone_validation/models/phone_blacklist.py
@@ -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
diff --git a/addons/survey/models/survey_survey.py b/addons/survey/models/survey_survey.py
index 60558a94924..c08f13339ba 100644
--- a/addons/survey/models/survey_survey.py
+++ b/addons/survey/models/survey_survey.py
@@ -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()