Arsalan Sherwani
Arsalan Sherwani

Reputation: 560

What does ir.sequence represent in OpenERP development under Python?

I have been going through some source code of Python language in order to develop some OpenERP modules . I have come through a syntax of code which I dont think I am getting . Could someone please help me so that I can move onto my learning of Python language for developing OpenERP modules. Here is the code

self.write(cr, uid, ids, {'name': self.pool.get('ir.sequence').get(cr, uid, 'hr.applicant'),'state': 'approved'})

I am sure that ir.sequence is a class but I dont seem to understand the semantics of the code here. Please help me. Thanks, hopes for suggestion

Upvotes: 0

Views: 828

Answers (1)

Adrian Merrall
Adrian Merrall

Reputation: 2499

ir.sequence is where OpenERP keeps configurable sequences. These are installed by modules that need them and they have a couple of functions you can use such as defining prefixes (for example sales orders) and they can also have per company values so if you are running multi-company, you won't find sales orders for a company going up in odd increments due to orders in other companies.

So in the above code snippet, it says "get me the next number in the hr.applicant sequence". The get method on the ir.sequence model will handle the multi-company and assign prefixes/suffixes etc.

A couple of points to note.

  1. You set these up yourself in your module with a record element but make sure you put a noupdate="1" on the record or you will reset the counter when you update your module. You can define prefixes and suffixes I believe.
  2. They are a table based sequence. This means that unlike the Postgres sequences used for record IDs, if the transaction rolls back due to an error, the sequence number isn't used.
  3. Don't grab lots of them in long running transactions if you are writing your own code or you may get serialisation roll backs in Postgres due to contention. Regular, get the next value and write it code should be fine.
  4. They have been around for a while so you will see lambdas used a lot to get the next value.
  5. There are two objects you have to set up when creating these. Have a look at sale.order for a good example.

Upvotes: 3

Related Questions