Odoo - OpenERP - Module with codes for Generate Employee Code - Sequence with Prefix & Suffix ?

Support
Support
5000
| 2 1 2
Asked on 8/21/15, 4:09 PM
0
vote
4697 Views

Employee code can be generated in following three simple steps:

1. Create a sequence file

emp_code_sequence_view.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <!-- Sequences for employee code -->
        <record id="emp_code_sequence" model="ir.sequence.type">
            <field name="name">Employee Code</field>
            <field name="code">hr.employee</field>
        </record>

        <record id="seq_hr_employee" model="ir.sequence">
            <field name="name">Employee Code</field>
            <field name="code">hr.employee</field>
           <field name="prefix">EMP</field>
            <field name="padding">5</field>
            <field name="company_id" eval="False"/>
        </record>
        <!-- End of Sequence code for employee code -->

    </data>
</openerp>


2. Add new field to class in .py file

class hr_employee(osv.osv):
    _name = 'hr.employee'
    _inherit = 'hr.employee'    
    _columns = {
                'emp_code':fields.char('Employee Code', size=8, readonly=True)
    }

3. Update database in .py file

def create(self, cr, uid, vals, context=None):
        vals['emp_code']=self.pool.get('ir.sequence').get(cr, uid,'hr.employee')
        res=super(hr_employee, self).create(cr, uid, vals)
        return res

create function will be called only when new employee is added.

Employee code will start from EMP00001

You can generate emp_code without sequence file as well and write code directly in create function as well.

But standard way is using sequence file only.

Note: Don't forget to include 'emp_code_sequence_view.xml' file in data section of'__openerp__.py' file.

Support
Support
5000
| 2 1 2
Answered on 8/21/15, 4:12 PM
0
vote

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!

Ask a Question

Keep Informed

About This Forum

This forum is for HiTechnologia Employees & just Odoo general knowledge purpose only.

Read Guidelines

Question tools

3 follower(s)

Stats

Asked: 8/21/15, 4:09 PM
Seen: 4697 times
Last updated: 8/21/15, 4:12 PM