Numbering sales invoice after deleting

@eamonn I am not sure its standard way to add name after submission.
If you need solution, here is steps to do it or hire someone from job portal

Add custom field Invoice Number in sales invoice.
Add script to calculate existing MAX(Invoice Number).
Add script to update Invoice Number on submission of Sales Invoice.

Note: In this case, if you cancel or delete any old invoice then this will not give you solution.

@kolate_sambhaji The correct order of things should be the one that matches the be the one that is based on sound business logic and if we are talking about sound logic then itā€™s simple. A sales invoice should never have gaps in the sales invoice numbers unless a sales invoice has been explicitly deleted. The fact that you can get this behaviour of gaps appearing without explicitly deleting is regrettable not least because it then fails to meet needs of all users across the European Union who have to deal with VAT whether they understand their obligations or not. It would also be a concern to any auditor across the world. Anyway Iā€™ve made my point and my reasons so I donā€™t see much point in pursuing this point any further as Iā€™m bored listening to myself now :smiley:

This is not how numbers are usually generated, and if this is happening it must be a bug. Invoice numbers are generated when the invoice is saved as a draft. If numbers are being created before being saved as a draft, then a git hub issue should be created, because this is a bug. A draft invoice is not the same as a pro-forma invoice though. At least in my company, we use Sales Orders for Pro-Forma invoices.A draft invoice is simply a draft invoice, i.e. itā€™s not complete.

Draft invoices must be numbered, else it would ruin the organization. If you have an invoice that is still a draft, a mistake, and you donā€™t want any gaps, then you should submit then cancel the invoice. It wonā€™t affect any accounts, and will still be a permanent record.

You should change permissions so that nobody can delete invoices.

Itā€™s simple an invoice can never be amended. An invoice is a tablet of stone. What the customer has must be exactly the same as your records which is why it can never be amended. That is why if you should never delete and invoice and why you never amend one and why you instead create credit notes. I will accept that a sales order can serve the same purpose as a pro forma however that being the case there is never a need for a draft invoice because the draft invoice serves the same purpose as the sales order. When you have a draft status you have pro forma irrespective of whether that is duplicate of a sales order or not the very fact that it exists means it can only be one document and that is pro forma. Pro forma are not invoices therefore to generate an invoice number at this stage is not following the business process.

@cpurbaugh Thanks. Iā€™ve checked out the Sales Invoice numbering and they do only get created on saving so that gets rid of my biggest concern. The issue about pro forma invoices and invoices is still a reality however itā€™s not something that would overly concern myself with as I agree that when saving the pro forma you can easily cancel which is perfectly acceptable. I was more concerned about gaps appearing before submission as that would have been a big issue for me and that isnā€™t the case now. I now have no idea whether this was ever a problem or if I misinterpreted what Iā€™d seen. No way of telling now as that was about 8 months ago and I have done that much testing since itā€™s impossible to tell now. Oh well. At least thatā€™s one more thing I can stroke of my list of issues :smiley:

The same situation for Delivery Notes. Although that I deleted delivery note e.g. number 5 and if I add new one, the new number of DN is 6, but not 5. Is there any way to control or understand how the numbering works ? Because yours answers donā€™t give full solution.

Did anybody ever find a solution for this please? I deleted the last sales invoice (made a mistake) and try to remake it but it skips a number now so there is a gap in the numbering.
Is there any way to solve this in DB or code?
Thanks in advance

EDIT: First I tried to fix it with imports, which gave me the right numbers (manually set via xlsx file) but when adding a new sales invoice it gave me an error on duplicate naming so the numbering was not really ā€œregisteredā€. Then I found the solution (super easy, wish I found it earlier): Duplicate name Item Price RFD/03610

Setup ā†’ Settings ā†’ Naming Series and set the ā€œlast entryā€ number to the one you desire for the prefix you want.

There is tabSeries in the db which will have the last doc name created for Sales Invoice, change it there