From fa4b3ba505b45c5f99de77ebf0ffe36d40360887 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 20 Jan 2021 21:59:27 +0530 Subject: [PATCH] fix: basic validations for Membership Type Linked Item --- .../doctype/membership_type/membership_type.js | 12 ++++++++++-- .../doctype/membership_type/membership_type.py | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/erpnext/non_profit/doctype/membership_type/membership_type.js b/erpnext/non_profit/doctype/membership_type/membership_type.js index 94ccdd8334..5bd8a6cf6e 100644 --- a/erpnext/non_profit/doctype/membership_type/membership_type.js +++ b/erpnext/non_profit/doctype/membership_type/membership_type.js @@ -3,12 +3,20 @@ frappe.ui.form.on('Membership Type', { refresh: function (frm) { - frappe.db.get_single_value("Membership Settings", "enable_razorpay").then(val => { + frappe.db.get_single_value('Membership Settings', 'enable_razorpay').then(val => { if (val) frm.set_df_property('razorpay_plan_id', 'hidden', false); }); - frappe.db.get_single_value("Membership Settings", "enable_invoicing").then(val => { + frappe.db.get_single_value('Membership Settings', 'enable_invoicing').then(val => { if (val) frm.set_df_property('linked_item', 'hidden', false); }); + + frm.set_query('linked_item', () => { + return { + filters: { + is_stock_item: 0 + } + } + }) } }); diff --git a/erpnext/non_profit/doctype/membership_type/membership_type.py b/erpnext/non_profit/doctype/membership_type/membership_type.py index b95b04316f..38e6f65556 100644 --- a/erpnext/non_profit/doctype/membership_type/membership_type.py +++ b/erpnext/non_profit/doctype/membership_type/membership_type.py @@ -7,7 +7,11 @@ from frappe.model.document import Document import frappe class MembershipType(Document): - pass + def validate(self): + if self.linked_item: + is_stock_item = frappe.db.get_value("Item", self.linked_item, "is_stock_item") + if is_stock_item: + frappe.throw(_("The Linked Item should be a service item")) def get_membership_type(razorpay_id): return frappe.db.exists("Membership Type", {"razorpay_plan_id": razorpay_id}) \ No newline at end of file