From f115aa013b25ea7585b77b7158153310d8a83a34 Mon Sep 17 00:00:00 2001 From: thsh-odoo Date: Tue, 13 Jun 2023 04:07:56 +0000 Subject: [PATCH] [FIX] website_slides: inaccurate completion time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit How to reproduce the bug =========================. 1. Open e-Learning. 2. Create a section. 3. Add a content in the created section and change the default duration . -> New duration is not set and it is taking the default duration only Technical ========= https://github.com/odoo/odoo/commit/7b7fdf8f2771840797e1d416a8275ba3666ab542 This commit introduce the feature to set default time for the content in the backend if user put the Duration field empty for that content but because of the extra 'not' in the condition it was always getting true so every time default value is stored and if completion_time is not there then it is set to 0. After this Commit ================== Now whatever duration user will put, it will be set and if completion_time is not given then it will give us the default time. Task-3340462 closes odoo/odoo#135668 X-original-commit: 5cae7c3fa6f564a3f8d42cb255377cdc2ef86276 Signed-off-by: Stéphane Debauche (std) --- addons/website_slides/models/slide_slide.py | 2 +- .../tests/test_slide_channel.py | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) 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):