feat: filter sla based on customer in issue

This commit is contained in:
Himanshu Warekar 2019-06-20 10:00:11 +05:30
parent 24cef8e26e
commit 41bf0c6855
3 changed files with 31 additions and 38 deletions

View File

@ -1,38 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
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)
for value in priority:
doc.append("priorities",
{
"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)
for value in priority:
doc.append("priorities",
{
"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)

View File

@ -1,6 +1,7 @@
frappe.ui.form.on("Issue", {
onload: function(frm) {
frm.email_field = "raised_by";
if (frm.doc.service_level_agreement) {
frappe.call({
method: "erpnext.support.doctype.service_level_agreement.service_level_agreement.get_service_level_agreement_priorities",
@ -19,6 +20,24 @@ frappe.ui.form.on("Issue", {
}
}
});
frappe.call({
method: "erpnext.support.doctype.service_level_agreement.service_level_agreement.get_valid_service_level_agreements",
args: {
customer: frm.doc.customer,
},
callback: function (r) {
if (r && r.message) {
frm.set_query('service_level_agreement', function() {
return {
filters: {
"name": ["in", r.message],
}
};
});
}
}
});
}
},

View File

@ -70,6 +70,18 @@ def get_active_service_level_agreement_for(priority, customer=None, service_leve
def get_service_level_agreement_priorities(name):
return [priority.priority for priority in frappe.get_list("Service Level Priority", filters={"parent": name}, fields=["priority"])]
@frappe.whitelist()
def get_valid_service_level_agreements(customer):
or_filters = [
["Service Level Agreement", "entity", "in", [customer, get_customer_group(customer), get_customer_territory(customer), "IS NULL"]],
["Service Level Agreement", "default_service_level_agreement", "=", 1]
]
if not customer:
or_filters = ["Service Level Agreement", "default_service_level_agreement", "=", 1]
return [d.name for d in frappe.get_list("Service Level Agreement", or_filters=or_filters)]
def get_customer_group(customer):
if customer:
return frappe.db.get_value("Customer", customer, "customer_group")