Allocate credit note / debit note to another sales invoice / purchase invoice

frappe.ui.form.on('Sales Invoice', {
    "is_return": function(frm) {
            if (frm.doc.is_return=='1') {
              (frm.set_value('naming_series', 'CN-.YYYY.-'));
            }
            if (frm.doc.is_return=='0') {
              (frm.set_value('naming_series', 'ACC-SINV-.YYYY.-'));
            }
            
    }
    });
frappe.ui.form.on("Sales Invoice", {
    "onload": function(frm) {
            if (frm.doc.is_return=='1') {
              (frm.set_value('naming_series', 'CN-.YYYY.-'));
            }
            
    }
    });
1 Like

Hi @Aadhil_P_M thank you so much. This worked! :grin: I will also use this for the debit note. Thank you again.

1 Like

Hi @Aadhil_P_M sorry but I have another problem here. Since last time I already have previous documents of credit note using the naming series of the sales invoice. Now the system is keeps on asking to update the document so it will set value the correct naming series based the credit note series.

how can I included on the code that it should set_value or it should only work on a specific created document date?

Can you please add the queries with screenshots ?

If you have a existing records and added the below scripts:

frappe.ui.form.on('Sales Invoice', {
    "is_return": function(frm) {
            if (frm.doc.is_return=='1') {
              (frm.set_value('naming_series', 'CN-.YYYY.-'));
            }
            if (frm.doc.is_return=='0') {
              (frm.set_value('naming_series', 'ACC-SINV-.YYYY.-'));
            }
            
    }
    });
frappe.ui.form.on("Sales Invoice", {
    "onload": function(frm) {
            if (frm.doc.is_return=='1') {
              (frm.set_value('naming_series', 'CN-.YYYY.-'));
            }
            
    }
    });

The custom script will keep on running. You will not have any problem for future records however, for the old saved records, an update button appears for all roles not only to the system manager. and due to the update button, you cannot cancel and amend the old records.


as a workaround:

we added this code

((frm.doc.__islocal) &&

So that the script will not run for all saved transactions and the update button will not appear.

This solution only works (for me, V12), when the PE against the original SINV is submitted after the credit note is issued.

In the case (which is the most common for us) in which we’ve generated SINV and PE before making the Credit Note, the remainding won’t “appear” int the “Payment reconciliation” tool.

as a workaround:

we added this code

((frm.doc.__islocal) &&

So that the script will not run for all saved transactions and the update button will not appear.

Helo, where did you put the workaround script? was it inside the last frm.set_value ?

Just revisiting this - seems there was a pull request which addressed the allocation / advanced payment entry for credit notes (in the ‘Pre requisite Feats added’ section). Seems to have gone stale though…

Looks like, even after 5yrs of having this issue there is no concrete solution to utilize credit-note balance in a new invoice.

I have been searching for a solution in the core but it is a shame that there is no solution for it.

We did add a customization to create a JV and utilize it in new invoice but that effects General Ledger entry and some customers do no want a report with such JV entries.

@umair Any reason this was closed as completed but never implemented in the core?

While someone tried to contribute a solution but that was not accepted yet.

@netchampfaris Any advice ?

Here is a simple use case which is already mentioned above.

Case 1:
Customer A, buys items worth $1000. New Invoice is created SI22-0010

Next day Customer A returns all items, so a sales invoice return is made and $1000 is credited to the Customer A under Debtor.


Next Day Customer A comes back to buy some items worth $1000. New Sales Invoice is made and submitted. S122-0050
In accounting ledger Customers balance is tallied but SI22-0050 still shows unpaid.
There is no way to make it paid. Match payment with invoice does not show any payment entry.

Can someone advice on how they do it for such case?

Hi. I´ll explain how I´d manage this Case 1.
When you make the credit note to the sale invoice SI22-0010, do it without any kind of mode of payment o pos payment link. So this credit note just cancel the sale (the earning account) and let the sale invoice SI22-0010 with the negative balance.
Next you can try to make a journal entry from this sale invoice with a row to the credit to the cash back acount linked to the invoice SI22-0010. And a row to the debit for the cash account as a Is Advance (checked) with no sale invoice linked.
Both rows linked to the customer.
Now you must use this amount to pay the new sale invoice SI22-0050.
I hope it helps.

This creates further confusion.

We did try to make JV and that leads to 2 extra issue.

  1. Accounts receivable is always showing these JV.
  2. General Ledger show these extra entries. (Some strict customers don’t accept such Customer Statement report)

I will try something similar to see if that will fix the issue we’re facing.

Thanks for the quick response.