Thursday, 3 May 2012

Auto Number Generate in OpenERP

Auto Number Generate in OpenERP


Simply just create a new file .xml
lib.resource = table name

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data noupdate="1">

        <!-- Sequences for lib.resource -->
        <record id="seq_type_library_sub_resource" model="ir.sequence.type">
            <field name="name">Library Resource</field>
            <field name="code">lib.sub.resource</field>
        </record>

        <record id="seq_library_sub_resource" model="ir.sequence">
            <field name="name">Library Resource</field>
            <field name="code">lib.sub.resource</field>
            <field name="prefix">BC</field>
            <field name="padding">10</field>
        </record>
    </data>
</openerp>


 Or


simply write below code in your view.xml file
 <record id="seq_type_library_sub_resource" model="ir.sequence.type">
            <field name="name">Library Resource</field>
            <field name="code">lib.sub.resource</field>
        </record>

        <record id="seq_library_sub_resource" model="ir.sequence">
            <field name="name">Library Resource</field>
            <field name="code">lib.sub.resource</field>
            <field name="prefix">BC</field>
            <field name="padding">10</field>
        </record>


and in your .py file in _default simply write the below code 


_defaults : 
{
    'number': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'lib.resource'),
}

6 comments:

  1. Thanks Pinakin...u saved my whole day :-)

    ReplyDelete
  2. I tried to do this but when the page loads the sequence number is not loaded. Is there something missing?

    ReplyDelete
  3. hi Pinakin! thank you.. it worked!!!.. but there is an error when i try to save it :( "DataError: invalid input syntax for integer: "CRN00015"
    LINE 1: ...3, 2, 1, 'none', 1, 'draft', 'out_invoice', NULL, 'CRN00015'..." ....... is there a way that I can use button to generate the sequence when i click a button?

    ReplyDelete
  4. may be you have to change the type of field to char

    ReplyDelete
  5. thank youuu... it worked :)..very helpful

    ReplyDelete
  6. How can I insert a number that is generated in automatic for a specific model the code that you have already applied and I did not work that another solution exists

    ReplyDelete