feat: allow member creation via API
This commit is contained in:
parent
98bcedd09c
commit
e4c58c37c8
@ -9,6 +9,7 @@ from frappe.model.document import Document
|
||||
from frappe.contacts.address_and_contact import load_address_and_contact
|
||||
from frappe.utils import cint
|
||||
from frappe.integrations.utils import get_payment_gateway_controller
|
||||
from erpnext.non_profit.doctype.membership_type.membership_type import get_membership_type
|
||||
|
||||
class Member(Document):
|
||||
def onload(self):
|
||||
@ -74,19 +75,23 @@ def get_or_create_member(user_details):
|
||||
return create_member(user_details)
|
||||
|
||||
def create_member(user_details):
|
||||
user_details = frappe._dict(user_details)
|
||||
member = frappe.new_doc("Member")
|
||||
member.update({
|
||||
"member_name": user_details.fullname,
|
||||
"email_id": user_details.email,
|
||||
"pan_number": user_details.pan or None,
|
||||
"membership_type": user_details.plan_id,
|
||||
"customer": create_customer(user_details)
|
||||
"subscription_id": user_details.subscription_id or None
|
||||
})
|
||||
|
||||
member.insert(ignore_permissions=True)
|
||||
member.customer = create_customer(user_details, member.name)
|
||||
member.save(ignore_permissions=True)
|
||||
|
||||
return member
|
||||
|
||||
def create_customer(user_details):
|
||||
def create_customer(user_details, member=None):
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.customer_name = user_details.fullname
|
||||
customer.customer_type = "Individual"
|
||||
@ -107,7 +112,13 @@ def create_customer(user_details):
|
||||
"link_name": customer.name
|
||||
})
|
||||
|
||||
contact.save()
|
||||
if member:
|
||||
contact.append("links", {
|
||||
"link_doctype": "Member",
|
||||
"link_name": member
|
||||
})
|
||||
|
||||
contact.save(ignore_permissions=True)
|
||||
|
||||
except frappe.DuplicateEntryError:
|
||||
return customer.name
|
||||
@ -139,12 +150,31 @@ def create_member_subscription_order(user_details):
|
||||
|
||||
user_details = frappe._dict(user_details)
|
||||
member = get_or_create_member(user_details)
|
||||
if not member:
|
||||
member = create_member(user_details)
|
||||
|
||||
subscription = member.setup_subscription()
|
||||
|
||||
member.subscription_id = subscription.get('subscription_id')
|
||||
member.save(ignore_permissions=True)
|
||||
|
||||
return subscription
|
||||
return subscription
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def register_member(fullname, email, rzpay_plan_id, subscription_id, pan=None, mobile=None):
|
||||
plan = get_membership_type(rzpay_plan_id)
|
||||
if not plan:
|
||||
raise frappe.DoesNotExistError
|
||||
|
||||
member = frappe.db.exists("Member", {'email': email, 'subscription_id': subscription_id })
|
||||
if member:
|
||||
return member
|
||||
else:
|
||||
member = create_member(dict(
|
||||
fullname=fullname,
|
||||
email=email,
|
||||
plan_id=plan,
|
||||
subscription_id=subscription_id,
|
||||
pan=pan,
|
||||
mobile=mobile
|
||||
))
|
||||
|
||||
return member.name
|
@ -39,12 +39,12 @@
|
||||
"fieldname": "linked_item",
|
||||
"fieldtype": "Link",
|
||||
"label": "Linked Item",
|
||||
"options": "Item"
|
||||
"options": "Item",
|
||||
"unique": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2020-07-28 10:57:50.821375",
|
||||
"modified": "2020-08-05 15:21:43.595745",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Non Profit",
|
||||
"name": "Membership Type",
|
||||
|
@ -4,6 +4,10 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from frappe.model.document import Document
|
||||
import frappe
|
||||
|
||||
class MembershipType(Document):
|
||||
pass
|
||||
pass
|
||||
|
||||
def get_membership_type(razorpay_id):
|
||||
return frappe.db.exists("Membership Type", {"razorpay_plan_id": razorpay_id})
|
Loading…
Reference in New Issue
Block a user