I have three companies, FACTORY,SOFTWARE,HARDWARE
I have many employees in each companies.
First i edit employee nam and then select company name. when i select company name, employee id should be generated automatically according to the below steps.
If employee1 is in FACTORY then employee id FAC0001
else if employee1 is in SOFTWARE then employee id SOF0001
else employee1 is in HARDWARE then employee id HAR0001
How cani achieve this?
code
hr_sequence.py
import openerp
from openerp.osv import fields, osv
class employee_sequence(osv.osv):
_inherit = "hr.employee"
_columns = {
'sequence_code': fields.char('Employee ID',size = 16,required = True,translate = True),
}
def create(self, cr, uid, vals, context=None):
if context is None:
context = {}
context['force_company'] = vals['company_id']
if vals.get('sequence_code', '/') == False:
vals['sequence_code'] = self.pool.get('ir.sequence').next_by_code(
cr, uid, 'hr.employee', context=context) or '/'
return super(employee_sequence, self).create(cr, uid, vals, context=context
)
employee_sequence()
hr_sequence.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<!-- Sequences for hr.employee -->
<record id="seq_type_hr_employee" model="ir.sequence.type">
<field name="name">Employee Id</field>
<field name="code">hr.employee</field>
</record>
<record id="seq_hr_employee_com1" model="ir.sequence">
<field name="name">Employee Id(com1)</field>
<field name="code">hr.employee</field>
<field name="prefix">SOF</field>
<field name="padding">3</field>
<field name="company_id" eval="1"/> <!-- SET FAC Company ID! (select id from res_company where name='FAC')-->
</record>
<record id="seq_hr_employee_com2" model="ir.sequence">
<field name="name">Employee Id(com2)</field>
<field name="code">hr.employee</field>
<field name="prefix">SOF</field>
<field name="padding">3</field>
<field name="company_id" eval="3"/> <!-- SET FAC Company ID! (select id from res_company where name='FAC')-->
</record>
</data>
</openerp>
hr_sequence_view.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="hr_sequence_form" model="ir.ui.view">
<field name="name">hr.sequence.form.inherit</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<field name='name' position='after'>
<field name="sequence_code"/>
</field>
</field>
</record>
<record id="hr_sequence_extra" model="ir.actions.act_window">
<field name="name">Employee</field>
<field name="res_model">hr.employee</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
</data>
</openerp>
please rewrite the code.
Hi Remya, I am newbie to OpenERP. Can you please tell me at what location i should create these python and xml files?