Skip to Content

Welcome!

Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

Sign up

You need to be registered to interact with the community.
This question has been flagged
1 Reply
24 Views

How to create an auto increment ID Number field in HR Employee? So that everytime I create an employee, the id number of an employee will automatically increment + 1 in a custom field (readonly). anyone can help? thank you in advance.



Avatar
Discard

Hi create a custom module like below code .any issue

hr_custom.py file

==========================================================================================

class hr_employee(osv.osv):

    

 

    _inherit='hr.employee'

_columns={

    'emp_id':fields.char('Employee ID',readonly=True)

}

 

def create(self, cr, uid, vals, context=None):

           vals['emp_id'] = self.pool.get('ir.sequence').get(cr, uid, 'hr.employee')

           return super(hr_employee, self).create(cr, uid, vals, context=context)


_defaults={

                'emp_id': lambda obj, cr, uid, context: '/',

               

                

              }


====================================================================================

create xml view file

 

<record id="hr_form_inherited" model="ir.ui.view">

                <field name="name">hr new1</field>

                <field name="model">hr.employee</field>

                <field name="type">form</field>

                <field name="inherit_id" ref="hr.view_employee_form"/>

                <field name="arch" type="xml">

                    <xpath expr="/form/sheet/div/field[@name='category_ids']" position="after">

                        

                        <field name="emp_id" string="Employee ID" />

                    </xpath>


</record>

===========================================================================================


==========================================================================================

create a xml file like below and add this file name in openerp.py

<?xml version="1.0" encoding="utf-8"?>

<openerp>

    <data noupdate="1">

 

        <!-- Sequences for employee code -->

        <record id="seq__hr_code_inh1" model="ir.sequence.type">

            <field name="name">Employee ID</field>

            <field name="code">hr.employee</field>

        </record>

 

        <record id="seq_hr_code_inh2" model="ir.sequence">

            <field name="name">Employee ID </field>

            <field name="code">hr.employee</field>

            <field name="prefix">CU</field>

            <field name="padding">2</field>

             

        </record>

         

        

 

 

    </data>

</openerp>

=================================================================================================

Avatar
Discard

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!