[FIX] website_slides: do not crash when deleting a slide
Steps to reproduce: - Install the elearning module and go to a course not created by you. - Try to delete or add any slide. Note: the bug is not consistent it might happen for some courses and not for others. Issue: We get a traceback error when trying to modify anything about the slides in this course. Solution: Adding the `'channel_id.slide_ids.slide_ids'` dependece to the `_compute_category_id` will make the computation to take into account the changes on the slides. opw-3316697 closes odoo/odoo#128022 X-original-commit: 1d6f8f4c606ddb7f57acd7ef2a9f983d7de84a34 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user