-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TA#72188 [MIG] [16.0] project_task_deadline_from_project (#459)
* [16.0][MIG] project_task_deadline_from_project --------- Co-authored-by: Abdellatif Benzbiria <[email protected]>
- Loading branch information
1 parent
ec7b6c0
commit 68479ac
Showing
10 changed files
with
137 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,13 @@ | ||
Project Task Deadline From Project | ||
================================== | ||
This module automatically sets the deadline on a task from the project's deadline. | ||
|
||
When changing the task from one project to another, the deadline is automatically changed. | ||
|
||
If the destination project has no deadline, then, the deadline on the task is emptied. | ||
|
||
The deadline on a task can always be changed manually. | ||
|
||
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 2018-today 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,15 @@ | ||
# Copyright 2018-today 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 Deadline From Project", | ||
"version": "16.0.1.0.0", | ||
"author": "Numigi", | ||
"maintainer": "Numigi", | ||
"website": "https://bit.ly/numigi-com", | ||
"license": "LGPL-3", | ||
"category": "Project", | ||
"summary": "Propagate the deadline from projects to tasks.", | ||
"depends": ["project"], | ||
"installable": True, | ||
} |
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 2018-today 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,29 @@ | ||
# Copyright 2018-today 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 api, models | ||
|
||
|
||
class ProjectTaskWithDeadlineFromProject(models.Model): | ||
_inherit = "project.task" | ||
|
||
@api.model | ||
def create(self, vals): | ||
task = super().create(vals) | ||
should_propagate_deadline = task.project_id and "date_deadline" not in vals | ||
if should_propagate_deadline: | ||
task.date_deadline = task.project_id.date | ||
return task | ||
|
||
def write(self, vals): | ||
should_propagate_deadline = ( | ||
vals.get("project_id") and "date_deadline" not in vals | ||
) | ||
if should_propagate_deadline: | ||
project = self.env["project.project"].browse(vals["project_id"]) | ||
vals["date_deadline"] = project.date | ||
return super().write(vals) | ||
|
||
@api.onchange("project_id") | ||
def _onchange_project_propagate_deadline(self): | ||
self.date_deadline = self.project_id.date |
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 2018-today 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 |
66 changes: 66 additions & 0 deletions
66
project_task_deadline_from_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,66 @@ | ||
# Copyright 2018-today Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from datetime import date | ||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestProjectTask(TransactionCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.deadline = date(2018, 6, 1) | ||
cls.project_with_no_deadline = cls.env["project.project"].create( | ||
{ | ||
"name": "Project With No Deadline", | ||
"date": False, | ||
} | ||
) | ||
cls.project_with_deadline = cls.env["project.project"].create( | ||
{ | ||
"name": "Project With Deadline", | ||
"date": cls.deadline, | ||
} | ||
) | ||
cls.task = cls.env["project.task"].create({"name": "Task 1"}) | ||
|
||
def test_when_creating_task_with_project_then_deadline_is_propagated(self): | ||
task = self.env["project.task"].create( | ||
{ | ||
"name": "Task 2", | ||
"project_id": self.project_with_deadline.id, | ||
} | ||
) | ||
self.assertEqual(task.date_deadline, self.deadline) | ||
|
||
def test_when_creating_task_with_default_project_then_deadline_is_propagated(self): | ||
task = ( | ||
self.env["project.task"] | ||
.with_context(default_project_id=self.project_with_deadline.id) | ||
.create({"name": "Task 2"}) | ||
) | ||
self.assertEqual(task.date_deadline, self.deadline) | ||
|
||
def test_when_creating_task_if_project_has_no_deadline_then_deadline_is_empty(self): | ||
task = self.env["project.task"].create( | ||
{ | ||
"name": "Task 2", | ||
"project_id": self.project_with_no_deadline.id, | ||
} | ||
) | ||
self.assertFalse(task.date_deadline) | ||
|
||
def test_when_changing_project_then_deadline_is_propagated(self): | ||
self.task.project_id = self.project_with_deadline | ||
self.assertEqual(self.task.date_deadline, self.deadline) | ||
|
||
def test_when_changing_project_if_project_has_no_deadline_then_deadline_is_empty( | ||
self, | ||
): | ||
self.task.project_id = self.project_with_no_deadline | ||
self.assertFalse(self.task.date_deadline) | ||
|
||
def test_onchange_project_then_deadline_is_propagated_to_task(self): | ||
self.task.project_id = self.project_with_deadline | ||
self.task._onchange_project_propagate_deadline() | ||
self.assertEqual(self.task.date_deadline, self.deadline) |