Is it possible to block the creation of a sales invoice if customer has an overdue invoice? If so, how?

Hellow Szufisher.
I appreciate your reference but I had got some thing from those scripts.


But it disable the create the “create button” like below,

How do reference to this buttons.I need to enable restrictions for the “Return/Credit note”

Try this in client script for sales invoice:

frappe.ui.form.on('Sales Invoice', { 
    onload_post_render : function(frm){
        var bt = 'Return / Credit Note'
        if (! (frappe.user.has_role('Account Manager')))
        {
            frm.page.remove_inner_button(bt, 'Create')
            }
        }
    }
);

Note that this will hide the button if the user doesn’t have said role.

You can play around and use frappe.throw to create the error message and block return creation as well.

EDIT: added not operator

1 Like

Hey Ken,
Letmi try its and give you a feedback.
Regards.

Hi Ken,
This hides the button from all roles including the "Account Manager’
Screenshot%20from%202021-06-07%2014-57-25

Check the updated code. Just have to add a not (!) in front of the if condition.

It will then check if the user has the Account Manager role. If not, then it’ll remove the button.

Thanks alot .
It worked as expected

Please write complete script so that we can just paste & save as custom script … it will be very helpful to those who dont know coding.

.