Most Powerful Open Source ERP

How To Use ERP5 Id Tool

How To showing how to generate many different kind of IDs inside ERP5.
  • Last Update:2016-02-09
  • Version:001
  • Language:en

The Id Tool allows to generate many kinds of ids. It can be used in order to generate several sequences of strings or numbers.

Table of Contents

How to Use a new sequence

First you must choose a id generator for your new sequence, this one is used to generate and store the id of the sequence. The id generators are defined on portal_ids in your instance erp5. By default you can use the id generator "document" to store the id only in the ZODB otherwise the id generator "uid" to store in MySQL and in the ZODB.

Second you must define a name for your new sequence, it can be any string. Let's say you want a sequences for all your orders, you may decide to use the name "order_reference" for your sequence.

By default the id tool can automatically generate simple sequence of integers by increasing them one by one. The default value which will be used in order to initialize your sequence is 0 but you can set a default value.

new_id = context.portal_ids.generateNewId(id_generator='document', id_group='order_reference', default=4)

You may call this method each time you need it, each time it will returns a number bigger and bigger :

  first time : 4
  second time : 5
  third time : 6
  and so on...

Reset an id generator

It is possible to clear an id generator to delete all the sequence ids defined on the id generator given.

context.portal_ids.clearIdGenerator(id_generator='document')

By example, it's use to call again the sequence with a new default value

context.portal_ids.generateNewId(id_generator='document', id_group='order_reference', default=8)

Related Articles