I have successfully pull customer balance onto Sales Invoice everytime a customer is selected. However, if I am to click Get Items button and pull items from Sales Order, the customer outstanding balance will become zero, and I have to select the customer again in order for the customer balance to appear correctly.
I’m wondering if there’s any way to keep this from happening?
How do I write a validate custom script of the above function. I am at a loss as to where to put the “Validate” trigger for this function to get custom balance when I save the document.
Also, with the script described above, it will only fetch the customer balance on the date same as Sales Invoice posting date. If you want the current customer balance, you’ll need to set the arg: {date: frappe.datetime.nowdate() }
did you create a custom field called: customer_balance?
the custom field can be any name you prefer, just replace the “customer_balance” in the custom script above with the name of your custom field.
You’ll have to create a custom field for “remaining_credit”, another custom field to fetch “credit_limit” from Customer, then write another custom script to calculate the remaining_credit.
I don’t know of any way you can do that in Jinja Template.
The only way I know is create a custom field and use the custom script below to fetch the customer balance and print the custom field in your Jinja Template.
Also even if you could do that in Jinja Template, it is not recommended as the value won’t saved in the database as it would a custom field
Your solution would look something like this, provided you have the following custom fields:
remaining_credit
customer_balance (use the script above to fetch)
credit_limit (fetch it from Customer)
frappe.ui.form.on('Sales Order', {
validate: function(frm, cdt, cdn) {
// make calculation on the fields
var b = flt(frm.doc.credit_limit);
var c = flt(frm.doc.customer_balance);
var a = b - c;
frm.set_value('remaining_balance', a);
frm.refresh_field('remaining_balance');
}
});
Thank you. I tried to fetch credit limit from Customer doctype, but credit_limit is a child table field of Customer Credit Limit table.
I was unable to fetch the credit limit, let alone calculate the remaining credit. I had created three custom fields , customer_balance, credit_limit and remaining_limit.