Skip to Content
Menu
This question has been flagged
14 Replies
30021 Views

I want to create Employee Code in a sequence field. Please suggest.

Avatar
Discard

HI just go for various examples( like in sale ) module and look for sample reference field hope it will help

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"],
Avatar
Discard

I have an error Constraint Error

code must be unique

you can define a another sequence just replace <field name="code">hr.employee.sequence</field> to <field name="code">hr.employee.sequence2</field>

It works now.:) Thank you...

Hi, i tried your answer but i'm getting following error {Validate Error The value "crm.helpesk.sequence2" for the field "ir_sequence.code" is not in the selection }

@Borni This code is absolutely working. I want little different configuration. I have three companies-Software,Hardware,Factory. if employee 1 is in Software then employee id should be SOF001,...if employee 1 is in Hardware then employee id should be HAR001,...if employee 1 is in Factory then employee id should be FAC001,... how it generate automatically?

@Borni. Did you have any solution for my question?

@Borni, I have already wrote code this, but its not working. Can you please help me?

Best Answer

In odoo9 we can create a sequence code:

Create a new module name prod_quantity

 class prod_quantity(models.Model):     
  _name = 'products.car'

q_serial_no=fields.Char('Quantity Serial Number',default=lambda obj:

obj.env['ir.sequence'].next_by_code('products.car'))
View:

<form>

     <field name="q_serial_no"/>

</form>


 Create a new view file :

<openerp>

<data noupdate="0">

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

<field name="name">Sequence For Product</field>

<field name="code">products.car</field>

<field name="implementation">standard</field>

<field name="active">TRUE</field>

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

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

<field name="number_increment">1</field>

<field name="number_next_actual">1000</field>

</record>

</data>

</openerp>

Apply view file in openerp:

'data': [

'views/sequence.xml',

],

Avatar
Discard

It creates a sequence, but will advance the number even if you discard the new records, so it will skip numbers, how can that be fixed?

Best Answer

It creates a sequence, but will advance the number even if you discard the new records,  so it will skip numbers, how can that be fixed?

Avatar
Discard

please someone delete this post, I added my comment here by mistake

Related Posts Replies Views Activity
7
Nov 20
23139
11
Jan 19
8479
1
Jun 24
215
1
Dec 22
2438
3
Feb 19
8636