From 5cec89d1abf5a50f82a52705d9af7f786e1462e2 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Fri, 28 Jun 2019 19:07:13 +0530 Subject: [PATCH 1/2] fix: remove frm call for priority change --- .../patches/v12_0/set_priority_for_support.py | 2 ++ erpnext/support/doctype/issue/issue.js | 21 ------------------- erpnext/support/doctype/issue/issue.py | 12 ++++++++--- .../service_level_agreement.py | 2 +- 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/erpnext/patches/v12_0/set_priority_for_support.py b/erpnext/patches/v12_0/set_priority_for_support.py index cc290396f8..4eae0654e8 100644 --- a/erpnext/patches/v12_0/set_priority_for_support.py +++ b/erpnext/patches/v12_0/set_priority_for_support.py @@ -18,6 +18,8 @@ def set_issue_priority(): "name": priority }).insert(ignore_permissions=True) + frappe.delete_doc_if_exists("Property Setter", {"field_name": "priority", "property": "options"}) + def set_priority_for_issue(): # Sets priority for Issues as Select field is changed to Link field. issue_priority = frappe.get_list("Issue", fields=["name", "priority"]) diff --git a/erpnext/support/doctype/issue/issue.js b/erpnext/support/doctype/issue/issue.js index ba54edcf39..1a272d1bc4 100644 --- a/erpnext/support/doctype/issue/issue.js +++ b/erpnext/support/doctype/issue/issue.js @@ -73,27 +73,6 @@ frappe.ui.form.on("Issue", { } }, - priority: function(frm) { - if (frm.doc.service_level_agreement) { - frm.call('change_service_level_agreement_and_priority', { - "priority": frm.doc.priority, - "service_level_agreement": frm.doc.service_level_agreement - }).then(() => { - frappe.msgprint(__("Issue Priority changed to {0}.", [frm.doc.priority])); - frm.refresh(); - }); - } - }, - - service_level_agreement: function(frm) { - frm.call('change_service_level_agreement_and_priority', { - "service_level_agreement": frm.doc.service_level_agreement - }).then(() => { - frappe.msgprint(__("Service Level Agreement changed to {0}.", [frm.doc.service_level_agreement])); - frm.refresh(); - }); - }, - timeline_refresh: function(frm) { // create button for "Help Article" if(frappe.model.can_create('Help Article')) { diff --git a/erpnext/support/doctype/issue/issue.py b/erpnext/support/doctype/issue/issue.py index 70430b16bb..3b703d9a21 100644 --- a/erpnext/support/doctype/issue/issue.py +++ b/erpnext/support/doctype/issue/issue.py @@ -29,6 +29,7 @@ class Issue(Document): if not self.raised_by: self.raised_by = frappe.session.user + self.change_service_level_agreement_and_priority() self.update_status() self.set_lead_contact(self.raised_by) @@ -173,9 +174,14 @@ class Issue(Document): self.response_by_variance = round(time_diff_in_hours(self.response_by, now_datetime())) self.resolution_by_variance = round(time_diff_in_hours(self.resolution_by, now_datetime())) - def change_service_level_agreement_and_priority(self, priority=None, service_level_agreement=None): - self.set_response_and_resolution_time(priority=priority, service_level_agreement=service_level_agreement) - self.save(ignore_permissions=True) + def change_service_level_agreement_and_priority(self): + if not self.priority == frappe.db.get_value("Issue", self.name, "priority"): + self.set_response_and_resolution_time(priority=self.priority, service_level_agreement=self.service_level_agreement) + frappe.msgprint("Priority has been updated.") + + if not self.service_level_agreement == frappe.db.get_value("Issue", self.name, "service_level_agreement"): + self.set_response_and_resolution_time(priority=self.priority, service_level_agreement=self.service_level_agreement) + frappe.msgprint("Service Level Agreement has been updated.") def get_expected_time_for(parameter, service_level, start_date_time): current_date_time = start_date_time diff --git a/erpnext/support/doctype/service_level_agreement/service_level_agreement.py b/erpnext/support/doctype/service_level_agreement/service_level_agreement.py index 332bf63580..5536cc9df3 100644 --- a/erpnext/support/doctype/service_level_agreement/service_level_agreement.py +++ b/erpnext/support/doctype/service_level_agreement/service_level_agreement.py @@ -18,7 +18,7 @@ class ServiceLevelAgreement(Document): if self.start_date >= self.end_date: frappe.throw(_("Start Date of Agreement can't be greater than or equal to End Date.")) - if self.end_date < frappe.utils.getdate(): + if self.end_date < frappe.utils.nowdate(): frappe.throw(_("End Date of Agreement can't be less than today.")) if self.entity_type and self.entity: From bc0bc6677e7fa6312a1d773cd9b5777b23104508 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Fri, 28 Jun 2019 19:41:29 +0530 Subject: [PATCH 2/2] fix: use db sql to delete property setter --- erpnext/patches.txt | 1 + erpnext/patches/v12_0/delete_priority_property_setter.py | 9 +++++++++ erpnext/patches/v12_0/set_priority_for_support.py | 2 -- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 erpnext/patches/v12_0/delete_priority_property_setter.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index fa51638605..36a31cfadc 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -607,3 +607,4 @@ execute:frappe.delete_doc_if_exists("Page", "support-analytics") erpnext.patches.v12_0.make_item_manufacturer erpnext.patches.v12_0.set_quotation_status erpnext.patches.v12_0.set_priority_for_support +erpnext.patches.v12_0.delete_priority_property_setter diff --git a/erpnext/patches/v12_0/delete_priority_property_setter.py b/erpnext/patches/v12_0/delete_priority_property_setter.py new file mode 100644 index 0000000000..5927267543 --- /dev/null +++ b/erpnext/patches/v12_0/delete_priority_property_setter.py @@ -0,0 +1,9 @@ +import frappe + +def execute(): + frappe.db.sql(""" + DELETE FROM `tabProperty Setter` + WHERE `tabProperty Setter`.doc_type='Issue' + AND `tabProperty Setter`.field_name='priority' + AND `tabProperty Setter`.property='options' + """) \ No newline at end of file diff --git a/erpnext/patches/v12_0/set_priority_for_support.py b/erpnext/patches/v12_0/set_priority_for_support.py index 4eae0654e8..cc290396f8 100644 --- a/erpnext/patches/v12_0/set_priority_for_support.py +++ b/erpnext/patches/v12_0/set_priority_for_support.py @@ -18,8 +18,6 @@ def set_issue_priority(): "name": priority }).insert(ignore_permissions=True) - frappe.delete_doc_if_exists("Property Setter", {"field_name": "priority", "property": "options"}) - def set_priority_for_issue(): # Sets priority for Issues as Select field is changed to Link field. issue_priority = frappe.get_list("Issue", fields=["name", "priority"])