brotherton-erpnext/erpnext/patches/v13_0/update_response_by_variance.py
Chillar Anand 915b34391c
chore: Clean up imports (#27302)
* chore: Added isort to pre-commit config

* chore: Sort imports with isort

* chore: Clean up imports with pycln

* chore: Sort imports with isort

* chore: Fix import issues

* chore: Clean up sider issues

* chore: Remove import errors from flake8 ignore list

* chore: Clean up lint issues
2021-09-02 16:44:59 +05:30

34 lines
1.4 KiB
Python

# Copyright (c) 2020, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
if frappe.db.exists('DocType', 'Issue') and frappe.db.count('Issue'):
invalid_issues = frappe.get_all('Issue', {
'first_responded_on': ['is', 'set'],
'response_by_variance': ['<', 0]
}, ["name", "response_by_variance", "timestampdiff(Second, `first_responded_on`, `response_by`) as variance"])
# issues which has response_by_variance set as -ve
# but diff between first_responded_on & response_by is +ve i.e SLA isn't failed
invalid_issues = [d for d in invalid_issues if d.get('variance') > 0]
for issue in invalid_issues:
frappe.db.set_value('Issue', issue.get('name'), 'response_by_variance', issue.get('variance'), update_modified=False)
invalid_issues = frappe.get_all('Issue', {
'resolution_date': ['is', 'set'],
'resolution_by_variance': ['<', 0]
}, ["name", "resolution_by_variance", "timestampdiff(Second, `resolution_date`, `resolution_by`) as variance"])
# issues which has resolution_by_variance set as -ve
# but diff between resolution_date & resolution_by is +ve i.e SLA isn't failed
invalid_issues = [d for d in invalid_issues if d.get('variance') > 0]
for issue in invalid_issues:
frappe.db.set_value('Issue', issue.get('name'), 'resolution_by_variance', issue.get('variance'), update_modified=False)