diff --git a/addons/website_slides/models/slide_slide.py b/addons/website_slides/models/slide_slide.py index 0042d0b5363..bb9b8f3aab5 100644 --- a/addons/website_slides/models/slide_slide.py +++ b/addons/website_slides/models/slide_slide.py @@ -259,7 +259,7 @@ class Slide(models.Model): def _get_placeholder_filename(self, field): return self.channel_id._get_placeholder_filename(field) - @api.depends('channel_id.slide_ids.is_category', 'channel_id.slide_ids.sequence') + @api.depends('channel_id.slide_ids.is_category', 'channel_id.slide_ids.sequence', 'channel_id.slide_ids.slide_ids') def _compute_category_id(self): """ Will take all the slides of the channel for which the index is higher than the index of this category and lower than the index of the next category. diff --git a/addons/website_slides/tests/test_slide_slide.py b/addons/website_slides/tests/test_slide_slide.py index ddadfda9b1a..efc6a6fc463 100644 --- a/addons/website_slides/tests/test_slide_slide.py +++ b/addons/website_slides/tests/test_slide_slide.py @@ -9,6 +9,42 @@ from odoo.tools import mute_logger class TestSlideInternals(slides_common.SlidesCase): + def test_compute_category_completion_time(self): + """ + Check that we properly calculate the completion time of a course without error, after deleting a slide. + """ + self.category2 = self.env['slide.slide'].with_user(self.user_officer).create({ + 'name': 'Cooking Tips For Dieting', + 'channel_id': self.channel.id, + 'is_category': True, + 'is_published': True, + 'sequence': 5, + }) + self.slide_4 = self.env['slide.slide'].with_user(self.user_officer).create({ + 'name': 'Vegan Diet', + 'channel_id': self.channel.id, + 'slide_category': 'document', + 'is_published': True, + 'completion_time': 5.0, + 'sequence': 6, + }) + self.slide_5 = self.env['slide.slide'].with_user(self.user_officer).create({ + 'name': 'Normal Diet', + 'channel_id': self.channel.id, + 'slide_category': 'document', + 'is_published': True, + 'completion_time': 1.5, + 'sequence': 7, + }) + + before_unlink = self.category2.completion_time + self.assertEqual(before_unlink, self.slide_4.completion_time + self.slide_5.completion_time) + + self.channel.slide_ids[6].sudo().unlink() + self.category2._compute_category_completion_time() + + after_unlink = self.category2.completion_time + self.assertEqual(after_unlink, self.slide_4.completion_time) @mute_logger('odoo.sql_db') @users('user_manager')