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
|
import frappe
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
priorities = ["Low", "Medium", "High"]
|
priority = ["Low", "Medium", "High"]
|
||||||
|
|
||||||
service_levels = frappe.get_list("Service Level")
|
service_levels = frappe.get_list("Service Level")
|
||||||
for service_level in service_levels:
|
for service_level in service_levels:
|
||||||
doc = frappe.get_doc("Service Level", service_level)
|
doc = frappe.get_doc("Service Level", service_level)
|
||||||
doc.update({
|
for value in priority:
|
||||||
"priorities": [
|
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": doc.response_time,
|
||||||
"response_time_period": doc.response_time_period,
|
"response_time_period": doc.response_time_period,
|
||||||
"resolution_time": doc.resolution_time,
|
"resolution_time": doc.resolution_time,
|
||||||
"resolution_time_period": doc.resolution_time_period,
|
"resolution_time_period": doc.resolution_time_period,
|
||||||
}
|
}
|
||||||
]
|
)
|
||||||
})
|
doc.save(ignore_permissions=True)
|
||||||
|
|
||||||
service_level_agreements = frappe.get_list("Service Level Agreement")
|
service_level_agreements = frappe.get_list("Service Level Agreement")
|
||||||
for service_level_agreement in service_level_agreements:
|
for service_level_agreement in service_level_agreements:
|
||||||
doc = frappe.get_doc("Service Level Agreement", service_level_agreement)
|
doc = frappe.get_doc("Service Level Agreement", service_level_agreement)
|
||||||
doc.update({
|
for value in priority:
|
||||||
"priorities": [
|
doc.append("priorities",
|
||||||
{
|
{
|
||||||
"priority": "Low",
|
"priority": "{0}".format(value),
|
||||||
"response_time": doc.response_time,
|
"response_time": doc.response_time,
|
||||||
"response_time_period": doc.response_time_period,
|
"response_time_period": doc.response_time_period,
|
||||||
"resolution_time": doc.resolution_time,
|
"resolution_time": doc.resolution_time,
|
||||||
"resolution_time_period": doc.resolution_time_period,
|
"resolution_time_period": doc.resolution_time_period,
|
||||||
},
|
}
|
||||||
{
|
)
|
||||||
"priority": "Medium",
|
doc.save(ignore_permissions=True)
|
||||||
"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,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
|
@ -4,7 +4,7 @@ frappe.ui.form.on("Issue", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
refresh: function (frm) {
|
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);
|
set_time_to_resolve_and_response(frm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,8 +128,8 @@ class Issue(Document):
|
|||||||
def before_insert(self):
|
def before_insert(self):
|
||||||
self.set_response_and_resolution_time(priority=self.priority)
|
self.set_response_and_resolution_time(priority=self.priority)
|
||||||
|
|
||||||
def set_response_and_resolution_time(self, priority=None):
|
def set_response_and_resolution_time(self, priority):
|
||||||
service_level_agreement = get_active_service_level_agreement_for(self.customer, priority)
|
service_level_agreement = get_active_service_level_agreement_for(priority=priority, customer=self.customer)
|
||||||
if service_level_agreement:
|
if service_level_agreement:
|
||||||
self.service_level_agreement = service_level_agreement.name
|
self.service_level_agreement = service_level_agreement.name
|
||||||
else:
|
else:
|
||||||
|
@ -70,7 +70,6 @@
|
|||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "eval: !doc.default_service_level_agreement",
|
|
||||||
"fieldname": "agreement_details_section",
|
"fieldname": "agreement_details_section",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Agreement Details"
|
"label": "Agreement Details"
|
||||||
@ -83,7 +82,6 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": "Active",
|
"default": "Active",
|
||||||
"depends_on": "eval: !doc.default_service_level_agreement",
|
|
||||||
"fieldname": "agreement_status",
|
"fieldname": "agreement_status",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"label": "Agreement Status",
|
"label": "Agreement Status",
|
||||||
@ -133,7 +131,7 @@
|
|||||||
"unique": 1
|
"unique": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2019-05-06 00:31:06.167762",
|
"modified": "2019-05-06 22:00:44.623128",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Support",
|
"module": "Support",
|
||||||
"name": "Service Level Agreement",
|
"name": "Service Level Agreement",
|
||||||
|
@ -14,7 +14,7 @@ class ServiceLevelAgreement(Document):
|
|||||||
frappe.throw(_("Select a Customer or set as Default Service Level Agreement."))
|
frappe.throw(_("Select a Customer or set as Default Service Level Agreement."))
|
||||||
|
|
||||||
if self.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."))
|
frappe.throw(_("A Default Service Level Agreement already exists."))
|
||||||
else:
|
else:
|
||||||
if not (self.start_date and self.end_date):
|
if not (self.start_date and self.end_date):
|
||||||
@ -31,33 +31,23 @@ def check_agreement_status():
|
|||||||
{"agreement_status": "Active"},
|
{"agreement_status": "Active"},
|
||||||
{"default_service_level_agreement": 0}
|
{"default_service_level_agreement": 0}
|
||||||
])
|
])
|
||||||
service_level_agreements.reverse()
|
|
||||||
for service_level_agreement in service_level_agreements:
|
for service_level_agreement in service_level_agreements:
|
||||||
service_level_agreement = frappe.get_doc("Service Level Agreement", service_level_agreement)
|
service_level_agreement = frappe.get_doc("Service Level Agreement", service_level_agreement)
|
||||||
|
|
||||||
if service_level_agreement.end_date < frappe.utils.getdate():
|
if service_level_agreement.end_date < frappe.utils.getdate():
|
||||||
service_level_agreement.agreement_status = "Expired"
|
frappe.db.set_value("Service Level Agreement", service_level_agreement.name,
|
||||||
service_level_agreement.save()
|
"agreement_status", "Expired")
|
||||||
|
|
||||||
@frappe.whitelist()
|
@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,
|
if customer and frappe.db.exists("Service Level Agreement", {"customer": customer}):
|
||||||
`tabService Level Agreement`.holiday_list
|
or_filter = {"customer": customer}
|
||||||
from `tabService Level Agreement`
|
else:
|
||||||
inner join `tabService Level Priority`
|
or_filter = {"default_service_level_agreement": 1}
|
||||||
on `tabService Level Agreement`.name=`tabService Level Priority`.parent where
|
|
||||||
(
|
agreement = frappe.get_list("Service Level Agreement", filters={"agreement_status": "Active"},
|
||||||
`tabService Level Agreement`.customer='%(customer)s' and
|
or_filters=or_filter, fields=["name", "service_level"])
|
||||||
`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)
|
|
||||||
|
|
||||||
return agreement[0] if agreement else None
|
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:
|
if not default_service_level_agreement_exists:
|
||||||
default_service_level_agreement.insert(ignore_permissions=True)
|
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:
|
if not service_level_agreement_exists:
|
||||||
service_level_agreement.insert(ignore_permissions=True)
|
service_level_agreement.insert(ignore_permissions=True)
|
||||||
return service_level_agreement.name
|
return service_level_agreement.name
|
||||||
@ -180,5 +180,5 @@ def make_service_level_agreement():
|
|||||||
return service_level_agreement_exists
|
return service_level_agreement_exists
|
||||||
|
|
||||||
def get_service_level_agreement():
|
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
|
return service_level_agreement
|
Loading…
Reference in New Issue
Block a user