fix: test cases and use orm
diff --git a/erpnext/patches/v12_0/move_parameters_to_priority.py b/erpnext/patches/v12_0/move_parameters_to_priority.py
index c62c1c3..310bfe2 100644
--- a/erpnext/patches/v12_0/move_parameters_to_priority.py
+++ b/erpnext/patches/v12_0/move_parameters_to_priority.py
@@ -5,62 +5,34 @@
import frappe
def execute():
- priorities = ["Low", "Medium", "High"]
+ priority = ["Low", "Medium", "High"]
service_levels = frappe.get_list("Service Level")
for service_level in service_levels:
doc = frappe.get_doc("Service Level", service_level)
- doc.update({
- "priorities": [
+ for value in priority:
+ doc.append("priorities",
{
- "priority": "Low",
- "response_time": doc.response_time,
- "response_time_period": doc.response_time_period,
- "resolution_time": doc.resolution_time,
- "resolution_time_period": doc.resolution_time_period,
- },
- {
- "priority": "Medium",
- "response_time": doc.response_time,
- "response_time_period": doc.response_time_period,
- "resolution_time": doc.resolution_time,
- "resolution_time_period": doc.resolution_time_period,
- },
- {
- "priority": "High",
+ "priority": "{0}".format(value),
"response_time": doc.response_time,
"response_time_period": doc.response_time_period,
"resolution_time": doc.resolution_time,
"resolution_time_period": doc.resolution_time_period,
}
- ]
- })
+ )
+ doc.save(ignore_permissions=True)
service_level_agreements = frappe.get_list("Service Level Agreement")
for service_level_agreement in service_level_agreements:
doc = frappe.get_doc("Service Level Agreement", service_level_agreement)
- doc.update({
- "priorities": [
+ for value in priority:
+ doc.append("priorities",
{
- "priority": "Low",
+ "priority": "{0}".format(value),
"response_time": doc.response_time,
"response_time_period": doc.response_time_period,
"resolution_time": doc.resolution_time,
"resolution_time_period": doc.resolution_time_period,
- },
- {
- "priority": "Medium",
- "response_time": doc.response_time,
- "response_time_period": doc.response_time_period,
- "resolution_time": doc.resolution_time,
- "resolution_time_period": doc.resolution_time_period,
- },
- {
- "priority": "High",
- "response_time": doc.response_time,
- "response_time_period": doc.response_time_period,
- "resolution_time": doc.resolution_time,
- "resolution_time_period": doc.resolution_time_period,
- },
- ]
- })
+ }
+ )
+ doc.save(ignore_permissions=True)
\ No newline at end of file
diff --git a/erpnext/support/doctype/issue/issue.js b/erpnext/support/doctype/issue/issue.js
index a19b372..ab40a5b 100644
--- a/erpnext/support/doctype/issue/issue.js
+++ b/erpnext/support/doctype/issue/issue.js
@@ -4,7 +4,7 @@
},
refresh: function (frm) {
- if (frm.doc.service_level_agreement) {
+ if (frm.doc.service_level_agreement && frm.doc.status !== "Closed") {
set_time_to_resolve_and_response(frm);
}
diff --git a/erpnext/support/doctype/issue/issue.py b/erpnext/support/doctype/issue/issue.py
index 66eb55a..7eeb783 100644
--- a/erpnext/support/doctype/issue/issue.py
+++ b/erpnext/support/doctype/issue/issue.py
@@ -128,8 +128,8 @@
def before_insert(self):
self.set_response_and_resolution_time(priority=self.priority)
- def set_response_and_resolution_time(self, priority=None):
- service_level_agreement = get_active_service_level_agreement_for(self.customer, priority)
+ def set_response_and_resolution_time(self, priority):
+ service_level_agreement = get_active_service_level_agreement_for(priority=priority, customer=self.customer)
if service_level_agreement:
self.service_level_agreement = service_level_agreement.name
else:
diff --git a/erpnext/support/doctype/service_level_agreement/service_level_agreement.json b/erpnext/support/doctype/service_level_agreement/service_level_agreement.json
index 84dbdde..b63e2af 100644
--- a/erpnext/support/doctype/service_level_agreement/service_level_agreement.json
+++ b/erpnext/support/doctype/service_level_agreement/service_level_agreement.json
@@ -70,7 +70,6 @@
"read_only": 1
},
{
- "depends_on": "eval: !doc.default_service_level_agreement",
"fieldname": "agreement_details_section",
"fieldtype": "Section Break",
"label": "Agreement Details"
@@ -83,7 +82,6 @@
},
{
"default": "Active",
- "depends_on": "eval: !doc.default_service_level_agreement",
"fieldname": "agreement_status",
"fieldtype": "Select",
"label": "Agreement Status",
@@ -133,7 +131,7 @@
"unique": 1
}
],
- "modified": "2019-05-06 00:31:06.167762",
+ "modified": "2019-05-06 22:00:44.623128",
"modified_by": "Administrator",
"module": "Support",
"name": "Service Level Agreement",
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 ea869ee..00f5cb3 100644
--- a/erpnext/support/doctype/service_level_agreement/service_level_agreement.py
+++ b/erpnext/support/doctype/service_level_agreement/service_level_agreement.py
@@ -14,7 +14,7 @@
frappe.throw(_("Select a Customer or set as Default Service Level Agreement."))
if self.default_service_level_agreement:
- if frappe.db.exists("Service Level Agreement", {"default_service_level_agreement": "1"}):
+ if frappe.db.exists("Service Level Agreement", {"default_service_level_agreement": "1", "name": ["!=", self.name]}):
frappe.throw(_("A Default Service Level Agreement already exists."))
else:
if not (self.start_date and self.end_date):
@@ -31,33 +31,23 @@
{"agreement_status": "Active"},
{"default_service_level_agreement": 0}
])
- service_level_agreements.reverse()
+
for service_level_agreement in service_level_agreements:
service_level_agreement = frappe.get_doc("Service Level Agreement", service_level_agreement)
+
if service_level_agreement.end_date < frappe.utils.getdate():
- service_level_agreement.agreement_status = "Expired"
- service_level_agreement.save()
+ frappe.db.set_value("Service Level Agreement", service_level_agreement.name,
+ "agreement_status", "Expired")
@frappe.whitelist()
-def get_active_service_level_agreement_for(customer, priority):
+def get_active_service_level_agreement_for(priority, customer=None):
- agreement = frappe.db.sql("""select `tabService Level Agreement`.name, `tabService Level Agreement`.service_level,
- `tabService Level Agreement`.holiday_list
- from `tabService Level Agreement`
- inner join `tabService Level Priority`
- on `tabService Level Agreement`.name=`tabService Level Priority`.parent where
- (
- `tabService Level Agreement`.customer='%(customer)s' and
- `tabService Level Agreement`.agreement_status='Active' and
- `tabService Level Priority`.priority='%(priority)s'
- ) or
- (
- `tabService Level Agreement`.default_service_level_agreement='1'
- )
- limit 1""",
- {
- "customer": customer,
- "priority": priority
- }, as_dict=True)
+ if customer and frappe.db.exists("Service Level Agreement", {"customer": customer}):
+ or_filter = {"customer": customer}
+ else:
+ or_filter = {"default_service_level_agreement": 1}
+
+ agreement = frappe.get_list("Service Level Agreement", filters={"agreement_status": "Active"},
+ or_filters=or_filter, fields=["name", "service_level"])
return agreement[0] if agreement else None
\ No newline at end of file
diff --git a/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py b/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py
index b9d25e4..b2c0eba 100644
--- a/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py
+++ b/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py
@@ -85,7 +85,7 @@
]
})
- default_service_level_agreement_exists = frappe.db.exists("Service Level Agreement", "Default Service Level Agreement")
+ default_service_level_agreement_exists = frappe.db.exists("Service Level Agreement", "SLA-Default Service Level Agreement")
if not default_service_level_agreement_exists:
default_service_level_agreement.insert(ignore_permissions=True)
@@ -172,7 +172,7 @@
]
})
- service_level_agreement_exists = frappe.db.exists("Service Level Agreement", "_Test Service Level Agreement")
+ service_level_agreement_exists = frappe.db.exists("Service Level Agreement", "SLA-_Test Service Level Agreement")
if not service_level_agreement_exists:
service_level_agreement.insert(ignore_permissions=True)
return service_level_agreement.name
@@ -180,5 +180,5 @@
return service_level_agreement_exists
def get_service_level_agreement():
- service_level_agreement = frappe.db.exists("Service Level Agreement", "_Test Service Level Agreement")
+ service_level_agreement = frappe.db.exists("Service Level Agreement", "SLA-_Test Service Level Agreement")
return service_level_agreement
\ No newline at end of file