feat: add auto invoice creation fields and controllers
This commit is contained in:
parent
96dc67c35e
commit
811ac909f9
@ -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,
|
||||
|
@ -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. ") + `<a href='${docs_url}'>${__('ERPNext Docs')}</a>`, true);
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user