From e4a3c9824f42612ec32c50cb30df043bdc4b913d Mon Sep 17 00:00:00 2001
From: thsh-odoo <thsh@odoo.com>
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#135334

X-original-commit: 1c470b65bca48c2ac660fda919be7b8fc6e3990f
Signed-off-by: Stéphane Debauche (std) <std@odoo.com>
---
 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 9dc03bec0aa1..5ef1b33da7a6 100644
--- a/addons/website_slides/models/slide_slide.py
+++ b/addons/website_slides/models/slide_slide.py
@@ -641,7 +641,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 544d7f2a598f..a05e36dc8c41 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):
@@ -174,6 +174,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, slides_1.completion_time)
+        self.assertEqual(123.0, slides_2.completion_time)
 
 class TestSequencing(slides_common.SlidesCase):
 
-- 
GitLab