Numbering sales invoice after deleting


I have problem with numbering new sales invoices, because when I delete the last one for example and I will add new one, the new one has totally new number of sales inovice instead of having the number of sales invoice which I deleted.I want only substitute the old sales invoice to the new one and preserve numbering of invoices. My question is, Can I change it or Am I wrong ?


I think for accounting purposes you are not supposed to have any missing numbers (perhaps i case the tax man thinks you are hiding one). So better to cancel an invoice rather than delete it?

@PeterWR after you delete an invoice you have to reload the system so the cached number will be re-checked…

user menu > reload

@ramielian As @Ron_Taylor has stated this isn’t good practice. Any system that routinely allows this would be frowned upon by any Accountant, Auditor or Tax Authority. There must be complete transparency in all financial transactions. Deleting of financial records should never be an actual possibility in Production. This needs to be understood.

@eamonn you can disable deletion of the document, no one said its not possible and also it depends on the permissions you give to a user…

frappe / erpnext give the flexibility for anyone to do what ever they want when they are administrative users, but its up to you to what you grant to other users

@ramielian Flexibility is important in Dev mode however it is never acceptable to permit deletion of financial records in Production. Any business permitting that would come under severe scrutiny if found by any Tax Audit or Financial Reporting Auditor simply because the ability to manipulate the accounts just got a whole lot easier. If you are going to allow poor business practices then it shouldn’t be the default behaviour. Sane defaults are very important for a product that markets itself as easy to use. Easy to use often means that easier for people that don’t really understand what they are doing using it which requires a setup that is at least based on solid standards.

@eamonn you are right, but every single ERP system dose need implementation, ERPnext is perfectly fine for security and internal audits, but each ERP needs modifications when comes to implementation and production …

erpnext dose not allow deletion of docs unless for authorized users and you are the person to state which users have this permission and which dont…

Altough that I set permission to remove invoices, numbering still doesn’t work in the way as I want. For example I add new invoice to my system (before acceptation), but I remind that something is wrong and I have to remove this invoice. After deletion still the number of removed invoice is kept somewhere in database, but I want to add new invoice with this number. How can I do this ?


As @ramielian stated in his post you have to reload the page or if that doesn’t work logout and in again as the number will be held until you do that. In a multiuser environment this will never work reliably as someone could be creating a new invoice as you are trying to reload or logout and the gap will then be created and that missing number will not be allocated again.

am not sure who to disturb and tag to suggest a reload function to be triggered after deletion of any submitted doc…

@rmehta & @anand sorry to disturb but would this be possible ?

Yes, right, but I did in this way and still the number of invoice is increasing. I created a draft of invoice which has number 000020, next I delete it and I add new one, which has number 000021, but not 000020 ? After deletion I reload page from user menu as you said. Different users have the same problem.

I’ve never used reload however I do know if you log out and log back in again it doesn’t create a gap as I have used that in testing. You are right this issue has arisen before as gaps are not permitted in the invoice numbers in the EU for VAT purposes. My suggestion was that invoice numbers should not be allocated until submitted. They can use a temporary number in the background however the actual invoice number should not be assigned until that submission has taken place. For the EU areas after submission cancellation would be the only permitted way of handling an order that is cancelled after being accepted/submitted. If you make a mistake and submit an order you shouldn’t have then just cancel it. Does it really matter if it is deleted or cancelled. The result is the same and not deleting permits far more control within the business If someone is persistently having to delete orders then it is a sign they need to pay more attention or need more training.

Maybe simpler solution would be new field which can be increase automatically, what do you think ?

1 Like

I guess it would depend on how it’s implemented because there would be the system giving one invoice number and the paperwork another. If you search the number given on the paperwork would you even find the right invoice on the system?

The simpler solution is to simply not delete invoices.

As described above by myself gaps can be created without deleting any sales invoice. Click on Sales Invoice by mistake. Press the back button and press the invoice again and you get a new invoice number. For EU VAT purposes that is not acceptable.

Let’s just take this question from a completely different angle but much more important angle. When is an invoice an invoice? I’d argue it’s only an invoice once it is submitted and indeed this basic concept is well understood because we have a draft status. If it wasn’t then a draft would not be necessary. So my question would then would be why allocate an invoice number before it even exists? Model that you and are modelling the real business logic which is the real goal.

Draft and Submit are two states of Transaction document, meaning that in Draft you can change values, items and prices. so you can create invoice in draft state and wait for adding billing details or confirm rates.
After confirming details, you can submit invoice. After final submission one can not change any information in invoice but if needed one can make revision of invoice by canceling and amending it.

If you don’t want to cancel/delete invoice, you can create sales order and make sales invoice after final confirmation.

I’m sorry a draft is a pro forma invoice if you want to talk about documents. A pro forma invoice is not an invoice. A pro forma is never acceptable for VAT. Only an invoice is. You can argue until you are blue in the face but HMRC, UK Tax Authority, are clear about the difference and therefore we have to be clear about the difference.

You don’t address my initial point about how you can create a gap in invoice numbering simply by hitting the sales invoice option by mistake. Using sales orders doesn’t address that at all.

I’m delighted for those countries that don’t have to deal with VAT but I do.

You can create print format for Pro-Forma invoice on Sales Order.

For removing gap, one need to add rename option in Sales Invoice, So we can rename invoice to missing number, but its not good design.
Also if we keep another auto number for invoice, then there is also same change for missing numbers in auto-number.

Yeah. I can see all those problems which is why you can only ever resolve this issue by allocating the invoice numbers as part of the submission process. Whilst the sales invoice submission process is running then any new sales invoices should queue until that submission process has finished which allows you to roll back the number if submission fails. Only foolproof way I can think of doing this but then again I’m not a programmer.