Merge pull request #14160 from shreyashah115/patches-fixes-travis
Fix patches for Travis
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index 786ade1..8293ef7 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -5,7 +5,7 @@
from erpnext.hooks import regional_overrides
from frappe.utils import getdate
-__version__ = '10.1.33'
+__version__ = '10.1.34'
def get_default_company(user=None):
'''Get default company for user'''
diff --git a/erpnext/accounts/doctype/budget/budget.py b/erpnext/accounts/doctype/budget/budget.py
index d3a0d1d..ab9b93b 100644
--- a/erpnext/accounts/doctype/budget/budget.py
+++ b/erpnext/accounts/doctype/budget/budget.py
@@ -264,9 +264,12 @@
def get_item_details(args):
cost_center, expense_account = None, None
+ if not args.get('company'):
+ return cost_center, expense_account
+
if args.item_code:
- cost_center, expense_account = frappe.db.get_value('Item',
- args.item_code, ['buying_cost_center', 'expense_account'])
+ cost_center, expense_account = frappe.db.get_value('Item Default',
+ {'parent': args.item_code, 'company': args.get('company')}, ['buying_cost_center', 'expense_account'])
if not (cost_center and expense_account):
for doctype in ['Item Group', 'Company']:
@@ -286,6 +289,6 @@
def get_expense_cost_center(doctype, value):
fields = (['default_cost_center', 'default_expense_account']
- if doctype == 'Item Group'else ['cost_center', 'default_expense_account'])
+ if doctype == 'Item Group' else ['cost_center', 'default_expense_account'])
return frappe.db.get_value(doctype, value, fields)
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
index 93c0da4..242f42d 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
@@ -118,8 +118,8 @@
item_list = args.get("items")
args.pop("items")
-
- set_serial_nos_based_on_fifo = frappe.db.get_single_value("Stock Settings",
+
+ set_serial_nos_based_on_fifo = frappe.db.get_single_value("Stock Settings",
"automatically_set_serial_nos_based_on_fifo")
for item in item_list:
@@ -129,7 +129,7 @@
if set_serial_nos_based_on_fifo and not args.get('is_return'):
out.append(get_serial_no_for_item(args_copy))
return out
-
+
def get_serial_no_for_item(args):
from erpnext.stock.get_item_details import get_serial_no
@@ -150,7 +150,7 @@
"name": args.name,
"pricing_rule": None
})
-
+
if args.ignore_pricing_rule or not args.item_code:
if frappe.db.exists(args.doctype, args.name) and args.get("pricing_rule"):
item_details = remove_pricing_rule_for_item(args.get("pricing_rule"), item_details)
@@ -209,9 +209,9 @@
return item_details
def remove_pricing_rule_for_item(pricing_rule, item_details):
- pricing_rule = frappe.db.get_value('Pricing Rule', pricing_rule,
- ['rate_or_discount', 'margin_type'], as_dict=1)
- if pricing_rule and pricing_rule.rate_or_discount == 'Discount Percentage':
+ pricing_rule = frappe.db.get_value('Pricing Rule', pricing_rule,
+ ['price_or_discount', 'margin_type'], as_dict=1)
+ if pricing_rule and pricing_rule.price_or_discount == 'Discount Percentage':
item_details.discount_percentage = 0.0
if pricing_rule and pricing_rule.margin_type in ['Percentage', 'Amount']:
@@ -226,14 +226,14 @@
def remove_pricing_rules(item_list):
if isinstance(item_list, string_types):
item_list = json.loads(item_list)
-
- out = []
+
+ out = []
for item in item_list:
item = frappe._dict(item)
out.append(remove_pricing_rule_for_item(item.get("pricing_rule"), item))
-
+
return out
-
+
def get_pricing_rules(args):
def _get_tree_conditions(parenttype, allow_blank=True):
field = frappe.scrub(parenttype)
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
index 11edefc..8145d9b 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
@@ -4897,7 +4897,7 @@
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
- "modified": "2018-04-30 16:19:54.711885",
+ "modified": "2018-05-22 16:19:54.711885",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice",
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py
index 6aecab9..e84c85a 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.py
+++ b/erpnext/accounts/report/general_ledger/general_ledger.py
@@ -87,8 +87,8 @@
if gle_currency:
account_currency = gle_currency
else:
- account_currency = None if filters.party_type in ["Employee", "Student", "Shareholder"] else \
- frappe.db.get_value(filters.party_type, filters.party[0], "default_currency")
+ account_currency = (None if filters.party_type in ["Employee", "Student", "Shareholder", "Member"] else
+ frappe.db.get_value(filters.party_type, filters.party, "default_currency"))
filters["account_currency"] = account_currency or filters.company_currency
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index adab972..e3f7d1e 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -731,7 +731,7 @@
if self.doctype == "Sales Order" and getdate(d.due_date) < getdate(self.transaction_date):
frappe.throw(_("Row {0}: Due Date cannot be before posting date").format(d.idx))
elif d.due_date in dates:
- li.append('{0} in row {1}'.format(d.due_date, d.idx))
+ li.append(_("{0} in row {1}").format(d.due_date, d.idx))
dates.append(d.due_date)
if li:
diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py
index a4e95a1..a54cf7d 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -157,9 +157,10 @@
# scan description only if items are less than 50000
description_cond = 'or tabItem.description LIKE %(txt)s'
- return frappe.db.sql("""select tabItem.name, tabItem.item_group,
+ return frappe.db.sql("""select tabItem.name,
if(length(tabItem.item_name) > 40,
concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name,
+ tabItem.item_group,
if(length(tabItem.description) > 40, \
concat(substr(tabItem.description, 1, 40), "..."), description) as decription
from tabItem
diff --git a/erpnext/hr/doctype/leave_application/leave_application.js b/erpnext/hr/doctype/leave_application/leave_application.js
index 0b48706..c6cbb10 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.js
+++ b/erpnext/hr/doctype/leave_application/leave_application.js
@@ -91,6 +91,7 @@
employee: function(frm) {
frm.trigger("make_dashboard");
frm.trigger("get_leave_balance");
+ frm.trigger("set_leave_approver");
},
leave_approver: function(frm) {
@@ -189,4 +190,21 @@
});
}
},
+
+ set_leave_approver: function(frm) {
+ if(frm.doc.employee) {
+ // server call is done to include holidays in leave days calculations
+ return frappe.call({
+ method: 'erpnext.hr.doctype.leave_application.leave_application.get_leave_approver_data',
+ args: {
+ "employee": frm.doc.employee,
+ },
+ callback: function(r) {
+ if (r && r.message) {
+ frm.set_value('leave_approver', r.message);
+ }
+ }
+ });
+ }
+ }
});
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index c58e0cf..404501d 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -127,7 +127,7 @@
frappe.db.sql("""update `tabAttendance` set status = %s, leave_type = %s\
where name = %s""",(status, self.leave_type, d.name))
- elif self.from_date <= nowdate():
+ elif self.to_date <= nowdate():
for dt in daterange(getdate(self.from_date), getdate(self.to_date)):
date = dt.strftime("%Y-%m-%d")
if not date == self.half_day_date:
@@ -137,6 +137,7 @@
doc.company = self.company
doc.status = "On Leave"
doc.leave_type = self.leave_type
+ doc.insert(ignore_permissions=True)
doc.submit()
else:
doc = frappe.new_doc("Attendance")
@@ -145,6 +146,7 @@
doc.company = self.company
doc.status = "Half Day"
doc.leave_type = self.leave_type
+ doc.insert(ignore_permissions=True)
doc.submit()
def validate_salary_processed_days(self):
diff --git a/erpnext/hr/doctype/salary_structure_assignment/salary_structure_assignment.py b/erpnext/hr/doctype/salary_structure_assignment/salary_structure_assignment.py
index 6721749..2168a36 100644
--- a/erpnext/hr/doctype/salary_structure_assignment/salary_structure_assignment.py
+++ b/erpnext/hr/doctype/salary_structure_assignment/salary_structure_assignment.py
@@ -8,6 +8,8 @@
from frappe.utils import getdate
from frappe.model.document import Document
+class DuplicateAssignment(frappe.ValidationError): pass
+
class SalaryStructureAssignment(Document):
def validate(self):
self.validate_dates()
@@ -31,7 +33,7 @@
if self.from_date and getdate(self.from_date) > getdate(self.to_date):
frappe.throw(_("From Date {0} cannot be after To Date {1}")
.format(self.from_date, self.to_date))
- if relieving_date and getdate(self.to_date) > relieving_date and not self.flags.old_employee:
+ if relieving_date and getdate(self.to_date) > getdate(relieving_date) and not self.flags.old_employee:
frappe.throw(_("To Date {0} cannot be after employee's relieving Date {1}")
.format(self.to_date, relieving_date))
@@ -56,7 +58,8 @@
})
if assignment:
- frappe.throw(_("Active Salary Structure Assignment {0} found for employee {1} for the given dates").format(assignment[0][0], self.employee))
+ frappe.throw(_("Active Salary Structure Assignment {0} found for employee {1} for the given dates").
+ format(assignment[0][0], self.employee), DuplicateAssignment)
def get_assigned_salary_structure(employee, on_date):
if not employee or not on_date:
diff --git a/erpnext/patches/v11_0/create_department_records_for_each_company.py b/erpnext/patches/v11_0/create_department_records_for_each_company.py
index 2018ffd..4210c01 100644
--- a/erpnext/patches/v11_0/create_department_records_for_each_company.py
+++ b/erpnext/patches/v11_0/create_department_records_for_each_company.py
@@ -47,6 +47,9 @@
THEN "%s"
'''%(company, department, records[department]))
+ if not when_then:
+ return
+
frappe.db.sql("""
update
`tab%s`
diff --git a/erpnext/patches/v11_0/create_salary_structure_assignments.py b/erpnext/patches/v11_0/create_salary_structure_assignments.py
index 24874f6..12b477b 100644
--- a/erpnext/patches/v11_0/create_salary_structure_assignments.py
+++ b/erpnext/patches/v11_0/create_salary_structure_assignments.py
@@ -3,24 +3,29 @@
from __future__ import unicode_literals
import frappe
+from datetime import datetime
+from erpnext.hr.doctype.salary_structure_assignment.salary_structure_assignment import DuplicateAssignment
def execute():
frappe.reload_doc("hr", "doctype", "salary_structure_assignment")
for d in frappe.db.sql("""
select sse.*, ss.company from `tabSalary Structure Employee` sse, `tabSalary Structure` ss
- where ss.name = sse.parent""", as_dict=1):
- s = frappe.new_doc("Salary Structure Assignment")
- s.employee = d.employee
- s.employee_name = d.employee_name
- s.salary_structure = d.parent
- s.from_date = d.from_date
- s.to_date = d.to_date
- s.base = d.base
- s.variable = d.variable
- s.company = d.company
+ where ss.name = sse.parent AND sse.employee in (select name from `tabEmployee` where ifNull(status, '') != 'Left')""", as_dict=1):
+ try:
+ s = frappe.new_doc("Salary Structure Assignment")
+ s.employee = d.employee
+ s.employee_name = d.employee_name
+ s.salary_structure = d.parent
+ s.from_date = d.from_date
+ s.to_date = d.to_date if isinstance(d.to_date, datetime) else None
+ s.base = d.base
+ s.variable = d.variable
+ s.company = d.company
- # to migrate the data of the old employees
- s.flags.old_employee = True
- s.save()
+ # to migrate the data of the old employees
+ s.flags.old_employee = True
+ s.save()
+ except DuplicateAssignment:
+ pass
frappe.db.sql("update `tabSalary Structure` set docstatus=1")
\ No newline at end of file
diff --git a/erpnext/patches/v11_0/make_location_from_warehouse.py b/erpnext/patches/v11_0/make_location_from_warehouse.py
index b838ec9..b5b2e17 100644
--- a/erpnext/patches/v11_0/make_location_from_warehouse.py
+++ b/erpnext/patches/v11_0/make_location_from_warehouse.py
@@ -10,7 +10,7 @@
frappe.reload_doc('stock', 'doctype', 'warehouse')
for d in frappe.get_all('Warehouse',
- fields = ['warehouse_name', 'is_group', 'parent_warehouse'], order_by="is_group desc"):
+ fields = ['warehouse_name', 'is_group', 'parent_warehouse'], order_by="lft asc"):
try:
loc = frappe.new_doc('Location')
loc.location_name = d.warehouse_name
diff --git a/erpnext/regional/report/gstr_1/gstr_1.py b/erpnext/regional/report/gstr_1/gstr_1.py
index f9e0156..2c128e7 100644
--- a/erpnext/regional/report/gstr_1/gstr_1.py
+++ b/erpnext/regional/report/gstr_1/gstr_1.py
@@ -23,7 +23,7 @@
posting_date,
base_grand_total,
base_rounded_total,
- customer_gstin,
+ COALESCE(NULLIF(customer_gstin,''), NULLIF(billing_address_gstin, '')) as customer_gstin,
place_of_supply,
ecommerce_gstin,
reverse_charge,
diff --git a/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py b/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
index e57636c..e7bb5b4 100644
--- a/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
+++ b/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
@@ -91,17 +91,22 @@
start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:]
item_details = frappe.db.sql("""
- select
- sum(soi.stock_qty * (st.allocated_percentage/100)) as qty,
- sum(soi.base_net_amount * (st.allocated_percentage/100)) as amount,
- st.sales_person, MONTHNAME(so.transaction_date) as month_name
+ SELECT st.sales_person, MONTHNAME(so.transaction_date) as month_name,
+ CASE
+ WHEN so.status = "Closed" THEN sum(soi.delivered_qty * soi.conversion_factor * (st.allocated_percentage/100))
+ ELSE sum(soi.stock_qty * (st.allocated_percentage/100))
+ END as qty,
+ CASE
+ WHEN so.status = "Closed" THEN sum(soi.delivered_qty * soi.conversion_factor * soi.base_net_rate * (st.allocated_percentage/100))
+ ELSE soi.base_net_amount * (st.allocated_percentage/100))
+ END as amount
from
`tabSales Order Item` soi, `tabSales Order` so, `tabSales Team` st
where
soi.parent=so.name and so.docstatus=1 and st.parent=so.name
and so.transaction_date>=%s and so.transaction_date<=%s
- and exists(select name from `tabSales Person` where lft >= %s and rgt <= %s and name=st.sales_person)
- and exists(select name from `tabItem Group` where lft >= %s and rgt <= %s and name=soi.item_group)
+ and exists(SELECT name from `tabSales Person` where lft >= %s and rgt <= %s and name=st.sales_person)
+ and exists(SELECT name from `tabItem Group` where lft >= %s and rgt <= %s and name=soi.item_group)
group by
sales_person, month_name
""",
diff --git a/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py b/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py
index 025e740..19b6774 100644
--- a/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py
+++ b/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py
@@ -15,11 +15,12 @@
data = []
for d in entries:
- data.append([
- d.name, d.customer, d.territory, d.posting_date, d.item_code,
- item_details.get(d.item_code, {}).get("item_group"), item_details.get(d.item_code, {}).get("brand"),
- d.stock_qty, d.base_net_amount, d.sales_person, d.allocated_percentage, d.contribution_amt
- ])
+ if d.stock_qty > 0:
+ data.append([
+ d.name, d.customer, d.territory, d.posting_date, d.item_code,
+ item_details.get(d.item_code, {}).get("item_group"), item_details.get(d.item_code, {}).get("brand"),
+ d.stock_qty, d.base_net_amount, d.sales_person, d.allocated_percentage, d.contribution_amt
+ ])
if data:
total_row = [""]*len(data[0])
@@ -40,18 +41,34 @@
def get_entries(filters):
date_field = filters["doc_type"] == "Sales Order" and "transaction_date" or "posting_date"
+ if filters["doc_type"] == "Sales Order":
+ qty_field = "delivered_qty"
+ else:
+ qty_field = "qty"
conditions, values = get_conditions(filters, date_field)
+
entries = frappe.db.sql("""
select
dt.name, dt.customer, dt.territory, dt.%s as posting_date, dt_item.item_code,
- dt_item.stock_qty, dt_item.base_net_amount, st.sales_person, st.allocated_percentage,
- dt_item.base_net_amount*st.allocated_percentage/100 as contribution_amt
+ st.sales_person, st.allocated_percentage,
+ CASE
+ WHEN dt.status = "Closed" THEN dt_item.%s * dt_item.conversion_factor
+ ELSE dt_item.stock_qty
+ END as stock_qty,
+ CASE
+ WHEN dt.status = "Closed" THEN (dt_item.base_net_rate * dt_item.%s * dt_item.conversion_factor)
+ ELSE dt_item.base_net_amount
+ END as base_net_amount,
+ CASE
+ WHEN dt.status = "Closed" THEN ((dt_item.base_net_rate * dt_item.%s * dt_item.conversion_factor) * st.allocated_percentage/100)
+ ELSE dt_item.base_net_amount * st.allocated_percentage/100
+ END as contribution_amt
from
`tab%s` dt, `tab%s Item` dt_item, `tabSales Team` st
where
st.parent = dt.name and dt.name = dt_item.parent and st.parenttype = %s
and dt.docstatus = 1 %s order by st.sales_person, dt.name desc
- """ %(date_field, filters["doc_type"], filters["doc_type"], '%s', conditions),
+ """ %(date_field, qty_field, qty_field, qty_field, filters["doc_type"], filters["doc_type"], '%s', conditions),
tuple([filters["doc_type"]] + values), as_dict=1)
return entries
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index 1269705..64d7c23 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -541,7 +541,7 @@
def update_item_price(self):
frappe.db.sql("""update `tabItem Price` set item_name=%s,
- item_description=%s, brand=%s, modified=NOW() where item_code=%s""",
+ item_description=%s, brand=%s where item_code=%s""",
(self.item_name, self.description, self.brand, self.name))
def on_trash(self):
diff --git a/erpnext/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js
index 62ea2b6..bd49adf 100644
--- a/erpnext/stock/doctype/material_request/material_request.js
+++ b/erpnext/stock/doctype/material_request/material_request.js
@@ -58,7 +58,6 @@
$.each(r.message, function(k, v) {
if(!d[k]) d[k] = v;
});
- debugger
}
}
});
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 849a294..4a9c029 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -566,7 +566,7 @@
item = frappe.db.sql("""select i.stock_uom, i.description, i.image, i.item_name, i.item_group,
i.has_batch_no, i.sample_quantity, i.has_serial_no,
id.expense_account, id.buying_cost_center
- from `tabItem`, `tabItem Default` id
+ from `tabItem` i, `tabItem Default` id
where i.name=%s and i.name=id.parent and id.company=%s
and i.disabled=0
and (i.end_of_life is null or i.end_of_life='0000-00-00' or i.end_of_life > %s)""",
diff --git a/erpnext/stock/doctype/warehouse/warehouse.js b/erpnext/stock/doctype/warehouse/warehouse.js
index 1bfa416..1bea00e 100644
--- a/erpnext/stock/doctype/warehouse/warehouse.js
+++ b/erpnext/stock/doctype/warehouse/warehouse.js
@@ -39,6 +39,8 @@
frm.toggle_enable(['is_group', 'company'], false);
+ frappe.dynamic_link = {doc: frm.doc, fieldname: 'name', doctype: 'Warehouse'};
+
frm.fields_dict['parent_warehouse'].get_query = function(doc) {
return {
filters: {
diff --git a/erpnext/support/doctype/issue/issue.json b/erpnext/support/doctype/issue/issue.json
index d2ec7c3..923a79c 100644
--- a/erpnext/support/doctype/issue/issue.json
+++ b/erpnext/support/doctype/issue/issue.json
@@ -926,6 +926,37 @@
"set_only_once": 0,
"translatable": 0,
"unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "via_customer_portal",
+ "fieldtype": "Check",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Via Customer Portal",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
}
],
"has_web_view": 0,
@@ -939,7 +970,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2018-04-13 13:03:14.748090",
+ "modified": "2018-05-07 05:53:20.684275",
"modified_by": "Administrator",
"module": "Support",
"name": "Issue",
diff --git a/erpnext/support/doctype/issue/issue.py b/erpnext/support/doctype/issue/issue.py
index 6a18f11..dfcc2a8 100644
--- a/erpnext/support/doctype/issue/issue.py
+++ b/erpnext/support/doctype/issue/issue.py
@@ -17,6 +17,8 @@
return "{0}: {1}".format(_(self.status), self.subject)
def validate(self):
+ if (self.get("__islocal") and self.via_customer_portal):
+ self.flags.create_communication = True
if not self.raised_by:
self.raised_by = frappe.session.user
self.update_status()
@@ -26,6 +28,12 @@
from frappe.desk.form.assign_to import clear
clear(self.doctype, self.name)
+ def on_update(self):
+ # create the communication email and remove the description
+ if (self.flags.create_communication and self.via_customer_portal):
+ self.create_communication()
+ self.flags.communication_created = None
+
def set_lead_contact(self, email_id):
import email.utils
email_id = email.utils.parseaddr(email_id)[1]
@@ -53,6 +61,26 @@
# if no date, it should be set as None and not a blank string "", as per mysql strict config
self.resolution_date = None
+ def create_communication(self):
+ communication = frappe.new_doc("Communication")
+ communication.update({
+ "communication_type": "Communication",
+ "communication_medium": "Email",
+ "sent_or_received": "Received",
+ "email_status": "Open",
+ "subject": self.subject,
+ "sender": self.raised_by,
+ "content": self.description,
+ "status": "Linked",
+ "reference_doctype": "Issue",
+ "reference_name": self.name
+ })
+ communication.ignore_permissions = True
+ communication.ignore_mandatory = True
+ communication.save()
+
+ self.db_set("description", "")
+
def get_list_context(context=None):
return {
"title": _("Issues"),
diff --git a/erpnext/support/doctype/support_search_source/__init__.py b/erpnext/support/doctype/support_search_source/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/support/doctype/support_search_source/__init__.py
diff --git a/erpnext/support/doctype/support_search_source/support_search_source.json b/erpnext/support/doctype/support_search_source/support_search_source.json
new file mode 100644
index 0000000..db3a7bb
--- /dev/null
+++ b/erpnext/support/doctype/support_search_source/support_search_source.json
@@ -0,0 +1,668 @@
+{
+ "allow_copy": 0,
+ "allow_guest_to_view": 0,
+ "allow_import": 0,
+ "allow_rename": 0,
+ "beta": 0,
+ "creation": "2018-05-16 21:15:21.207007",
+ "custom": 0,
+ "docstatus": 0,
+ "doctype": "DocType",
+ "document_type": "",
+ "editable_grid": 1,
+ "engine": "InnoDB",
+ "fields": [
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "source_name",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 1,
+ "in_standard_filter": 0,
+ "label": "Source Name",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "source_type",
+ "fieldtype": "Select",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 1,
+ "in_standard_filter": 0,
+ "label": "Source Type",
+ "length": 0,
+ "no_copy": 0,
+ "options": "API\nLink",
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 1,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "depends_on": "eval:doc.source_type==\"API\"",
+ "fieldname": "api_sb",
+ "fieldtype": "Section Break",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "API",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "base_url",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Base URL",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "collapsible_depends_on": "",
+ "columns": 0,
+ "depends_on": "eval:doc.source_type==\"API\"",
+ "fieldname": "query_options_sb",
+ "fieldtype": "Section Break",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Query Options",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "query_route",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Query Route String",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "cb_1",
+ "fieldtype": "Column Break",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "search_term_param_name",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Search Term Param Name",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "collapsible_depends_on": "",
+ "columns": 0,
+ "depends_on": "eval:doc.source_type==\"API\"",
+ "fieldname": "response_options_sb",
+ "fieldtype": "Section Break",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Response Options",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "response_result_key_path",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Response Result Key Path",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "post_route",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Post Route String",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "post_route_key_list",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Post Route Key List",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "response_post_cb",
+ "fieldtype": "Column Break",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "post_title_key",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Post Title Key",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "post_description_key",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Post Description Key",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "collapsible_depends_on": "",
+ "columns": 0,
+ "depends_on": "eval:doc.source_type==\"Link\"",
+ "fieldname": "link_options_sb",
+ "fieldtype": "Section Break",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Link Options",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "source_doctype",
+ "fieldtype": "Link",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Source DocType",
+ "length": 0,
+ "no_copy": 0,
+ "options": "DocType",
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "result_title_field",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Result Title Field",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "result_preview_field",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Result Preview Field",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "result_route_field",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Result Route Field",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ }
+ ],
+ "has_web_view": 0,
+ "hide_heading": 0,
+ "hide_toolbar": 0,
+ "idx": 0,
+ "image_view": 0,
+ "in_create": 0,
+ "is_submittable": 0,
+ "issingle": 0,
+ "istable": 1,
+ "max_attachments": 0,
+ "modified": "2018-05-18 18:36:37.129830",
+ "modified_by": "Administrator",
+ "module": "Support",
+ "name": "Support Search Source",
+ "name_case": "",
+ "owner": "Administrator",
+ "permissions": [],
+ "quick_entry": 1,
+ "read_only": 0,
+ "read_only_onload": 0,
+ "show_name_in_global_search": 0,
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "track_changes": 1,
+ "track_seen": 0
+}
\ No newline at end of file
diff --git a/erpnext/support/doctype/support_search_source/support_search_source.py b/erpnext/support/doctype/support_search_source/support_search_source.py
new file mode 100644
index 0000000..93e503a
--- /dev/null
+++ b/erpnext/support/doctype/support_search_source/support_search_source.py
@@ -0,0 +1,9 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+from frappe.model.document import Document
+
+class SupportSearchSource(Document):
+ pass
diff --git a/erpnext/support/doctype/support_settings/support_settings.json b/erpnext/support/doctype/support_settings/support_settings.json
index 7adfd4d..2b79107 100644
--- a/erpnext/support/doctype/support_settings/support_settings.json
+++ b/erpnext/support/doctype/support_settings/support_settings.json
@@ -1,92 +1,560 @@
{
- "allow_copy": 0,
- "allow_import": 0,
- "allow_rename": 0,
- "beta": 0,
- "creation": "2017-02-17 13:07:35.686409",
- "custom": 0,
- "docstatus": 0,
- "doctype": "DocType",
- "document_type": "",
- "editable_grid": 1,
- "engine": "InnoDB",
+ "allow_copy": 0,
+ "allow_guest_to_view": 0,
+ "allow_import": 0,
+ "allow_rename": 0,
+ "beta": 0,
+ "creation": "2017-02-17 13:07:35.686409",
+ "custom": 0,
+ "docstatus": 0,
+ "doctype": "DocType",
+ "document_type": "",
+ "editable_grid": 1,
+ "engine": "InnoDB",
"fields": [
{
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "default": "7",
- "description": "Auto close Issue after 7 days",
- "fieldname": "close_issue_after_days",
- "fieldtype": "Int",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "label": "Close Issue After Days",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "issues_sb",
+ "fieldtype": "Section Break",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Issues",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "default": "7",
+ "description": "Auto close Issue after 7 days",
+ "fieldname": "close_issue_after_days",
+ "fieldtype": "Int",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Close Issue After Days",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "portal_sb",
+ "fieldtype": "Section Break",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Support Portal",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "get_started_sections",
+ "fieldtype": "Code",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Get Started Sections",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "show_latest_forum_posts",
+ "fieldtype": "Check",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Show Latest Forum Posts",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "depends_on": "show_latest_forum_posts",
+ "fieldname": "forum_sb",
+ "fieldtype": "Section Break",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Forum Posts",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "forum_url",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Forum URL",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "get_latest_query",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Get Latest Query",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "response_key_list",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Response Key List",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "column_break_10",
+ "fieldtype": "Column Break",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "post_title_key",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Post Title Key",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "post_description_key",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Post Description Key",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "post_route_key",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Post Route Key",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "post_route_string",
+ "fieldtype": "Data",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Post Route String",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "search_apis_sb",
+ "fieldtype": "Section Break",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Search APIs",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "search_apis",
+ "fieldtype": "Table",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Search APIs",
+ "length": 0,
+ "no_copy": 0,
+ "options": "Support Search Source",
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
"unique": 0
}
- ],
- "hide_heading": 0,
- "hide_toolbar": 0,
- "idx": 0,
- "image_view": 0,
- "in_create": 0,
-
- "is_submittable": 0,
- "issingle": 1,
- "istable": 0,
- "max_attachments": 0,
- "modified": "2017-02-17 13:07:46.049536",
- "modified_by": "Administrator",
- "module": "Support",
- "name": "Support Settings",
- "name_case": "",
- "owner": "Administrator",
+ ],
+ "has_web_view": 0,
+ "hide_heading": 0,
+ "hide_toolbar": 0,
+ "idx": 0,
+ "image_view": 0,
+ "in_create": 0,
+ "is_submittable": 0,
+ "issingle": 1,
+ "istable": 0,
+ "max_attachments": 0,
+ "modified": "2018-05-17 02:11:33.462444",
+ "modified_by": "Administrator",
+ "module": "Support",
+ "name": "Support Settings",
+ "name_case": "",
+ "owner": "Administrator",
"permissions": [
{
- "amend": 0,
- "apply_user_permissions": 0,
- "cancel": 0,
- "create": 1,
- "delete": 1,
- "email": 1,
- "export": 0,
- "if_owner": 0,
- "import": 0,
- "permlevel": 0,
- "print": 1,
- "read": 1,
- "report": 0,
- "role": "System Manager",
- "set_user_permissions": 0,
- "share": 1,
- "submit": 0,
+ "amend": 0,
+ "cancel": 0,
+ "create": 1,
+ "delete": 1,
+ "email": 1,
+ "export": 0,
+ "if_owner": 0,
+ "import": 0,
+ "permlevel": 0,
+ "print": 1,
+ "read": 1,
+ "report": 0,
+ "role": "System Manager",
+ "set_user_permissions": 0,
+ "share": 1,
+ "submit": 0,
"write": 1
}
- ],
- "quick_entry": 1,
- "read_only": 0,
- "read_only_onload": 0,
- "show_name_in_global_search": 0,
- "sort_field": "modified",
- "sort_order": "DESC",
- "track_changes": 1,
+ ],
+ "quick_entry": 1,
+ "read_only": 0,
+ "read_only_onload": 0,
+ "show_name_in_global_search": 0,
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "track_changes": 1,
"track_seen": 0
}
\ No newline at end of file
diff --git a/erpnext/support/doctype/support_settings/test_support_settings.js b/erpnext/support/doctype/support_settings/test_support_settings.js
new file mode 100644
index 0000000..0787306
--- /dev/null
+++ b/erpnext/support/doctype/support_settings/test_support_settings.js
@@ -0,0 +1,23 @@
+/* eslint-disable */
+// rename this file from _test_[name] to test_[name] to activate
+// and remove above this line
+
+QUnit.test("test: Support Settings", function (assert) {
+ let done = assert.async();
+
+ // number of asserts
+ assert.expect(1);
+
+ frappe.run_serially([
+ // insert a new Support Settings
+ () => frappe.tests.make('Support Settings', [
+ // values to be set
+ {key: 'value'}
+ ]),
+ () => {
+ assert.equal(cur_frm.doc.key, 'value');
+ },
+ () => done()
+ ]);
+
+});
diff --git a/erpnext/support/doctype/support_settings/test_support_settings.py b/erpnext/support/doctype/support_settings/test_support_settings.py
new file mode 100644
index 0000000..9c47f96
--- /dev/null
+++ b/erpnext/support/doctype/support_settings/test_support_settings.py
@@ -0,0 +1,9 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
+# See license.txt
+from __future__ import unicode_literals
+
+import unittest
+
+class TestSupportSettings(unittest.TestCase):
+ pass
diff --git a/erpnext/support/web_form/issues/issues.json b/erpnext/support/web_form/issues/issues.json
index 264b9df..a8c7ab9 100644
--- a/erpnext/support/web_form/issues/issues.json
+++ b/erpnext/support/web_form/issues/issues.json
@@ -18,7 +18,7 @@
"is_standard": 1,
"login_required": 1,
"max_attachment_size": 0,
- "modified": "2017-07-25 22:49:10.762704",
+ "modified": "2018-05-07 05:54:22.213127",
"modified_by": "Administrator",
"module": "Support",
"name": "issues",
@@ -83,6 +83,17 @@
"max_value": 0,
"read_only": 0,
"reqd": 0
+ },
+ {
+ "default": "1",
+ "fieldname": "via_customer_portal",
+ "fieldtype": "Check",
+ "hidden": 1,
+ "label": "Via Customer Portal",
+ "max_length": 0,
+ "max_value": 0,
+ "read_only": 1,
+ "reqd": 0
}
]
}
\ No newline at end of file
diff --git a/erpnext/support/web_form/issues/issues.py b/erpnext/support/web_form/issues/issues.py
index 2334f8b..bb9197a 100644
--- a/erpnext/support/web_form/issues/issues.py
+++ b/erpnext/support/web_form/issues/issues.py
@@ -4,4 +4,5 @@
def get_context(context):
# do your magic here
- pass
+ if context.doc:
+ context.read_only = 1
\ No newline at end of file
diff --git a/erpnext/templates/pages/help.html b/erpnext/templates/pages/help.html
new file mode 100644
index 0000000..f7568d5
--- /dev/null
+++ b/erpnext/templates/pages/help.html
@@ -0,0 +1,62 @@
+{% extends "templates/web.html" %}
+
+{% block title %} {{ _("Help") }} {% endblock %}
+
+{% block header %}<h1>{{ _("Help") }}</h1>
+
+<div style="margin-bottom: 20px;">
+ <form action='/search_help'>
+ <input name='q' class='form-control' type='text'
+ style='max-width: 400px; display: inline-block; margin-right: 10px;'
+ value='{{ frappe.form_dict.q or ''}}'
+ {% if not frappe.form_dict.q%}placeholder="{{ _("What do you need help with?") }}"{% endif %}>
+ <input type='submit'
+ class='btn btn-sm btn-primary btn-search' value="{{ _("Search") }}">
+ </form>
+</div>
+
+{% for section in get_started_sections %}
+<div style="margin-bottom: 30px;">
+ <h2>{{ section["name"] }}</h2>
+ {% for item in section["items"] %}
+ <div style="margin: 20px 0;">
+ <a href="{{ item.link }}"><b>{{ item.title }}</b></a>
+ {% if item.description -%}
+ <p>{{ item.description }}</p>
+ {%- endif %}
+ </div>
+ {% endfor %}
+ <p><a href="/kb/support">{{ _("See All Articles") }}</a></p>
+ <hr>
+</div>
+{% endfor %}
+
+<div style="margin-bottom: 30px;">
+ <h2>{{ _("Forum Activity") }}</h2>
+ {% for topic in topics %}
+ <div style="margin: 20px 0;">
+ <a href="{{ topic[post_params.link] }}">
+ <b>{{ topic[post_params.title] }}</b>
+ </a>
+ {% if topic[post_params.description] -%}
+ <p>{{ topic[post_params.description] }}</p>
+ {%- endif %}
+ </div>
+ {% endfor %}
+ <p><a href="{{ forum_url }}">{{ _("Visit the forums") }}</a></p>
+ <hr>
+</div>
+
+<div style="margin-bottom: 20px;">
+ <h2>{{ _("Your tickets") }}</h2>
+ {% for doc in issues %}
+ {% include "templates/includes/issue_row.html" %}
+ {% endfor %}
+ <p><a href="/issues">{{ _("See all open tickets") }}</a></p>
+</div>
+
+<a href="/issues?new=1" class="btn btn-primary btn-new btn-sm">
+ {{ _("Open a new ticket") }}
+</a>
+
+{% endblock %}
diff --git a/erpnext/templates/pages/help.py b/erpnext/templates/pages/help.py
new file mode 100644
index 0000000..754a09c
--- /dev/null
+++ b/erpnext/templates/pages/help.py
@@ -0,0 +1,41 @@
+from __future__ import unicode_literals
+import frappe, json
+
+import requests
+
+def get_context(context):
+ context.no_cache = 1
+ settings = frappe.get_doc("Support Settings", "Support Settings")
+ s = settings
+
+ # Get Started sections
+ sections = json.loads(s.get_started_sections)
+ context.get_started_sections = sections
+
+ # Forum posts
+ topics_data, post_params = get_forum_posts(s)
+ context.post_params = post_params
+ context.forum_url = s.forum_url
+ context.topics = topics_data[:3]
+
+ # Issues
+ context.issues = frappe.get_list("Issue")[:3]
+
+def get_forum_posts(s):
+ response = requests.get(s.forum_url + '/' + s.get_latest_query)
+ response.raise_for_status()
+ response_json = response.json()
+
+ topics_data = {} # it will actually be an array
+ key_list = s.response_key_list.split(',')
+ for key in key_list:
+ topics_data = response_json.get(key) if not topics_data else topics_data.get(key)
+
+ for topic in topics_data:
+ topic["link"] = s.forum_url + '/' + s.post_route_string + '/' + str(topic.get(s.post_route_key))
+
+ post_params = {
+ "title": s.post_title_key,
+ "description": s.post_description_key
+ }
+ return topics_data, post_params
diff --git a/erpnext/templates/pages/search_help.html b/erpnext/templates/pages/search_help.html
new file mode 100644
index 0000000..bf19540
--- /dev/null
+++ b/erpnext/templates/pages/search_help.html
@@ -0,0 +1,7 @@
+{% extends "templates/web.html" %}
+
+{% block page_content %}
+
+{% include "templates/includes/search_template.html" %}
+
+{% endblock %}
diff --git a/erpnext/templates/pages/search_help.py b/erpnext/templates/pages/search_help.py
new file mode 100644
index 0000000..e564e21
--- /dev/null
+++ b/erpnext/templates/pages/search_help.py
@@ -0,0 +1,99 @@
+from __future__ import unicode_literals
+import frappe, requests
+from frappe import _
+from jinja2 import utils
+from html2text import html2text
+from frappe.utils import sanitize_html
+from frappe.utils.global_search import search
+
+def get_context(context):
+ context.no_cache = 1
+ if frappe.form_dict.q:
+ query = str(utils.escape(sanitize_html(frappe.form_dict.q)))
+ context.title = _('Help Results for "{0}"').format(query)
+ context.route = '/search_help'
+ d = frappe._dict()
+ d.results_sections = get_help_results_sections(query)
+ context.update(d)
+ else:
+ context.title = _('Docs Search')
+
+@frappe.whitelist(allow_guest = True)
+def get_help_results_sections(text):
+ out = []
+ settings = frappe.get_doc("Support Settings", "Support Settings")
+
+ for api in settings.search_apis:
+ results = []
+ if api.source_type == "API":
+ response_json = get_response(api, text)
+ topics_data = get_topics_data(api, response_json)
+ results = prepare_api_results(api, topics_data)
+ else:
+ # Source type is Doctype
+ doctype = api.source_doctype
+ raw = search(text, 0, 20, doctype)
+ results = prepare_doctype_results(api, raw)
+
+ if results:
+ # Add section
+ out.append({
+ "title": api.source_name,
+ "results": results
+ })
+
+ return out
+
+def get_response(api, text):
+ response = requests.get(api.base_url + '/' + api.query_route, data={
+ api.search_term_param_name: text
+ })
+
+ response.raise_for_status()
+ return response.json()
+
+def get_topics_data(api, response_json):
+ if not response_json:
+ response_json = {}
+ topics_data = {} # it will actually be an array
+ key_list = api.response_result_key_path.split(',')
+
+ for key in key_list:
+ topics_data = response_json.get(key) if not topics_data else topics_data.get(key)
+
+ return topics_data or []
+
+def prepare_api_results(api, topics_data):
+ if not topics_data:
+ topics_data = []
+
+ results = []
+ for topic in topics_data:
+ route = api.base_url + '/' + (api.post_route + '/' if api.post_route else "")
+ for key in api.post_route_key_list.split(','):
+ route += unicode(topic[key])
+
+ results.append(frappe._dict({
+ 'title': topic[api.post_title_key],
+ 'preview': html2text(topic[api.post_description_key]),
+ 'route': route
+ }))
+ return results[:5]
+
+def prepare_doctype_results(api, raw):
+ results = []
+ for r in raw:
+ prepared_result = {}
+ parts = r["content"].split(' ||| ')
+
+ for part in parts:
+ pair = part.split(' : ', 1)
+ prepared_result[pair[0]] = pair[1]
+
+ results.append(frappe._dict({
+ 'title': prepared_result[api.result_title_field],
+ 'preview': prepared_result[api.result_preview_field],
+ 'route': prepared_result[api.result_route_field]
+ }))
+
+ return results