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’),

}

Comments

Shanil: Hi, Thanks for the valuable information. I have a doubt regarding this, how can we create a sequence accesssible for muliple companies?".

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Anonymous says:

    Thank you for this article.
    Just one question, is it possible to add such sequence using the client (GTK or web). I mean without code?
    Thanks

    1. jabir says:

                                                                         

      Hello,
      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.

      1. Anonymous says:

        In the particular case of an invoice, suppose you need to setup an invoice sequence for invoicing from a new branch office, I assume that is not necessary to write code, since in the invoice screen, you can choose a different sequence to use.
        In this case, is it needed to setup a different sequence code, or you can use the same sequence code for another sequence?
        If in this case you must write code, don’t understand why.

        1. Anonymous says:

          Hey im new to openerp and i need help to create a function field called Total that calculates the sum of all the fields of the same object…
          eg.
          _name = ‘hr.performanzze’
          _columns = {
          ‘p’:fields.selection(((1,’Outstanding’), (2,’Well Above Expectations’), (3,’As Expected’), (4,’Below Expectations’), (5,’VeryPoor’), 0,’N/A’)),’title.’),
          ‘b’:fields.selection(((1,’Outstanding’), (2,’Well Above Expectations’), (3,’As Expected’), (4,’Below Expectations’), (5,’Very Poor’), (0,’N/A’)),’title’),
          ‘total’ : fields.function(get_total, method=True, string=’Total Mark’),
          }
          def get_total(self, cr, uid, field_name, arg, context):
          //want to calculate the sum of p and b
          return the answer

  2. Kusno says:

    Nice post…….let me bookmark your site

  3. neoinsurrounder says:

    Thank you for this useful reply
    I’m new at Openerp 6.1
    Would you just specify where we have to add the _default action. Because I have to create a sequence field in res.partner view ( for the client) and I don’t know how to do it.
    Thanks for your help

  4. Anonymous says:

    hi, whenever i upgrade or reinstall module, all user defined sequences starts again from a 1 unlike other openerp defined sequences like sale order ‘SO*’ which starts from next no. from last generated sequence no.
    Looking for the reply.

  5. edwin says:

    every time I close in to openerp sequence restarts, anyone know why?

  6. Bhavik says:

    Want to create a sequence for an existing field – Payment Ref (under Customer Invoices).
    Copied above code to account_voucher_sequence.xml, however, cant see new entry under Settings>Configuration>Sequence&Identifiers>Sequences
    Also tried renaming ‘name’ and ‘code’ of Purchase Entry in the same XML file, however, unable to see any changes under Settings>Configuration>Sequence&Identifiers>Sequences
    Please let me know where m i going wrong. thanks!

  7. Shanil says:

    Hi,
    Thanks for the valuable information.
    I have a doubt regarding this, how can we create a sequence accesssible for muliple companies?

© 2020 Zesty Beanz Pvt Ltd All Rights Reserved.