Script: Reset invoice number

Resets the invoice number counter

The invoice number is reset. This script is used, for example, when an invoice has to be deleted and created so that no invoice number is “wasted”.

There are 2 scripts:

  • Script 1: Resets the invoice number by one counter.
  • Script 2: If you want to reset the invoice number by more than one counter, use this script. You can specify the desired counter in a query.

Both scripts reset the last used invoice number with the current prefix.

If you want to increase the invoice number instead, you do not need this script, but can specify the next invoice number in system settings > invoice / invoice.

    version description Script
    6.6 This script can also be used with Vertec versions from 6.7.0.12 onwards, it does not use argobject still selectedobjects.

    Script 1: Resetinvoice number.py

    Script 2: Resetinvoice numberinput.py

    Execute

    Somewhere in Vertec via Script Editor.

    When you register the script, register it so that it is available where it makes sense to you.

    As of Vertec version 6.7.0.12 you can also register the script to a folder, for example to Invoicing with the class Ordner and the display condition self->first.eintragid = 'FolderInvoicing'.

    Script Text 1

    Resets the invoice number by one counter.

     # coding: windows-1252
    #
    #---Bezeichnung: Rechnungsnummer zurücksetzen
    #   Klasse: 
    #   CondExpression:
    #   Selectedobjectsscript: Yes
    #   EventType: Kein
    #   EventClass:
    #   EventMembers:
    #   ExtendedRights: N
    #---Setzt die Rechnungsnummer um einen Zähler zurück.
    #---12.02.2004, Vertec AG: erstellt
    #---02.06.2008, sr: UpdateDatabase ergänzt.
    #---19.06.2017, sr: Script in Python erstellt.
    #---21.07.2025, sth: Umgestellt auf getpropertyvalue(). Funktioniert mit EN und DE.
    
    
    def main():
    
        prop = vtcapp.getpropertyvalue("PraefixRechnungsnummer")
        if prop:
            prefix = vtcapp.evalocl("usedprefix->select(prefix='" + prop + "')->first")
            if prefix:
                lastusednumber = prefix.lastusednumber
                if lastusednumber > 0: 
                    prefix.lastusednumber = lastusednumber - 1
                    vtcapp.updatedatabase()
                    vtcapp.msgbox(vtcapp.translate('The invoice number has been reset'))
    
    main()

    Script Text 2

    Sets the invoice number to the value requested by the user.

     # coding: windows-1252
    #
    #---Bezeichnung: Rechnungsnummer zurücksetzen mit Input
    #   Klasse: 
    #   CondExpression:
    #   Selectedobjectsscript: Yes
    #   EventType: Kein
    #   EventClass:
    #   EventMembers:
    #   ExtendedRights: N
    #---Setzt die Rechnungsnummer zurück. Die zu verwendende nächste
    #   Rechnungsnummer kann in einer Abfrage angeben werden.
    #---15.02.2007, sc: erstellt.
    #---31.12.2012, sr: Angaben in msgbox um Präfix ergänzt.
    #---19.06.2017, sr: Script in Python erstellt.
    #---21.07.2025, sth: Umgestellt auf getpropertyvalue(). Funktioniert mit EN und DE.
    
    def main():
    
        prop = vtcapp.getpropertyvalue("PraefixRechnungsnummer")
        if prop:
            prefix = vtcapp.evalocl("usedprefix->select(prefix='" + prop + "')->first")
            if prefix:
                lastusednumber = prefix.lastusednumber
                userinput = vtcapp.inputbox("Vertec", vtcapp.translate("The last invoice number assigned is: {} \nThe corresponding prefix is: {} \nEnter a new invoice number (without the prefix):").format(lastusednumber, prop),"")
                if userinput:
                    try:
                        newnumber = int(userinput)
                        if newnumber < 1:
                            vtcapp.msgbox(vtcapp.translate('The value entered must be at least 1. Please enter a number >= 1.'), 0, 'Vertec')
                            return
                        prefix.lastusednumber = int(newnumber) -1
                        vtcapp.updatedatabase()
                    except ValueError:
                        vtcapp.msgbox(vtcapp.translate('The value you entered is not a number. Please enter a numeric value >= 1.'), 0, 'Vertec')
    
    main()

    Netherlands

    United Kingdom