Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
14 Trả lời
31682 Lượt xem

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

Ảnh đại diện
Huỷ bỏ

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

Câu trả lời hay nhất

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"],
Ảnh đại diện
Huỷ bỏ

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?

Câu trả lời hay nhất

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

],

Ảnh đại diện
Huỷ bỏ

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?

Câu trả lời hay nhất

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?

Ảnh đại diện
Huỷ bỏ

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
7
thg 11 20
25019
11
thg 1 19
9985
1
thg 6 24
1548
1
thg 12 22
4133
3
thg 2 19
9944