diff --git a/erpnext/non_profit/doctype/membership/membership.py b/erpnext/non_profit/doctype/membership/membership.py index 729e111e57..eea18393f1 100644 --- a/erpnext/non_profit/doctype/membership/membership.py +++ b/erpnext/non_profit/doctype/membership/membership.py @@ -57,6 +57,35 @@ class Membership(Document): self.load_from_db() self.db_set('paid', 1) + def generate_and_send_invoice(self): + if not self.paid: + frappe.throw(_("The payment for this membership is not paid. To generate invoice mark the paid check")) + + member = frappe.get_doc("Member", self.member) + plan = frappe.get_doc("Membership Type", self.membership_type) + settings = frappe.get_doc("Membership Settings") + + invoice = make_invoice(self, member, plan, settings) + +def make_invoice(membership, member, plan, settings): + invoice = frappe.get_doc({ + 'doctype': 'Sales Invoice', + 'customer': member.customer, + 'debit_to': settings.debit_account, + 'currency': membership.currency, + 'is_pos': 0, + 'items': [ + { + 'item_code': plan.linked_item, + 'rate': membership.amount, + 'qty': 1 + } + ] + }) + + invoice.insert(ignore_permissions=True) + invoice.submit() + def get_member_based_on_subscription(subscription_id, email): members = frappe.get_all("Member", filters={ 'subscription_id': subscription_id, diff --git a/erpnext/non_profit/doctype/membership_settings/membership_settings.js b/erpnext/non_profit/doctype/membership_settings/membership_settings.js index f5e0274c3a..02ef0292ea 100644 --- a/erpnext/non_profit/doctype/membership_settings/membership_settings.js +++ b/erpnext/non_profit/doctype/membership_settings/membership_settings.js @@ -19,6 +19,16 @@ frappe.ui.form.on("Membership Settings", { }; }); + frm.set_query('debit_account', function(doc) { + return { + filters: { + 'account_type': 'Receivable', + 'is_group': 0, + 'company': frm.doc.company + } + }; + }); + let docs_url = "https://docs.erpnext.com/docs/user/manual/en/non_profit/membership"; frm.set_intro(__("You can learn more about memberships in the manual. ") + `${__('ERPNext Docs')}`, true); diff --git a/erpnext/non_profit/doctype/membership_settings/membership_settings.json b/erpnext/non_profit/doctype/membership_settings/membership_settings.json index 29013fafdc..37bea49826 100644 --- a/erpnext/non_profit/doctype/membership_settings/membership_settings.json +++ b/erpnext/non_profit/doctype/membership_settings/membership_settings.json @@ -11,8 +11,15 @@ "billing_frequency", "webhook_secret", "column_break_6", + "print_format", + "company", + "debit_account", + "column_break_9", "enable_auto_invoicing", - "print_format" + "send_invoice", + "section_break_10", + "new_member", + "renewal" ], "fields": [ { @@ -47,7 +54,8 @@ }, { "fieldname": "column_break_6", - "fieldtype": "Column Break" + "fieldtype": "Section Break", + "label": "Invoicing" }, { "default": "0", @@ -56,18 +64,57 @@ "label": "Enable Auto Invoicing" }, { - "depends_on": "eval:doc.enable_auto_invoicing", "fieldname": "print_format", "fieldtype": "Link", "label": "Print Format", - "mandatory_depends_on": "eval:doc.enable_auto_invoicing", "options": "Print Format" + }, + { + "fieldname": "new_member", + "fieldtype": "Text Editor", + "label": "Message for New Member", + "mandatory_depends_on": "eval:doc.send_invoice" + }, + { + "fieldname": "renewal", + "fieldtype": "Text Editor", + "label": "Message for Renewal", + "mandatory_depends_on": "eval:doc.send_invoice" + }, + { + "depends_on": "eval:doc.company", + "fieldname": "debit_account", + "fieldtype": "Link", + "label": "Debit Account", + "options": "Account" + }, + { + "depends_on": "eval:doc.send_invoice", + "fieldname": "section_break_10", + "fieldtype": "Section Break", + "hide_border": 1 + }, + { + "fieldname": "column_break_9", + "fieldtype": "Column Break" + }, + { + "fieldname": "company", + "fieldtype": "Link", + "label": "Company", + "options": "Company" + }, + { + "default": "0", + "fieldname": "send_invoice", + "fieldtype": "Check", + "label": "Send Email with Invoice" } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2020-07-28 11:01:40.125896", + "modified": "2020-07-28 12:18:35.289893", "modified_by": "Administrator", "module": "Non Profit", "name": "Membership Settings",