[hotfix] filter doctype if the doctype has subscription field (#11038)
diff --git a/erpnext/accounts/doctype/subscription/subscription.js b/erpnext/accounts/doctype/subscription/subscription.js
index 9c5b264..15927d5 100644
--- a/erpnext/accounts/doctype/subscription/subscription.js
+++ b/erpnext/accounts/doctype/subscription/subscription.js
@@ -3,6 +3,12 @@
frappe.ui.form.on('Subscription', {
setup: function(frm) {
+ frm.fields_dict['reference_doctype'].get_query = function(doc) {
+ return {
+ query: "erpnext.accounts.doctype.subscription.subscription.subscription_doctype_query"
+ };
+ };
+
frm.fields_dict['reference_document'].get_query = function() {
return {
filters: {
diff --git a/erpnext/accounts/doctype/subscription/subscription.py b/erpnext/accounts/doctype/subscription/subscription.py
index 352a0aa..0e14e84 100644
--- a/erpnext/accounts/doctype/subscription/subscription.py
+++ b/erpnext/accounts/doctype/subscription/subscription.py
@@ -276,4 +276,20 @@
doc.update_status(status)
doc.save()
- return doc.status
\ No newline at end of file
+ return doc.status
+
+def subscription_doctype_query(doctype, txt, searchfield, start, page_len, filters):
+ return frappe.db.sql("""select parent from `tabDocField`
+ where fieldname = 'subscription'
+ and parent like %(txt)s
+ order by
+ if(locate(%(_txt)s, parent), locate(%(_txt)s, parent), 99999),
+ parent
+ limit %(start)s, %(page_len)s""".format(**{
+ 'key': searchfield,
+ }), {
+ 'txt': "%%%s%%" % txt,
+ '_txt': txt.replace("%", ""),
+ 'start': start,
+ 'page_len': page_len
+ })
\ No newline at end of file