fix: test cases and use orm
This commit is contained in:
parent
aa0eaab3df
commit
c5999154e6
@ -5,62 +5,34 @@ from __future__ import unicode_literals
|
||||
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)
|
@ -4,7 +4,7 @@ frappe.ui.form.on("Issue", {
|
||||
},
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -128,8 +128,8 @@ class Issue(Document):
|
||||
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:
|
||||
|
@ -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",
|
||||
|
@ -14,7 +14,7 @@ class ServiceLevelAgreement(Document):
|
||||
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 @@ def check_agreement_status():
|
||||
{"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
|
@ -85,7 +85,7 @@ def make_service_level_agreement():
|
||||
]
|
||||
})
|
||||
|
||||
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 @@ def make_service_level_agreement():
|
||||
]
|
||||
})
|
||||
|
||||
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 @@ def make_service_level_agreement():
|
||||
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
|
Loading…
Reference in New Issue
Block a user