-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] cb_maintenance: Add time to close
- Loading branch information
Showing
5 changed files
with
96 additions
and
4 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
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,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() |
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,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 | ||
""", | ||
) |
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
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