Odoo Help

0

onchange fields . it does not work.

By
huongcute
on 8/11/14, 11:25 PM 2,297 views

hi all. I created a module. I used field function onchange filed. so it does not change . Can you help me?

 

Code .py

class danh_sach_nv(osv.Model):
    _name = 'danh.sach.nv'
    _rec_name = 'ma_nv'
    
    def onchange_luong(self, cr, uid, ids, ma_nv, context=None):
        res = {}
        if ma_nv:
            obj = self.pool.get('dieu.chinh').browse(cr, uid, ma_nv)
            res['luong_ct'] = obj.luong_dc
            
            return {'value': res}
    _columns = {
                
               'ma_nv':fields.char('Mã NV',size=30),

               'luong_ct':fields.char('Lương chính thức',size = 20),

}

 

class dieu_chinh(osv.Model):
    _name = 'dieu.chinh'
    _columns = {
                'ma_nv':fields.many2one('danh.sach.nv', 'Mã NV'),
                'ten_nv':fields.related('ma_nv', 'ten_nv', type ='char', size = 50, string = 'Tên nhân viên'),
                'luong_ct':fields.related('ma_nv', 'luong_ct', type ='char', size = 50, string = 'Tên nhân viên'),
                'luong_dc':fields.char('Lương điều chỉnh', size = 20),
                'ly_do_dc': fields.char('Lý do điều chỉnh', size = 30),
                
                }

 

.xml 

<record model= 'ir.ui.view' id ='danh_sach_nv_form'>
            <field name ='name'>danh.sach.nv.form</field>
            <field name ='model'>danh.sach.nv</field>
            <field name = 'arch' type = 'xml'>
                <form string = 'Nhân viên' version = '7.0'>

                        <group>
   
                           <field name = 'ma_nv' on_change = 'onchange_luong(ma_nv)'/>

                             <field name = 'luong_ct'/>

                         </group>

I dont know What I make mistakes?

Can you help me?

 

8
Janeesh
On 8/12/14, 3:10 AM

Hi,

No need to change your code. Change the field type of field 'ma_nv' from char to many2one to object 'dieu.chinh'. Then you will get id of the record you selected in 'ma_nv' in the onchange function. Then you can browse with this id as you did.

 

 

0

Hi,

I think you should correct the following line. May be my assemption is right.

res['luong_ct'] = obj.luong_dc.name 

Note : If obj.luong_dc is filed like many2one then you have to assign its name to the char field 'luong_ct'.

So, your code may be like below.

 def onchange_luong(self, cr, uid, ids, ma_nv, context=None):

    res = {}
    if ma_nv:
        obj = self.pool.get('dieu.chinh').browse(cr, uid, ma_nv)
        res['luong_ct'] = obj.luong_dc.name
        
        return {'value': res}

    return {'value':res}

0
Jagdish Panchal
On 8/11/14, 11:53 PM

Hello,

Try this code

class danh_sach_nv(osv.Model):
    _name = 'danh.sach.nv'
    _rec_name = 'ma_nv'
    
    def onchange_luong(self, cr, uid, ids, ma_nv, context=None):
        res = {}
        if ma_nv:
            obj = self.pool.get('dieu.chinh').browse(cr, uid, ma_nv)
            res['luong_ct'] = obj.luong_dc
            
            return {'value': res}
        
    _columns = {
                
               'ma_nv':fields.many2one('dieu.chinh','Mã NV'),

               'luong_ct':fields.char('Lương chính thức',size = 20),

}

 

0
huongcute
On 8/12/14, 12:22 AM

I tried what you told me. but I dont understand why it did not work

What exactly you want do using this oncahnge method, which value you want fetch using this browse code >> self.pool.get('dieu.chinh').browse(cr, uid, ma_nv) ???

Jagdish Panchal
on 8/12/14, 1:11 AM

yes. I want when in objcet: dieu.chinh change value of fields ma_nv then value in object danh.sach.nv change and equal to value in field in dieu.chinh

huongcute
on 8/12/14, 2:32 AM

I have update ans. .. pls check it

Jagdish Panchal
on 8/12/14, 2:43 AM

you test my code ?? I checked it , but it did not work

huongcute
on 8/12/14, 3:09 AM

I tried your code . but it did not work as I want

huongcute
on 8/12/14, 5:40 AM

Update answer try it

Jagdish Panchal
on 8/12/14, 6:18 AM
I tried it, but it did not work. I dont understand


2014-08-12 17:18 GMT+07:00 Jagdish Panchal <jnp1682@mail.odoo.com>:

Update answer try it

--
Jagdish Panchal Sent by Odoo Inc. using Odoo. Access your messages and documents in Odoo

huongcute
on 8/12/14, 9:30 PM

I tried it, but it did not nothing.

huongcute
on 8/12/14, 9:57 PM

Can you help me? I dont understand your mean? Can you clear for me?

huongcute
on 8/13/14, 12:36 AM

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 8/11/14, 11:25 PM
Seen: 2297 times
Last updated: 3/16/15, 8:10 AM