diff --git a/erpnext/non_profit/doctype/member/member.js b/erpnext/non_profit/doctype/member/member.js index 5cfbe42195..1612e216be 100644 --- a/erpnext/non_profit/doctype/member/member.js +++ b/erpnext/non_profit/doctype/member/member.js @@ -28,5 +28,18 @@ frappe.ui.form.on('Member', { frappe.contacts.clear_address_and_contact(frm); } + frappe.call({ + method:"frappe.client.get_value", + args:{ + 'doctype':"Membership", + 'filters':{'member': frm.doc.name}, + 'fieldname':[ + 'to_date' + ] + }, + callback: function (data) { + frappe.model.set_value(frm.doctype,frm.docname, "expires_on", data.message.to_date); + } + }); } }); diff --git a/erpnext/non_profit/doctype/membership/membership.py b/erpnext/non_profit/doctype/membership/membership.py index e645e5f96e..436f6077f1 100644 --- a/erpnext/non_profit/doctype/membership/membership.py +++ b/erpnext/non_profit/doctype/membership/membership.py @@ -19,6 +19,7 @@ class Membership(Document): member = frappe.get_doc(dict( doctype='Member', email=frappe.session.user, + membership_type=self.membership_type, member_name=user.get_fullname() )).insert(ignore_permissions=True) member_name = member.name @@ -29,12 +30,15 @@ class Membership(Document): # get last membership (if active) last_membership = erpnext.get_last_membership() - if last_membership: + # if person applied for offline membership + if last_membership and not frappe.session.user == "Administrator": # if last membership does not expire in 30 days, then do not allow to renew - if getdate(add_days(last_membership.to_date, -30)) > getdate(nowdate()): + if getdate(add_days(last_membership.to_date, -30)) > getdate(nowdate()) : frappe.throw(_('You can only renew if your membership expires within 30 days')) self.from_date = add_days(last_membership.to_date, 1) + elif frappe.session.user == "Administrator": + self.from_date = self.from_date else: self.from_date = nowdate()