Hello everyone,
Can anyone help me if there is any way in Non Profit Module- to create Bulk Sales Invoices from Multiple memberships. That is one selects the memberships and Bulk sales Invoices are generated against the selected memberships.
Thanks
NCP
September 25, 2024, 11:23am
2
Possible with a server script.
Otherwise, you can use both the client and server side.
Ok can you help with sample code please
Thanks
NCP
September 25, 2024, 11:37am
4
That for, you have to write a code on listview level:
frappe.listview_settings['Membership'] = {
onload: function(listview) {
listview.page.add_action_item(__('Create Bulk Sales Invoices'), function() {
const selected_memberships = listview.get_checked_items();
if (selected_memberships.length === 0) {
frappe.msgprint(__('Please select at least one membership'));
return;
}
const membership_ids = selected_memberships.map(m => m.name);
frappe.call({
method: "path.to.your.create_bulk_sales_invoices",
args: {
selected_memberships: membership_ids
},
callback: function(response) {
if (response.message) {
frappe.msgprint(response.message);
}
}
});
});
}
};
Server side:
import frappe
@frappe.whitelist()
def create_bulk_sales_invoices(selected_memberships):
selected_memberships = frappe.parse_json(selected_memberships)
for membership_id in selected_memberships:
membership = frappe.get_doc("Membership", membership_id)
if not membership.is_invoiced:
sales_invoice = frappe.new_doc("Sales Invoice")
sales_invoice.customer = membership.customer
sales_invoice.membership_id = membership.name
sales_invoice.append("items", {
"item_code": membership.membership_type,
"qty": 1,
"rate": membership.amount,
"description": f"Membership for {membership.membership_type}"
})
sales_invoice.insert()
sales_invoice.submit()
membership.is_invoiced = 1
membership.save()
return "Bulk Sales Invoices Created Successfully!"
Now you can set it your according to the scenario.
1 Like
Hello, can i use use server side only ? The above solution did not work. Help with code
Regards,
NCP
November 27, 2024, 6:12am
7
Noreen_Mushema:
server side
Possibile, but you have to use the doc_events .