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>
<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>
<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>
Eg :
<record id="sequence_reconcile" model="ir.sequence.type">
<field name="name">Account Reconcile</field>
<field name="code">account.reconcile</field>
</record>
<record id="sequence_reconcile_seq" model="ir.sequence">
<field name="name">Account reconcile sequence</field>
<field name="code">account.reconcile</field>
<field name="prefix">A</field>
<field eval="1" name="number_next"/>
<field eval="1" name="number_increment"/>
</record>
When thsi xml file is executed, the new
sequence with name “Name” will be created on OpenERP. You can see this
sequence from “under
Settings>Configuration(Technical)>Sequence&Identifiers>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'),
}
Ex:
_defaults = {
'name': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'account.reconcile', context=context) or '/',
}
Note :
You can create new sequence without any python code. But to link with a field we need to write code. Or on some form view we can make a many2one field to sequence and take the sequence which is selected there. You can see example for this in Journal(Accounting/Configuration/Financial Accounting/Journals/Journals). There is a field named "Entry Sequence". This sequence is used for numbering of journal entries created for this journal.
Ex:
_defaults = {
'name': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'account.reconcile', context=context) or '/',
}
Note :
You can create new sequence without any python code. But to link with a field we need to write code. Or on some form view we can make a many2one field to sequence and take the sequence which is selected there. You can see example for this in Journal(Accounting/Configuration/Financial Accounting/Journals/Journals). There is a field named "Entry Sequence". This sequence is used for numbering of journal entries created for this journal.
0 comments:
Post a Comment