-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG][16.0] project_task_subtask_same_project
- Loading branch information
Showing
16 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Project Task Subtask Same Project | ||
================================= | ||
Force the subtasks to be on the same project than its parent. | ||
|
||
|
||
When attempting to assign a subtask to a task from a different project, | ||
an error message is displayed | ||
|
||
.. image:: static/description/subtask_in_different_project.png | ||
|
||
Project Readonly on Subtask | ||
--------------------------- | ||
On the form view of a subtask, the project is readonly. | ||
The value is automatically propagated from the parent task. | ||
|
||
.. image:: static/description/subtask_project_readonly.png | ||
|
||
|
||
|
||
Contributors | ||
------------ | ||
* Numigi (tm) and all its contributors (https://bit.ly/numigiens) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from . import models | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
{ | ||
"name": "Project Task Subtask Same Project", | ||
"version": "16.0.1.0.0", | ||
"author": "Numigi", | ||
"maintainer": "Numigi", | ||
"website": "https://bit.ly/numigi-com", | ||
"license": "LGPL-3", | ||
"category": "Project", | ||
"summary": "Constrain a subtask to be on the same project that its parent.", | ||
"depends": ["project"], | ||
"data": [ | ||
"data/res_config_data.xml", | ||
"views/project_task_views.xml", | ||
], | ||
"installable": True, | ||
} |
12 changes: 12 additions & 0 deletions
12
project_task_subtask_same_project/data/res_config_data.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<data> | ||
<record model="res.config.settings" id="res_config_settings"> | ||
<field name="group_subtask_project" eval="1" /> | ||
</record> | ||
|
||
<function model="res.config.settings" name="execute"> | ||
<value eval="[ref('res_config_settings')]" /> | ||
</function> | ||
</data> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * project_task_subtask_same_project | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-11-27 10:44+0000\n" | ||
"PO-Revision-Date: 2024-11-27 10:44+0000\n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: project_task_subtask_same_project | ||
#: model:ir.model,name:project_task_subtask_same_project.model_project_task | ||
msgid "Task" | ||
msgstr "Tâche" | ||
|
||
#. module: project_task_subtask_same_project | ||
#. odoo-python | ||
#: code:addons/project_task_subtask_same_project/models/project_task.py:0 | ||
#, python-format | ||
msgid "" | ||
"The task {task} is in the project {task_project}. The subtask {subtask} must" | ||
" be in the same project." | ||
msgstr "" | ||
"La tâche {task} est dans le projet {task_project}. La sous-tâche {subtask} " | ||
"doit être dans le même projet." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from . import project_task | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from odoo import models, _ | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class ProjectTaskSubtaskSameProject(models.Model): | ||
_inherit = "project.task" | ||
|
||
def _check_subtask_not_in_different_project(self): | ||
subtasks = self.filtered(lambda t: t.parent_id) | ||
for subtask in subtasks: | ||
task = subtask.parent_id | ||
if subtask.project_id != task.project_id: | ||
raise ValidationError( | ||
_( | ||
"The task {task} is in the project {task_project}. " | ||
"The subtask {subtask} must be in the same project." | ||
).format( | ||
task=task.display_name, | ||
task_project=task.project_id.display_name, | ||
subtask=subtask.display_name, | ||
) | ||
) | ||
|
||
def write(self, vals): | ||
""" | ||
Propagate the value of the project to the subtask when it | ||
is changed on the parent task. | ||
""" | ||
res = super().write(vals) | ||
for task in self: | ||
if task.child_ids and "project_id" in vals: | ||
task.child_ids.write({"project_id": vals["project_id"]}) | ||
task._check_subtask_not_in_different_project() | ||
return res |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+123 KB
...t_task_subtask_same_project/static/description/subtask_in_different_project.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+33.8 KB
...sk_subtask_same_project/static/description/subtask_kanban_no_project_filter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+110 KB
project_task_subtask_same_project/static/description/subtask_project_readonly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from . import test_project_task |
51 changes: 51 additions & 0 deletions
51
project_task_subtask_same_project/tests/test_project_task.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
import pytest | ||
from odoo.exceptions import ValidationError | ||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestProjectTaskSubTaskSameProject(TransactionCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.project_a = cls.env["project.project"].create({"name": "projectA"}) | ||
cls.project_b = cls.env["project.project"].create({"name": "projectB"}) | ||
cls.task_parent = cls.env["project.task"].create( | ||
{"name": "Task Parent", "project_id": cls.project_a.id} | ||
) | ||
cls.subtask_1 = cls.env["project.task"].create( | ||
{ | ||
"name": "Task Child 1", | ||
"project_id": cls.task_parent.project_id.id, | ||
"parent_id": cls.task_parent.id, | ||
"planned_hours": 1.0, | ||
} | ||
) | ||
cls.subtask_2 = cls.env["project.task"].create( | ||
{ | ||
"name": "Task Child 2", | ||
"project_id": cls.task_parent.project_id.id, | ||
"parent_id": cls.task_parent.id, | ||
"planned_hours": 1.0, | ||
} | ||
) | ||
|
||
def test_whenParentTaskChangeProject_thenSubTaskInheritNewProject(self): | ||
""" | ||
Given a parent task is on project A | ||
And the subtasks are on project A too | ||
When the parent task is changed to project B | ||
Then the subtasks are changed to project B too. | ||
""" | ||
self.task_parent.project_id = self.project_b.id | ||
|
||
assert self.subtask_1.project_id == self.project_b | ||
assert self.subtask_2.project_id == self.project_b | ||
|
||
def test_onUpdateSubtask_ifNotSameProject_raiseError(self): | ||
with pytest.raises(ValidationError): | ||
self.subtask_1.project_id = self.project_b |
29 changes: 29 additions & 0 deletions
29
project_task_subtask_same_project/views/project_task_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
|
||
<record id="view_task_form2" model="ir.ui.view"> | ||
<field name="name">Project task: Project Readonly for Subtasks</field> | ||
<field name="model">project.task</field> | ||
<field name="inherit_id" ref="project.view_task_form2"/> | ||
<field name="arch" type="xml"> | ||
<field name="display_project_id" position="attributes"> | ||
<attribute name="attrs">{'readonly': [('parent_id', '!=', False)],'invisible': [('parent_id', '=', False)]}</attribute> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<record id="view_task_kanban" model="ir.ui.view"> | ||
<field name="name">Project task: Project Readonly for Subtasks Kanban</field> | ||
<field name="model">project.task</field> | ||
<field name="inherit_id" ref="project.view_task_kanban"/> | ||
<field name="arch" type="xml"> | ||
<field name="project_id" position="after"> | ||
<field name="parent_id" invisible="1"/> | ||
</field> | ||
<field name="project_id" position="attributes"> | ||
<attribute name="attrs">{'readonly': [('parent_id', '!=', False)]}</attribute> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |