Skip to content

Commit

Permalink
[ADD] project_status_sla: add new module
Browse files Browse the repository at this point in the history
  • Loading branch information
kaynnan committed Aug 12, 2024
1 parent c211819 commit b975221
Show file tree
Hide file tree
Showing 19 changed files with 395 additions and 0 deletions.
84 changes: 84 additions & 0 deletions project_status_sla/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
==================
Project Status SLA
==================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0a0cd378a237876b5b3ec27927d63a9e10ef69d1dd9c027a7d92cfae15bb1a41
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-Escodoo%2Fproject--addons-lightgray.png?logo=github
:target: https://github.com/Escodoo/project-addons/tree/12.0/project_status_sla
:alt: Escodoo/project-addons

|badge1| |badge2| |badge3|

This module adds SLA funcionality in Project Status module.

**Table of contents**

.. contents::
:local:

Configuration
=============

To configure this module, you need to:

#. Allow SLA for a Project

Allow SLA
~~~~~~~~~~~~~~~

#. Go to Project > Configuration > Project Statuses SLA.
#. Edit or create a new SLA.
#. Select a Project.
#. Select a Status.
#. Select a days or hours for that SLA.

Usage
=====

#. Go to *Project > Reports > Project Statuses SLA Lines * to see history SLA in Project.
Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/Escodoo/project-addons/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/Escodoo/project-addons/issues/new?body=module:%20project_status_sla%0Aversion:%2012.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
~~~~~~~

* Escodoo

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

* `Escodoo <https://www.escodoo.com.br>`_:

* Marcel Savegnago <marcel.savegnago@escodoo.com.br>
* Kaynnan Lemes <kaynnan.lemes@escodoo.com.br>

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

This module is part of the `Escodoo/project-addons <https://github.com/Escodoo/project-addons/tree/12.0/project_status_sla>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions project_status_sla/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
22 changes: 22 additions & 0 deletions project_status_sla/__manifest__.py
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",
],
}
14 changes: 14 additions & 0 deletions project_status_sla/data/project_status_sla_cron.xml
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>
3 changes: 3 additions & 0 deletions project_status_sla/models/__init__.py
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
67 changes: 67 additions & 0 deletions project_status_sla/models/project_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# 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)
)

self.message_post(
body=message, message_type="notification", subtype="mail.mt_comment"
)
43 changes: 43 additions & 0 deletions project_status_sla/models/project_status_sla.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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 timedelta

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):
create_date = self.create_date

# Calcula a data de vencimento com base na criação do SLA
deadline = create_date + timedelta(days=self.days, hours=self.hours)

# Verifica se o SLA expirou
project.sla_deadline = deadline
project.sla_expired = deadline < fields.Datetime.now()
project._create_project_sla_history()
23 changes: 23 additions & 0 deletions project_status_sla/models/project_status_sla_line.py
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"
)
12 changes: 12 additions & 0 deletions project_status_sla/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
To configure this module, you need to:

#. Allow SLA for a Project

Allow SLA
~~~~~~~~~~~~~~~

#. Go to Project > Configuration > Project Statuses SLA.
#. Edit or create a new SLA.
#. Select a Project.
#. Select a Status.
#. Select a days or hours for that SLA.
4 changes: 4 additions & 0 deletions project_status_sla/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `Escodoo <https://www.escodoo.com.br>`_:

* Marcel Savegnago <marcel.savegnago@escodoo.com.br>
* Kaynnan Lemes <kaynnan.lemes@escodoo.com.br>
1 change: 1 addition & 0 deletions project_status_sla/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module adds SLA funcionality in Project Status module.
1 change: 1 addition & 0 deletions project_status_sla/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#. Go to *Project > Reports > Project Statuses SLA Lines * to see history SLA in Project.
5 changes: 5 additions & 0 deletions project_status_sla/security/ir.model.access.csv
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
Binary file added project_status_sla/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions project_status_sla/views/project_project.xml
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>
53 changes: 53 additions & 0 deletions project_status_sla/views/project_status_sla.xml
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>
Loading

0 comments on commit b975221

Please sign in to comment.