Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How can I create Employee Code in a sequence field

By
Debashis Das
on 6/18/13, 3:58 AM 7,860 views

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

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

Abhishek
on 6/18/13, 5:38 AM
6

Borni DHIFI

--Borni DHIFI--
5102
| 6 8 9
Tunis, Tunisia
--Borni DHIFI--

Techno Functional Consultant Odoo(OpenERP) 

http://www.linkedin.com/in/borni

Skype : dhifi.borni

Borni DHIFI
On 6/18/13, 5:45 AM

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

I have an error Constraint Error

code must be unique

Urpit Timbadiya
on 8/22/13, 12:45 PM

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

Borni DHIFI
on 8/22/13, 7:05 PM

It works now.:) Thank you...

Urpit Timbadiya
on 8/23/13, 2:55 AM

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 }

Sam path
on 3/27/14, 3:32 AM

@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?

Remya
on 4/4/14, 9:30 AM

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

Remya
on 4/4/14, 9:54 AM

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

Remya
on 4/4/14, 10:25 AM
1
kirubanidhi
On 7/5/16, 5:01 AM

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',

],

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/18/13, 3:58 AM
Seen: 7860 times
Last updated: 7/5/16, 5:01 AM