You can create
multiple sequence codes from single sequence file. For example, if
you want to create different employee codes for 'Regular Employee'
and 'Trainee Employee' you can use single sequence file and achieve
your results. As follow:
If you don't know at
all about sequences, how to create sequence in Odoo/OpenERP, Please click here.
emp_code_sequence_view.xml
<!-- Sequences for Regular Employee code -->
<record id="seq_hr_employee" model="ir.sequence">
<!-- Sequences for Trainee code -->
</data>
<?xml version="1.0"
encoding="utf-8"?>
<openerp>
<data>
<!-- Sequences for Regular 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="padding">5</field>
<field
name="company_id" eval="False"/>
</record>
<!-- End of code for
employee code sequence-->
<!-- Sequences for Trainee code -->
<record
id="trainee_code_sequence" model="ir.sequence.type">
<field
name="name">Trainee Code</field>
<field
name="code">hr.trainee</field>
</record>
<record
id="seq_hr_trainee" model="ir.sequence">
<field
name="name">Trainee Code</field>
<field
name="code">hr.trainee</field>
<field
name="padding">5</field>
<field
name="prefix">TR</field>
<field
name="company_id" eval="False"/>
</record>
<!-- End of code for
Trainee code sequence-->
</data>
</openerp>
hr_employee_view.xml
<button
name="generate_emp_code" string="Generate Employee Code"
type="object" class="oe_highlight" attrs="{'invisible':[('emp_code','!=',False),]}"
groups="base.group_hr_manager"
context="{'employment_type_id':employment_type_id}" />
hr_employee.py
def
generate_emp_code(self, cr,uid, ids, context=None):
if context
== None:
return
False
if not
context.get('employment_type_id', False):
return
False
employment_type_id = context.get('employment_type_id')
emp_code_details = self.pool.get('employment.type').read(cr, uid,
employment_type_id, ['name'])
if
emp_code_details['name'] == 'Trainee':
emp_code_val=self.pool.get('ir.sequence').get(cr, uid,'hr.trainee')
else:
emp_code_val=self.pool.get('ir.sequence').get(cr, uid,'hr.employee')
res=super(hr_employee, self).write(cr, uid, ids,
{'emp_code':emp_code_val})
return res
That's it.
Thanks!!!!!!!!!! Enjoy Programming :)
Comments
Post a Comment
Thanks for your valuable comments.