Skip to Content
Menu
This question has been flagged
3 Replies
1458 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
Author

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>

Best Answer

Try it for your problem.

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

Avatar
Discard
Author

thanks for the reply , i tired it still getting the same

Worked..

Author

still it showing the same , pls help what am doing wrong ?

Best Answer

Hi,

Refer the blog below to generate sequence for you model

https://www.cybrosys.com/blog/how-to-add-sequence-in-odoo-12

also refer the following forum post

https://www.odoo.com/forum/help-1/question/how-can-i-create-employee-code-in-a-sequence-field-21501

Regards

Avatar
Discard
Author

thanks for the reply , i tired it still getting the same