-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TA#72203 [MIG][16.0] project_task_subtask_same_project #458
Open
rivo2302
wants to merge
4
commits into
16.0
Choose a base branch
from
TA#72203
base: 16.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello @rivo2302 |
||
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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @rivo2302
It would be preferable to use
@api.constrains
here instead of calling the check in thewrite()
method.