Help

How to implement sequences

Closed
Avatar
cdn

The question has been closed

by
Sudhir Arya (ERP Harbor Consulting Services)
on 04/18/2013 05:20:12

I'm new at openerp and a little bit confused about all.

I would like to add a sequence to automatically create customers ID. For that I need to create a xml file and implement this, right?

But I have no idea where I have to do this. Is there a manual for openerp, where this is explained?

Thank you

Avatar
Discard
1 Answer
7

Create sequence.xml file and add it in data in __openerp__.py

Here is an example for sequence:

<record model="ir.sequence.type" id="seq_type_emp_id">
    <field name="name">Employee Number</field>
    <field name="code">hr.employee</field>
</record>
<record model="ir.sequence" id="seq_emp_id">
    <field name="name">Employee Number</field>
    <field name="code">hr.employee</field>
    <field name="prefix"></field>
    <field name="padding">3</field>
</record>

After creating sequence in xml, you can call that sequence from your code:

my_sequence = self.pool['ir.sequence'].get(cr, uid, seq_obj_name)
self.write(cr, uid, [picking.id], {'ur_emp_no_field': my_sequence})

You can call this sequence either from create or from your own function or from _defaults.

Hope this will sort out your confusion.

Thanks

10 Comments
Avatar
Discard
Avatar
cdn
-

Thanks for your answer, but this manual do not help me. I don't know where to call the sequence and also do not know the structure of a module. Isn't there sth. like an overview ? Thanks for your replies

Avatar
Atchuthan
-

Hi Sudhir, in self.write(cr, uid, [picking.id], {'ur_emp_no_field': my_sequence})

what is [picking.id]? and also how can i use my current id without 'ids' in the argument field of the ORM create method

Add this in your create method:

vals['your_field_name'] = my_sequence
Avatar
Atchuthan
-

yeah i tried... but this will provide the value after clicking on "SAVE" button.

That is normal. When you create a new record and click on Save button, create method is called and then record is saved to database.

Avatar
Atchuthan
-

my requirement is to display the sequence generated in the form. If I use _defaults to provide the value... the sequence generated are always even numbers like E002, E004, E006, etc...

So how can I show the sequence at the same time the value must not change after clicking on "SAVE" button

If you are generating sequence code from _default, then make sure you have removed get sequence code from create method.

Avatar
Atchuthan
-

If I use _default and display in the form, at the opening of the form the employee number is E001 and after adding values to other field. When "SAVE" button is clicked, the records employee number changes to E002.

Did you remove code from create method for sequence?

Avatar
Atchuthan
-

I already removed it in create