Showing posts with label auto number in openerp. Show all posts
Showing posts with label auto number in openerp. Show all posts

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'),
}