Skip to Content
Menu
This question has been flagged
1 Reply
3115 Views

hi all , iam trying to get the sequence for the employees in hr_module , but when i create a employee it shows NEW instead of the sequence EMP_



hr.py :

name_seq = fields.Char(string='Order Reference', required=True, copy=False, readonly=True, index=True, default=lambda self: _('New'))

@api.model

def create(self, vals):

if vals.get('name_seq', _('New')) == _('New'):

vals['name_seq'] = self.env['ir.sequence'].next_by_code('hr.employee.sequence', sequence_date=seq_date) or _('New')

result = super(HrEmployeePrivate, self).create(vals)

return result



sequence.xml:

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

<odoo>

<data noupdate="1">

<!-- Sequences for transfer.order -->

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

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

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

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

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

<field name="company_id" eval="False"/>

</record>

</data>

</odoo>



hr_views.xml :

<div class="oe_title">

<h1>

<field name="name_seq" readonly ="1"/>

</h1>

<h2>

<field name="name" placeholder="Employee's Name" required="True"/>

</h2>

<h3>

<field name="job_title" placeholder="Job Position" />

</h3>

<field name="category_ids" widget="many2many_tags" options="{'color_field': 'color', 'no_create_edit': True}" placeholder="Tags" groups="hr.group_hr_manager"/>

</div>

Avatar
Discard
Best Answer

Hi,

create a new sequence :

Settings>>Technical>> Sequences & Identifiers>>Sequence Codes. image description then

Settings>>Technical>> Sequences & Identifiers>>Sequences. image description

then create a new module to add a Employee Code

class hr_employee(osv.osv):
    _inherit = "hr.employee"

    def _get_code(self, cr, uid,context, *args):
        obj_sequence = self.pool.get('ir.sequence')    
        return obj_sequence.next_by_code(cr, uid, 'hr.employee.sequence', context=context)

    _columns = { 'code' : fields.char('Code', size=64), }

    _defaults = { 'code': _get_code, }

 hr_employee()

you can define this sequence in your module :

my_module_data.xml :

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data noupdate="0">
        <record model="ir.sequence.type" id="hr_employee_code_sequence">
            <field name="name">Code sequence hr employee</field>
            <field name="code">hr.employee.sequence</field>
        </record>
        <record model="ir.sequence" id="hr_employee_sequence">
            <field name="name">Sequence For employee</field>
            <field name="code">hr.employee.sequence</field>
            <field name="active">TRUE</field>
            <field name="prefix">EMP</field>
            <field name="number_increment">1</field>
            <field name="number_next">1000</field>
            <field name="implementation">standard</field>
        </record>       
    </data>
</openerp>

and in __openerp__.py:

"init_xml": ["my_module_data.xml"],

  • Also watch this video https://www.youtube.com/watch?v=ZfKzmfiqeg0&t=156s

Avatar
Discard

It's helping me alot.. Thanks MUHAMMAD

Good explanation