summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addons/survey/models/survey_survey.py7
-rw-r--r--addons/survey/tests/test_certification_badge.py16
2 files changed, 23 insertions, 0 deletions
diff --git a/addons/survey/models/survey_survey.py b/addons/survey/models/survey_survey.py
index c08f13339ba..5d8a297363e 100644
--- a/addons/survey/models/survey_survey.py
+++ b/addons/survey/models/survey_survey.py
@@ -328,6 +328,12 @@ class Survey(models.Model):
default = dict(default or {}, title=title)
return super(Survey, self).copy_data(default)
+ def toggle_active(self):
+ super(Survey, self).toggle_active()
+ activated = self.filtered(lambda survey: survey.active)
+ activated.mapped('certification_badge_id').action_unarchive()
+ (self - activated).mapped('certification_badge_id').action_archive()
+
# ------------------------------------------------------------
# ANSWER MANAGEMENT
# ------------------------------------------------------------
@@ -946,6 +952,7 @@ class Survey(models.Model):
# ------------------------------------------------------------
# GAMIFICATION / BADGES
# ------------------------------------------------------------
+
def _prepare_challenge_category(self):
return 'certification'
diff --git a/addons/survey/tests/test_certification_badge.py b/addons/survey/tests/test_certification_badge.py
index 2b7348be427..df31c5e68d9 100644
--- a/addons/survey/tests/test_certification_badge.py
+++ b/addons/survey/tests/test_certification_badge.py
@@ -8,6 +8,7 @@ from odoo.tools import mute_logger
class TestCertificationBadge(common.TestSurveyCommon):
+
def setUp(self):
super(TestCertificationBadge, self).setUp()
self.certification_survey = self.env['survey.survey'].with_user(self.survey_manager).create({
@@ -49,6 +50,21 @@ class TestCertificationBadge(common.TestSurveyCommon):
'level': None,
})
+ def test_archive(self):
+ """ Archive status of survey is propagated to its badges. """
+ self.certification_survey.write({
+ 'certification_give_badge': True,
+ 'certification_badge_id': self.certification_badge.id
+ })
+
+ self.certification_survey.action_archive()
+ self.assertFalse(self.certification_survey.active)
+ self.assertFalse(self.certification_badge.active)
+
+ self.certification_survey.action_unarchive()
+ self.assertTrue(self.certification_survey.active)
+ self.assertTrue(self.certification_badge.active)
+
def test_give_badge_without_badge(self):
with mute_logger('odoo.sql_db'):
with self.assertRaises(IntegrityError):