diff --git a/erpnext/non_profit/doctype/member/member.js b/erpnext/non_profit/doctype/member/member.js index 3e9d0baba5..199dcfc04f 100644 --- a/erpnext/non_profit/doctype/member/member.js +++ b/erpnext/non_profit/doctype/member/member.js @@ -29,6 +29,14 @@ frappe.ui.form.on('Member', { frappe.set_route('query-report', 'Accounts Receivable', {member:frm.doc.name}); }); + if (!frm.doc.customer) { + frm.add_custom_button(__('Create Customer'), () => { + frm.call('make_customer_and_link').then(() => { + frm.reload_doc(); + }); + }); + } + // indicator erpnext.utils.set_party_dashboard_indicators(frm); diff --git a/erpnext/non_profit/doctype/member/member.py b/erpnext/non_profit/doctype/member/member.py index 7818c99fbe..c52082ca23 100644 --- a/erpnext/non_profit/doctype/member/member.py +++ b/erpnext/non_profit/doctype/member/member.py @@ -53,6 +53,19 @@ class Member(Document): return subscription + def make_customer_and_link(self): + if self.customer: + frappe.msgprint(_("A customer is already linked to this Member")) + cust = create_customer(frappe._dict({ + 'fullname': self.member_name, + 'email': self.email_id or self.user, + 'phone': None + })) + + self.customer = cust + self.save() + + def get_or_create_member(user_details): member_list = frappe.get_all("Member", filters={'email': user_details.email, 'membership_type': user_details.plan_id}) if member_list and member_list[0]: @@ -83,8 +96,10 @@ def create_customer(user_details): try: contact = frappe.new_doc("Contact") contact.first_name = user_details.fullname - contact.add_phone(user_details.mobile, is_primary_phone=1, is_primary_mobile_no=1) - contact.add_email(user_details.email, is_primary=1) + if user_details.mobile: + contact.add_phone(user_details.mobile, is_primary_phone=1, is_primary_mobile_no=1) + if user_details.email: + contact.add_email(user_details.email, is_primary=1) contact.insert(ignore_permissions=True) contact.append("links", { diff --git a/erpnext/non_profit/doctype/membership/membership.json b/erpnext/non_profit/doctype/membership/membership.json index 9f10d0cfc7..238f4c31fd 100644 --- a/erpnext/non_profit/doctype/membership/membership.json +++ b/erpnext/non_profit/doctype/membership/membership.json @@ -120,13 +120,15 @@ { "fieldname": "webhook_payload", "fieldtype": "Code", + "hidden": 1, "label": "Webhook Payload", "options": "JSON", "read_only": 1 } ], + "index_web_pages_for_search": 1, "links": [], - "modified": "2020-04-06 14:29:33.856060", + "modified": "2020-07-27 14:28:11.532696", "modified_by": "Administrator", "module": "Non Profit", "name": "Membership",