Create Credit Note from Sales Invoice - blocked by linked Timesheet in Billed Status

Hello,
we need create a credit note against the submitted Sales Invoices that is linked to Timesheets.
Due the Sales Invoice is submitted and the per_billed = 100 on Timesheets, then the status of the Timesheets is “Billed”.

This is the reason why we get this error during Credit Note inserting:

How can we, please, skip this control?
I can set the status to “Submitted” in frappe.set_value… but this isn’t a clear way.

Thanks for any tip in advance.

PS: We won’t cancel the Sales Invoice.

Hi @Jiri_Sir,

If you want to skip the validation check for Timesheets’ status when creating a Credit Note from a Sales Invoice in ERPNext, you can modify your code as follows:

# Modify function
def validate_time_sheets_for_credit_note(self):
    for data in self.timesheets:
        if data.time_sheet:
            # Set the status to "Submitted" to bypass validation
            frappe.set_value("Timesheet", data.time_sheet, "status", "Submitted")

# Call the modified function during validation
def validate(self):
    self.validate_time_sheets_for_credit_note()
    # Other validation logic for Sales Invoice

This code sets the status of Timesheets to “Submitted” during the validation process for Credit Notes, bypassing the original validation check. However, be cautious when directly changing data like this, and thoroughly test the modified code in a controlled environment to ensure it behaves as expected.

first, please try on the local environment and also you can apply your own logic according.

I hope this helps.

Thank You!

1 Like

Hi @NCP ,
thank you very much for quick reply.
It this is only way then I will script it on the server script on “before validate” event for our custom needs.
Thank you.
Jiri Sir

Yes, you can @Jiri_Sir.