From 6cf824933f36cd8111ec61a2bb2da5bb99a2ec6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 3 Apr 2020 09:58:57 +0000 Subject: [PATCH] [IMP] survey: cascade archive of a survey to its badge Purpose of this commit is to synchronize active status of certifications to their badges. When archiving or activating a certification, its badge is also archived or activated. Task ID 2170708 Community PR odoo/odoo#46563 --- addons/survey/models/survey_survey.py | 7 +++++++ addons/survey/tests/test_certification_badge.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) 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):