diff --git a/addons/website_slides/models/slide_slide.py b/addons/website_slides/models/slide_slide.py index a74d134205a..bbf0c122cb9 100644 --- a/addons/website_slides/models/slide_slide.py +++ b/addons/website_slides/models/slide_slide.py @@ -654,7 +654,7 @@ class Slide(models.Model): # only update keys that are not set in the incoming vals slide.update({key: value for key, value in slide_metadata.items() if key not in vals.keys()}) - if not 'completion_time' not in vals: + if 'completion_time' not in vals: slide._on_change_document_binary_content() if slide.is_published and not slide.is_category: diff --git a/addons/website_slides/tests/test_slide_channel.py b/addons/website_slides/tests/test_slide_channel.py index 8374b3cbc39..23c3e1eb2bd 100644 --- a/addons/website_slides/tests/test_slide_channel.py +++ b/addons/website_slides/tests/test_slide_channel.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. - from odoo.addons.website_slides.tests import common as slides_common from odoo.exceptions import UserError from odoo.tests.common import users +from unittest.mock import patch class TestSlidesManagement(slides_common.SlidesCase): @@ -241,6 +241,38 @@ class TestSlidesManagement(slides_common.SlidesCase): self.assertFalse(self.channel.exists(), "Should have deleted channel along with the slides even if there are slides with quiz and participant(s)") + def test_default_completion_time(self): + """Verify whether the system calculates the completion time when it is not specified, + but if the user does provide a completion time, the default time should not be applied.""" + + def _get_completion_time_pdf(*args, **kwargs): + return 13.37 + + with patch( + 'odoo.addons.website_slides.models.slide_slide.Slide._get_completion_time_pdf', + new=_get_completion_time_pdf + ): + slides_1 = self.env['slide.slide'].create({ + 'name': 'Test_Content', + 'slide_category': 'document', + 'is_published': True, + 'is_preview': True, + 'document_binary_content': 'c3Rk', + 'channel_id': self.channel.id, + }) + + slides_2 = self.env['slide.slide'].create({ + 'name': 'Test_Content', + 'slide_category': 'document', + 'is_published': True, + 'is_preview': True, + 'document_binary_content': 'c3Rk', + 'channel_id': self.channel.id, + 'completion_time': 123, + }) + + self.assertEqual(13.37, round(slides_1.completion_time, 2)) + self.assertEqual(123.0, slides_2.completion_time) class TestSequencing(slides_common.SlidesCase):