diff --git a/addons/website_slides/models/slide_slide.py b/addons/website_slides/models/slide_slide.py index d9fac8c5264..78296759ecc 100644 --- a/addons/website_slides/models/slide_slide.py +++ b/addons/website_slides/models/slide_slide.py @@ -267,7 +267,7 @@ class Slide(models.Model): for slide in self: slide.slide_views = mapped_data.get(slide.id, 0) - @api.depends('slide_ids.slide_type', 'slide_ids.is_published', 'slide_ids.is_category') + @api.depends('slide_ids.sequence', 'slide_ids.slide_type', 'slide_ids.is_published', 'slide_ids.is_category') def _compute_slides_statistics(self): # Do not use dict.fromkeys(self.ids, dict()) otherwise it will use the same dictionnary for all keys. # Therefore, when updating the dict of one key, it updates the dict of all keys. diff --git a/addons/website_slides/tests/test_statistics.py b/addons/website_slides/tests/test_statistics.py index 3d94a8ed596..ae5c406f361 100644 --- a/addons/website_slides/tests/test_statistics.py +++ b/addons/website_slides/tests/test_statistics.py @@ -164,3 +164,18 @@ class TestSlideStatistics(common.SlidesCase): self.assertEqual( category.nbr_document, len(category.channel_id.slide_ids.filtered(lambda s: s.category_id == category and s.slide_type == 'document'))) + + self.assertEqual(category.total_slides, 2, 'The first category should contain 2 slides') + other_category = self.env['slide.slide'].with_user(self.user_publisher).create({ + 'name': 'Other Category', + 'channel_id': self.channel.id, + 'is_category': True, + 'is_published': True, + 'sequence': 5, + }) + self.assertEqual(other_category.total_slides, 0, 'The other category should not contain any slide yet') + + # move one of the slide to the other category + self.slide_3.write({'sequence': 6}) + self.assertEqual(category.total_slides, 1, 'The first category should contain 1 slide') + self.assertEqual(other_category.total_slides, 1, 'The other category should contain 1 slide')