Skip to content

Commit

Permalink
[ADD] project_forecast_line_priority
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsirintanis committed Feb 1, 2024
1 parent 9cc4029 commit 5f7eb1b
Show file tree
Hide file tree
Showing 13 changed files with 685 additions and 0 deletions.
76 changes: 76 additions & 0 deletions project_forecast_line_priority/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
==============================
Project Forecast Line Priority
==============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0c7a75d90fd3e732909de3a75615d2b034c399f90748a81be1be2979a3d28d44
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github
:target: https://github.com/OCA/project/tree/14.0/project_forecast_line_priority
:alt: OCA/project
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/project-14-0/project-14-0-project_forecast_line_priority
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/project&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module recomputes forecast line end dates based on the priority of connected task(s)

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/project/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/project/issues/new?body=module:%20project_forecast_line_priority%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Therp BV

Contributors
~~~~~~~~~~~~

* Nikos Tsirintanis <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/project <https://github.com/OCA/project/tree/14.0/project_forecast_line_priority>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions project_forecast_line_priority/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions project_forecast_line_priority/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 Therp BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Project Forecast Line Priority",
"summary": "Project Forecast Line dates according to task priority",
"version": "14.0.1.0.0",
"author": "Therp BV, Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Project",
"website": "https://github.com/OCA/project",
"depends": ["project_forecast_line_deadline", "project_task_add_very_high"],
"data": ["views/res_config_settings.xml"],
"installable": True,
}
2 changes: 2 additions & 0 deletions project_forecast_line_priority/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import project_task
from . import res_config_settings
44 changes: 44 additions & 0 deletions project_forecast_line_priority/models/project_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2024 Therp BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from datetime import timedelta

from odoo import fields, models


class ProjectTask(models.Model):
_inherit = "project.task"

def write(self, vals):
"""Set forecast_date_planned_end based on priority"""
# If user sets end date manually
if "forecast_date_planned_end" in vals or "date_deadline" in vals:
return super().write(vals)
if "priority" not in vals:
return super().write(vals)
config_model = self.env["ir.config_parameter"]
priority = int(vals.get("priority", 0))
today = fields.Date.today()
for this in self:
# date deadline is set, so ignore this one
if this.date_deadline:
continue
# if priority is 0, do nothing
if priority < 1:
continue
if priority == 1:
# add weeks to end date
vals["forecast_date_planned_end"] = config_model.get_param(
"project_forecast_line_priority.priority_1"
)
else:
# priorities 2 and 3
# add days to end date
interval = timedelta(
days=int(
config_model.get_param(
"project_forecast_line_priority.priority_%s" % priority
)
)
)
vals["forecast_date_planned_end"] = today + interval
return super().write(vals)
30 changes: 30 additions & 0 deletions project_forecast_line_priority/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2024 Therp BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

forecast_line_priority_1_date = fields.Date(
inverse="_inverse__compute_forecast_line_priority_1_date_str"
)
forecast_line_priority_1_date_str = fields.Char(
config_parameter="project_forecast_line_priority.priority_1"
)
forecast_line_priority_2 = fields.Integer(
config_parameter="project_forecast_line_priority.priority_2"
)
forecast_line_priority_3 = fields.Integer(
config_parameter="project_forecast_line_priority.priority_3"
)

def _inverse__compute_forecast_line_priority_1_date_str(self):
"""As config_parameters does not accept Date field,
we store the date formated string into a Char config field"""
for setting in self:
if setting.forecast_line_priority_1_date:
setting.forecast_line_priority_1_date_str = fields.Date.to_string(
setting.forecast_line_priority_1_date
)
1 change: 1 addition & 0 deletions project_forecast_line_priority/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Nikos Tsirintanis <[email protected]>
1 change: 1 addition & 0 deletions project_forecast_line_priority/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module recomputes forecast line end dates based on the priority of connected task(s)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5f7eb1b

Please sign in to comment.