-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] project_status_sla: add new module
- Loading branch information
Showing
18 changed files
with
397 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
=================== | ||
Project Project Sla | ||
=================== | ||
.. |badge1| image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
|
||
|badge1| | ||
|
||
Add SLA for Project | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
|
||
To Configure... | ||
|
||
Usage | ||
===== | ||
|
||
To usage... | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues | ||
<https://github.com/Escodoo/{project_repo}/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 | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Escodoo | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Marcel Savegnago <marcel.savegnago@escodoo.com.br> | ||
|
||
Other credits | ||
~~~~~~~~~~~~~ | ||
|
||
The development of this module has been financially supported by: | ||
|
||
* Escodoo - `https://www.escodoo.com.br <https://www.escodoo.com.br>`_ | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the Escodoo. | ||
|
||
.. |maintainer-escodoo| image:: https://github.com/escodoo.png?size=80px | ||
:target: https://github.com/Escodoo | ||
:alt: escodoo | ||
|
||
|maintainer-escodoo| | ||
|
||
We at Escodoo are exclusively dedicated to deploying the Odoo Platform and are | ||
focused on providing solutions that make our customers more competitive, lowering | ||
costs, making technology more accessible and ensuring it is used strategically to | ||
add even more value to the business. | ||
|
||
.. |maintainer-marcelsavegnago| image:: https://github.com/marcelsavegnago.png?size=40px | ||
:target: https://github.com/marcelsavegnago | ||
:alt: marcelsavegnago | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-marcelsavegnago| | ||
|
||
To contribute to this module, please visit https://www.escodoo.com.br. |
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 @@ | ||
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,22 @@ | ||
# Copyright 2024 - TODAY, Escodoo | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Project Status SLA", | ||
"summary": """ | ||
Add SLA for Project Status""", | ||
"version": "12.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "Escodoo", | ||
"website": "https://github.com/Escodoo/project-addons", | ||
"depends": [ | ||
"project_status", | ||
], | ||
"data": [ | ||
"data/project_status_sla_cron.xml", | ||
"security/ir.model.access.csv", | ||
"views/project_project.xml", | ||
"views/project_status_sla.xml", | ||
"views/project_status_sla_line.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,14 @@ | ||
<?xml version="1.0" encoding='UTF-8' ?> | ||
<odoo noupdate="1"> | ||
<record model="ir.cron" id="project_status_sla_cron_alert"> | ||
<field name="name">Generate Project Statuses SLA Alerts</field> | ||
<field name="model_id" ref="model_project_status_sla" /> | ||
<field name="state">code</field> | ||
<field name="code">model.check_sla()</field> | ||
<field name="user_id" ref="base.user_root" /> | ||
<field name="interval_number">5</field> | ||
<field name="interval_type">minutes</field> | ||
<field name="numbercall">-1</field> | ||
<field eval="False" name="doall" /> | ||
</record> | ||
</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,3 @@ | ||
from . import project_project | ||
from . import project_status_sla | ||
from . import project_status_sla_line |
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,72 @@ | ||
# Copyright 2024 - TODAY, Kaynnan Lemes <kaynnan.lemes@escodoo.com.br> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, fields, models | ||
|
||
|
||
class ProjectProject(models.Model): | ||
_inherit = "project.project" | ||
|
||
sla_deadline = fields.Datetime(string="SLA Deadline") | ||
sla_expired = fields.Boolean(string="SLA Expired") | ||
|
||
def _create_project_sla_history(self): | ||
"""Create SLA history records for the Project if not already present.""" | ||
|
||
# Check exist history | ||
existing_history_count = self.env["project.status.sla.line"].search_count( | ||
[ | ||
("project_id", "=", self.id), | ||
("stage_id", "=", self.project_status.id), | ||
("sla_deadline", "=", self.sla_deadline), | ||
("status", "in", ["not_met", "met"]), | ||
] | ||
) | ||
|
||
if existing_history_count: | ||
return | ||
|
||
# Search records in SLA related project and stage_id | ||
sla_records = self.env["project.status.sla"].search( | ||
[ | ||
("project_id", "=", self.id), | ||
("stage_id", "=", self.project_status.id), | ||
] | ||
) | ||
|
||
# Process SLA | ||
for sla in sla_records: | ||
self._create_sla_line(sla) | ||
self._post_sla_message() | ||
|
||
def _create_sla_line(self, sla): | ||
"""Create a new SLA line record.""" | ||
status = "not_met" if self.sla_expired else "met" | ||
self.env["project.status.sla.line"].create( | ||
{ | ||
"project_id": self.id, | ||
"stage_id": self.project_status.id, | ||
"sla_id": sla.id, | ||
"sla_deadline": self.sla_deadline, | ||
"sla_expired": self.sla_expired, | ||
"reached_date": fields.Datetime.now(), | ||
"status": status, | ||
} | ||
) | ||
|
||
def _post_sla_message(self): | ||
"""Post a message to notify about the SLA status.""" | ||
if self.sla_expired: | ||
message = _( | ||
"<p>The SLA for Project <b>%s</b> in Stage <b>%s</b> has been exceeded.</p>" | ||
% (self.name, self.project_status.name) | ||
) | ||
else: | ||
message = _( | ||
"<p>The SLA for Project <b>%s</b> in Stage <b>%s</b> has been achieved.</p>" | ||
% (self.name, self.project_status.name) | ||
) | ||
|
||
self.message_post( | ||
body=message, message_type="notification", subtype="mail.mt_comment" | ||
) |
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,61 @@ | ||
# Copyright 2024 - TODAY, Kaynnan Lemes <kaynnan.lemes@escodoo.com.br> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from datetime import datetime | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class ProjectStatusSLA(models.Model): | ||
_name = "project.status.sla" | ||
_description = "Project Status SLA" | ||
|
||
project_id = fields.Many2one( | ||
comodel_name="project.project", string="Project", required=True | ||
) | ||
stage_id = fields.Many2one( | ||
comodel_name="project.status", string="Stage", required=True | ||
) | ||
days = fields.Integer(string="Days", default=0, required=True) | ||
hours = fields.Integer(string="Hours", default=0, required=True) | ||
note = fields.Char(string="Note") | ||
|
||
@api.model | ||
def check_sla(self): | ||
slas = self.search([]) | ||
for sla in slas: | ||
projects = self.env["project.project"].search( | ||
[("id", "=", sla.project_id.id)] | ||
) | ||
for project in projects: | ||
if project.project_status == sla.stage_id: | ||
sla.check_project_sla(project) | ||
|
||
def check_project_sla(self, project): | ||
deadline = project.create_date | ||
working_calendar = project.resource_calendar_id | ||
|
||
if self.days > 0: | ||
deadline = working_calendar.plan_days( | ||
self.days + 1, deadline, compute_leaves=True | ||
) | ||
create_date = project.create_date | ||
|
||
deadline = deadline.replace( | ||
hour=create_date.hour, | ||
minute=create_date.minute, | ||
second=create_date.second, | ||
microsecond=create_date.microsecond, | ||
) | ||
|
||
deadline_for_working_cal = working_calendar.plan_hours(0, deadline) | ||
|
||
if deadline_for_working_cal and deadline.day < deadline_for_working_cal.day: | ||
deadline = deadline.replace(hour=0, minute=0, second=0, microsecond=0) | ||
|
||
deadline = working_calendar.plan_hours( | ||
self.hours, deadline, compute_leaves=True | ||
) | ||
project.sla_deadline = deadline | ||
project.sla_expired = project.sla_deadline < datetime.now() | ||
project._create_project_sla_history() |
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,23 @@ | ||
# Copyright 2024 - TODAY, Kaynnan Lemes <kaynnan.lemes@escodoo.com.br> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ProjectStatusSLALine(models.Model): | ||
_name = "project.status.sla.line" | ||
_description = "Project Status SLA line" | ||
|
||
project_id = fields.Many2one( | ||
comodel_name="project.project", string="Project", required=True | ||
) | ||
stage_id = fields.Many2one( | ||
comodel_name="project.status", string="Stage", required=True | ||
) | ||
sla_id = fields.Many2one(comodel_name="project.status.sla", string="SLA") | ||
sla_deadline = fields.Datetime(string="SLA Deadline") | ||
sla_expired = fields.Boolean(string="SLA Expired") | ||
reached_date = fields.Datetime(string="Reached Date") | ||
status = fields.Selection( | ||
selection=[("not_met", "Not Met"), ("met", "Met")], string="Status" | ||
) |
Empty file.
Empty file.
Empty file.
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,5 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_project_status_sla_user,Access Project Status SLA User,model_project_status_sla,base.group_user,1,0,0,0 | ||
access_project_status_sla_manager,Access Project Status SLA Manager,model_project_status_sla,project.group_project_manager,1,1,1,1 | ||
access_project_status_sla_line_user,Access Project Status SLA Line User,model_project_status_sla_line,base.group_user,1,0,0,0 | ||
access_project_status_sla_line_manager,Access Project Status SLA Line Manager,model_project_status_sla_line,project.group_project_manager,1,1,1,1 |
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,20 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2024 - TODAY, Kaynnan Lemes <kaynnan.lemes@escodoo.com.br> | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
|
||
<record model="ir.ui.view" id="project_project_form_view"> | ||
<field name="name">project.project.form (in project_status_sla)</field> | ||
<field name="model">project.project</field> | ||
<field name="inherit_id" ref="project.edit_project" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//sheet" position="inside"> | ||
<group> | ||
<field name="sla_deadline" readonly="1" /> | ||
<field name="sla_expired" readonly="1" /> | ||
</group> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
</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,53 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2024 - TODAY, Kaynnan Lemes <kaynnan.lemes@escodoo.com.br> | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<record model="ir.ui.view" id="project_status_sla_form"> | ||
<field name="name">project.status.sla.form (in project_status_sla)</field> | ||
<field name="model">project.status.sla</field> | ||
<field name="arch" type="xml"> | ||
<form string="SLA"> | ||
<sheet> | ||
<group> | ||
<group> | ||
<separator colspan="2" string="Apply on" /> | ||
<field name="project_id" string="Reach Project" /> | ||
<field name="stage_id" string="Reach Statuses" /> | ||
<label for="time_days" string="Reach In" /> | ||
<div class="o_row"> | ||
<field name="days" /> days<br /> | ||
<field name="hours" /> hours<br /> | ||
</div> | ||
</group> | ||
</group> | ||
<field name="note" placeholder="Description of the policy..." /> | ||
</sheet> | ||
</form> | ||
</field> | ||
</record> | ||
<record model="ir.ui.view" id="project_status_sla_tree"> | ||
<field name="name">project.status.sla.tree (in project_status_sla)</field> | ||
<field name="model">project.status.sla</field> | ||
<field name="arch" type="xml"> | ||
<tree string="SLA"> | ||
<field name="project_id" /> | ||
<field name="stage_id" /> | ||
<field name="days" /> | ||
<field name="hours" /> | ||
<field name="note" /> | ||
</tree> | ||
</field> | ||
</record> | ||
<record id="action_project_status_sla_tree" model="ir.actions.act_window"> | ||
<field name="name">Project Statuses SLA</field> | ||
<field name="res_model">project.status.sla</field> | ||
<field name="view_mode">tree,form</field> | ||
</record> | ||
<menuitem | ||
id="project_project" | ||
name="Project Statuses SLA" | ||
parent="project.menu_project_config" | ||
action="action_project_status_sla_tree" | ||
sequence="16" | ||
/> | ||
</odoo> |
Oops, something went wrong.