[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
This commit is contained in:
@@ -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'
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user