Try ERPNext Buy Support Partners Foundation

Button for customer credit balance

There should be a button to check Customer Credit Balance which opens the report in sales and i have to built it inside the doctype of name Order Book.

any idea, how to do it ?

thanks

Try this on order book js
frm.add_custom_button(__(‘Customer Credit Balance’), function() {
frappe.set_route(‘Form’,‘Report’,‘Customer Credit Balance’);

		})

Hi ,
While solution given is perfect and you may implement it , However , I am keen to know what is the use case ? Do you want to restrict or allow booking of orders when the customer credit balance is not adequate ? If you want to allow the order booking to continue even when credit limit is breached , there is an option at customer master "
Bypass credit limit check at Sales Order" , you may safely use this , If you want to allow order booking even when credit limit is in sufficient but with an approval then you will need to configure erpnext accordingly, Please let me know your use case for further discussions

Rgds
O

this opens the report and then i have to click on the show report inorder to get the balance, after that i have to choose the customer.
what i want is that it should automatically generate it based on the current customer(customer is a field in the doctype).

nothing of that sort. no such conditons applicable as now. just want the customer credit balance.

If you just want to see the outstanding balance of the customer while creating sales order/invoice, then create a custom field ‘outstanding balance’ and use the following custom script:

customer: function(frm) {
frappe.call({
method: “erpnext.accounts.utils.get_balance_on”,
args: {date: frm.doc.posting_date, party_type: ‘Customer’, party: frm.doc.customer},
callback: function® {
frm.doc.outstanding_balance = format_currency(r.message, erpnext.get_currency(frm.doc.company));
refresh_field(‘outstanding_balance’, ‘accounts’);
}
});

THis will autopopulate outstanding balance for the selected customer.

Try this
frm.add_custom_button(__(‘Customer Credit Balance’), function() {
frappe.set_route(‘query-report’, ’ Customer Credit Balance’,
{Customer:frm.doc.name});
});

my client needs a button for it.
so that on clicking the button the customer credit balance report opens in sales for the customer which was selected in the field.

@Nakul_Sharma - thanks for sharing the script. This indeed useful.

If it’s not too much trouble, may you repost the script as I think it did not paste the right way.

If you check , you will see your script has this “®”

Here is the script
customer: function(frm) {

   frappe.call({
       method: "erpnext.accounts.utils.get_balance_on",
       args: {date: frm.doc.posting_date, party_type: 'Customer', party: frm.doc.customer},
       callback: function(r) {
           frm.doc.outstanding_balance = format_currency(r.message, erpnext.get_currency(frm.doc.company));
           refresh_field('outstanding_balance', 'accounts');
       }
   });

@Nakul_Sharma- Thank you very much. This is greatly appreciated.:grinning: