Sequence in OpenERP
Adding a sequence for records in OpenERP is very simple. For making a field a sequence type, we need to create new sequence or use existing sequence. For creating a sequence, we need to create two type of objects, one is “ir.sequence.type” and other “ir.sequence”. The example to create these records are given below..
<record forcecreate="1" id="seq_type_id" model="ir.sequence.type">
<field name="name">Name</field>
<field name="code">code</field>
</record>
<record forcecreate="1" id="seq_id" model="ir.sequence">
<field name="name">Name</field>
<field name="code">code</field>
<field name="padding" eval="pading"/>
<field name="prefix">prefix</field>
<field name="suffix">suffix</field>
</record>
When thsi xml file is executed, the new sequence with name “Name” will be created on OpenERP. You can see this sequence from “Menu/Administration/Configuration/Sequences/Sequences”.
All the fields created here is self explanatory. If you have any doubt, you can keep the mouse over the label of each field on openerp and it will display corresponding help text.
Now we need to add this sequence to a record. For that we have to call the get function on ir.sequence class with the correct code. This function call can be done on _default so that the sequence is generated by default when new record is created. This can be done using following code,
_defaults = {
'field_name': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'code'),
}