From 7fe8dc77203c86ca5c1a87f2a4899a148ff243b2 Mon Sep 17 00:00:00 2001 From: Raouf Date: Thu, 8 Jun 2023 12:29:17 +0000 Subject: [PATCH] [IMP] project: improve create task shortcuts Before this commit: In 16.2, we have implemented a nice tool to set various fields at the creation of a task from the Kanban quick create using shortcuts. This implementation is simple (only a few lines of code), but is not very flexible. Indeed, shortcuts need to be in a specific order and at a specific place for them to work. As a consequence, it is very easy for the user to fail in the creation of their tasks using shortcuts. This task aims at making this feature more robust and complex so that it works in more cases. In this commit: It should be possible for the #tag, 23h, @demo, ! shortcuts to be put in whatever order, as long as they are at the end of the name task-3349154 closes odoo/odoo#124155 Signed-off-by: Xavier Bol (xbo) --- addons/hr_timesheet/models/project_task.py | 4 ++-- .../tests/test_project_task_quick_create.py | 4 ++-- addons/project/models/project_task.py | 15 ++++++++++----- .../tests/test_project_task_quick_create.py | 12 +++++++----- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/addons/hr_timesheet/models/project_task.py b/addons/hr_timesheet/models/project_task.py index 8dea201957d..3cbb10f1a40 100644 --- a/addons/hr_timesheet/models/project_task.py +++ b/addons/hr_timesheet/models/project_task.py @@ -124,8 +124,8 @@ class Task(models.Model): 'planned_hours': r'\s(\d+(?:\.\d+)?)[hH]', } - def _get_groups_patterns(self): - return ['(?:%s)*' % self._get_group_pattern()['planned_hours']] + super()._get_groups_patterns() + def _prepare_pattern_groups(self): + return [self._get_group_pattern()['planned_hours']] + super()._prepare_pattern_groups() def _get_cannot_start_with_patterns(self): return super()._get_cannot_start_with_patterns() + [r'(?!\d+(?:\.\d+)?(?:h|H))'] diff --git a/addons/hr_timesheet/tests/test_project_task_quick_create.py b/addons/hr_timesheet/tests/test_project_task_quick_create.py index 46a3db3f92f..2c4c017087b 100644 --- a/addons/hr_timesheet/tests/test_project_task_quick_create.py +++ b/addons/hr_timesheet/tests/test_project_task_quick_create.py @@ -14,8 +14,8 @@ class TestProjectTaskQuickCreate(TestCommonTimesheet): def test_create_task_with_valid_expressions(self): # tuple format = (display name, [expected name, expected tags count, expected users count, expected priority, expected planned hours]) valid_expressions = { - 'task A 30H 2.5h #tag1 @user_employee2 !': ('task A', 1, 1, "1", 32.5), - 'task A 30.H 2.h 2.13h': ('task A 30.H 2.h', 0, 0, "0", 2.13), + 'task A 30H 2.5h #tag1 @user_employee2 2H #tag2 @user_employee 5h !': ('task A', 2, 2, "1", 39.5), + 'task A 30.H 2.h 1H #tag2 ! @user_employee ! @user_employee2 2.13h !': ('task A 30.H 2.h', 1, 2, "1", 3.13), } for expression, values in valid_expressions.items(): diff --git a/addons/project/models/project_task.py b/addons/project/models/project_task.py index 4aea3acfdc2..f94f43f36b8 100644 --- a/addons/project/models/project_task.py +++ b/addons/project/models/project_task.py @@ -663,14 +663,19 @@ class Task(models.Model): def _get_group_pattern(self): return { 'tags_and_users': r'\s([#@]%s[^\s]+)', - 'priority': r'\s(!)$', + 'priority': r'\s(!)', } - def _get_groups_patterns(self): - group_pattern = self._get_group_pattern() + def _prepare_pattern_groups(self): + group = self._get_group_pattern() return [ - r'(?:%s)*' % (group_pattern['tags_and_users'] % ''), - r'(?:%s)?' % group_pattern['priority'], + group['tags_and_users'] % '', + group['priority'], + ] + + def _get_groups_patterns(self): + return [ + r'(?:%s)*' % ('|').join(self._prepare_pattern_groups()), ] def _get_cannot_start_with_patterns(self): diff --git a/addons/project/tests/test_project_task_quick_create.py b/addons/project/tests/test_project_task_quick_create.py index 20fad401156..eac8dc21f81 100644 --- a/addons/project/tests/test_project_task_quick_create.py +++ b/addons/project/tests/test_project_task_quick_create.py @@ -24,8 +24,11 @@ class TestProjectTaskQuickCreate(TestProjectCommon): def test_create_task_with_valid_expressions(self): # dict format = {display name: (expected name, expected tags count, expected users count, expected priority, expected planned hours)} valid_expressions = { - 'task A 30H 2.5h #Tag1 #tag2 #tag3 @Armande @Bast @raouf1 @raouf2 !': ('task A 30H 2.5h', 3, 4, "1", 0), + 'task A 30H 2.5h #Tag1 #tag2 @Armande @Bast @raouf1 @raouf2 !': ('task A 30H 2.5h', 2, 4, "1", 0), + 'task A 30H 2.5h #Tag1 #tag2 #tag3 @Armande @Bast @raouf1 ! @raouf2': ('task A 30H 2.5h', 3, 4, "1", 0), + 'task A ! 30H 2.5h #Tag1 #tag2 #tag3 @Armande @Bast ! @raouf1 #tag4': ('task A 30H 2.5h', 4, 3, "1", 0), 'task A': ('task A', 0, 0, "0", 0), + 'task A !': ('task A', 0, 0, "1", 0), 'task A 30H 2.5h #Tag1 #tag2 #tag3 @Armande @Bast @raouf1 @raouf2': ('task A 30H 2.5h', 3, 4, "0", 0), 'task A 30H 2.5h #Tag1 @Armande #tag3 @Bast @raouf1 #tag2 @raouf2 #tag4': ('task A 30H 2.5h', 4, 4, "0", 0), 'task A 30H #tag1 @raouf1 Nothing !': ('task A 30H #tag1 @raouf1 Nothing', 0, 0, '1', 0), @@ -43,11 +46,10 @@ class TestProjectTaskQuickCreate(TestProjectCommon): def test_create_task_with_invalid_expressions(self): invalid_expressions = ( - 'task A 30H #tag1 @raouf1 @raouf2 !!', - 'task A 30H #tag1 @raouf2 user', - '#tag1 #tag2 #tag3 @Armande @Bast @raouf1 @raouf2 !', - '@Armande @Bast @raouf1 @raouf2 !', + '#tag1 #tag2 #tag3 @Armande @Bast @raouf1 @raouf2', + '@Armande @Bast @raouf1 @raouf2', '!', + 'task A!' ) for expression in invalid_expressions: