Skip to content

Commit

Permalink
[IMP] cb_maintenance: Add time to close
Browse files Browse the repository at this point in the history
  • Loading branch information
etobella committed Nov 2, 2023
1 parent 55ed2fc commit e03cd80
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cb_maintenance/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Cb Maintenance",
"summary": """
CB maintenance base""",
"version": "14.0.2.0.0",
"version": "14.0.3.0.0",
"license": "AGPL-3",
"author": "CreuBlanca",
"website": "https://github.com/tegin/cb-maintenance",
Expand Down
12 changes: 12 additions & 0 deletions cb_maintenance/migrations/14.0.3.0.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import logging

from openupgradelib import openupgrade

_logger = logging.getLogger(__name__)


@openupgrade.migrate()
def migrate(env, version):
menu = env.ref("maintenance.maintenance_reporting")
if not menu.active:
menu.toggle_active()
44 changes: 44 additions & 0 deletions cb_maintenance/migrations/14.0.3.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2020 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from openupgradelib import openupgrade

_fields_to_add = [
(
"days_to_close",
"maintenance.request",
"maintenance_request",
"int",
False,
"account_statement_import_txt_xlsx",
),
(
"hours_to_close",
"maintenance.request",
"maintenance_request",
"float",
False,
"account_statement_import_txt_xlsx",
),
]


@openupgrade.migrate()
def migrate(env, version):
if not openupgrade.column_exists(env.cr, "maintenance_request", "hours_to_close"):
openupgrade.add_fields(env, _fields_to_add)
openupgrade.logged_query(
env.cr,
"""
UPDATE maintenance_request
SET hours_to_close = extract(EPOCH FROM close_datetime - create_date)/60/60
WHERE close_datetime is not NULL
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE maintenance_request
SET days_to_close = close_date - request_date
WHERE close_date is not NULL and close_date > request_date
""",
)
27 changes: 26 additions & 1 deletion cb_maintenance/models/maintenance_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class MaintenanceRequest(models.Model):
related="category_id.custom_info_template_id", store=True
)
company_id = fields.Many2one(default=False)

days_to_close = fields.Integer(store=True, compute="_compute_days_to_close")
hours_to_close = fields.Float(store=True, compute="_compute_hours_to_close")
solved_id = fields.Many2one("res.users", string="Solved by", readonly=True)
solution = fields.Html()
equipment_id = fields.Many2one(check_company=False)
Expand Down Expand Up @@ -50,6 +51,30 @@ class MaintenanceRequest(models.Model):
external_link = fields.Char()

# link_ocs = fields.Char(string="Link OCS") # TODO: Not sure if necessary
@api.depends("close_datetime", "create_date")
def _compute_hours_to_close(self):
for record in self:
if record.close_datetime and record.close_datetime > record.create_date:
record.hours_to_close = (
(record.close_datetime - record.create_date).total_seconds()
/ 60
/ 60
)
else:
record.hours_to_close = 0.0

@api.depends("close_date", "request_date")
def _compute_days_to_close(self):
for record in self:
if record.close_date and record.close_date > record.request_date:
record.days_to_close = int(
(record.close_date - record.request_date).total_seconds()
/ 60
/ 60
/ 24
)
else:
record.days_to_close = 0

def _compute_attachments_count(self):
for record in self:
Expand Down
15 changes: 13 additions & 2 deletions cb_maintenance/views/maintenance_request.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@
attrs="{'invisible': [('solved_id', '=', False)]}"
options="{'no_open': True}"
/>
<field
name="hours_to_close"
attrs="{'invisible': [('close_datetime', '=', False)]}"
/>
<field
name="days_to_close"
attrs="{'invisible': [('close_datetime', '=', False)]}"
/>
</field>
<button name="archive_equipment_request" position="attributes">
<attribute name="invisible">1</attribute>
Expand Down Expand Up @@ -392,8 +400,11 @@
<field name="parent_id" ref="maintenance.menu_maintenance_title" />
<field name="sequence" eval="2" />
</record>
<record id="maintenance.maintenance_reporting" model="ir.ui.menu">
<field name="active" eval="False" />
<record id="maintenance.maintenance_request_reporting" model="ir.ui.menu">
<field
eval="[(6, 0, [ref('maintenance.group_equipment_manager')])]"
name="groups_id"
/>
</record>
<record id="maintenance.menu_m_dashboard" model="ir.ui.menu">
<field
Expand Down

0 comments on commit e03cd80

Please sign in to comment.