From a3ceea7a8bdb9fc58af16e519bc33cd004c6f19f Mon Sep 17 00:00:00 2001 From: unaiberis <146723346+unaiberis@users.noreply.github.com> Date: Tue, 2 Jul 2024 12:09:54 +0200 Subject: [PATCH] [ADD] Add module project_task_date_compute (#286) Co-authored-by: Ana Juaristi --- project_task_date_compute/README.rst | 29 +++++++++++++++++++ project_task_date_compute/__init__.py | 1 + project_task_date_compute/__manifest__.py | 17 +++++++++++ project_task_date_compute/models/__init__.py | 1 + .../models/project_task.py | 23 +++++++++++++++ .../views/project_task_views.xml | 27 +++++++++++++++++ .../odoo/addons/project_task_date_compute | 1 + setup/project_task_date_compute/setup.py | 6 ++++ 8 files changed, 105 insertions(+) create mode 100644 project_task_date_compute/README.rst create mode 100644 project_task_date_compute/__init__.py create mode 100644 project_task_date_compute/__manifest__.py create mode 100644 project_task_date_compute/models/__init__.py create mode 100644 project_task_date_compute/models/project_task.py create mode 100644 project_task_date_compute/views/project_task_views.xml create mode 120000 setup/project_task_date_compute/odoo/addons/project_task_date_compute create mode 100644 setup/project_task_date_compute/setup.py diff --git a/project_task_date_compute/README.rst b/project_task_date_compute/README.rst new file mode 100644 index 00000000..0b6ecf1f --- /dev/null +++ b/project_task_date_compute/README.rst @@ -0,0 +1,29 @@ +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +================================ +Compute Task Start and End Dates +================================ + +* Compute the start and end dates of tasks. +* This modules uses timesheet_ids to compute the start and end dates. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Contributors +------------ + +* Unai Beristain +* Ana Juaristi diff --git a/project_task_date_compute/__init__.py b/project_task_date_compute/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/project_task_date_compute/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/project_task_date_compute/__manifest__.py b/project_task_date_compute/__manifest__.py new file mode 100644 index 00000000..1dc8a6db --- /dev/null +++ b/project_task_date_compute/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2024 Unai Beristain - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Compute Task Start and End Dates", + "summary": "Module to compute task start and end dates based on time entries and stage", + "website": "https://github.com/avanzosc/project-addons", + "license": "AGPL-3", + "author": "AvanzOSC", + "version": "14.0.1.0.0", + "depends": ["base", "project", "hr_timesheet"], + "data": [ + "views/project_task_views.xml", + ], + "installable": True, + "auto_install": False, +} diff --git a/project_task_date_compute/models/__init__.py b/project_task_date_compute/models/__init__.py new file mode 100644 index 00000000..edf2d36b --- /dev/null +++ b/project_task_date_compute/models/__init__.py @@ -0,0 +1 @@ +from . import project_task diff --git a/project_task_date_compute/models/project_task.py b/project_task_date_compute/models/project_task.py new file mode 100644 index 00000000..f71a7fed --- /dev/null +++ b/project_task_date_compute/models/project_task.py @@ -0,0 +1,23 @@ +from odoo import api, fields, models + + +class ProjectTask(models.Model): + _inherit = "project.task" + + start_date = fields.Date( + string="Start Date", compute="_compute_start_date", store=True + ) + end_date = fields.Date(string="End Date", compute="_compute_end_date", store=True) + + @api.depends("timesheet_ids.date") + def _compute_start_date(self): + for task in self: + task.start_date = min(task.timesheet_ids.mapped("date"), default=False) + + @api.depends("timesheet_ids.date", "stage_id") + def _compute_end_date(self): + for task in self: + if task.stage_id.fold: + task.end_date = max(task.timesheet_ids.mapped("date"), default=False) + else: + task.end_date = False diff --git a/project_task_date_compute/views/project_task_views.xml b/project_task_date_compute/views/project_task_views.xml new file mode 100644 index 00000000..27daaa89 --- /dev/null +++ b/project_task_date_compute/views/project_task_views.xml @@ -0,0 +1,27 @@ + + + + project.task.tree.inherit + project.task + + + + + + + + + + project.task.form.inherit + project.task + + + + + + + + + + + diff --git a/setup/project_task_date_compute/odoo/addons/project_task_date_compute b/setup/project_task_date_compute/odoo/addons/project_task_date_compute new file mode 120000 index 00000000..5d60eb5d --- /dev/null +++ b/setup/project_task_date_compute/odoo/addons/project_task_date_compute @@ -0,0 +1 @@ +../../../../project_task_date_compute \ No newline at end of file diff --git a/setup/project_task_date_compute/setup.py b/setup/project_task_date_compute/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/project_task_date_compute/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)