Skip to content
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#72188 [MIG] [16.0] project_task_deadline_from_project #459

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"depends": [
"project",
"project_task_date_planned",
"project_task_deadline_from_project",
"project_task_full_text_search",
"project_type_advanced",
"project_default_task_stage",
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ USER odoo

COPY project_stage_allow_timesheet mnt/extra-addons/project_stage_allow_timesheet
COPY project_task_date_planned /mnt/extra-addons/project_task_date_planned
COPY project_task_deadline_from_project /mnt/extra-addons/project_task_deadline_from_project
COPY project_task_full_text_search /mnt/extra-addons/project_task_full_text_search
COPY project_type_advanced /mnt/extra-addons/project_type_advanced
COPY project_default_task_stage /mnt/extra-addons/project_default_task_stage
Expand Down
13 changes: 13 additions & 0 deletions project_task_deadline_from_project/README.rst
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)
4 changes: 4 additions & 0 deletions project_task_deadline_from_project/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright2023 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

Check notice on line 4 in project_task_deadline_from_project/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

project_task_deadline_from_project/__init__.py#L4

'.models' imported but unused (F401)
15 changes: 15 additions & 0 deletions project_task_deadline_from_project/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright2023 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{

Check warning on line 4 in project_task_deadline_from_project/__manifest__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

project_task_deadline_from_project/__manifest__.py#L4

Statement seems to have no effect
"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,
}
4 changes: 4 additions & 0 deletions project_task_deadline_from_project/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright2023 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

Check notice on line 4 in project_task_deadline_from_project/models/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

project_task_deadline_from_project/models/__init__.py#L4

'.project_task' imported but unused (F401)
29 changes: 29 additions & 0 deletions project_task_deadline_from_project/models/project_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright2023 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.
4 changes: 4 additions & 0 deletions project_task_deadline_from_project/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright2023 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 project_task_deadline_from_project/tests/test_project_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright2023 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)
Loading