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

onchange fields . it does not work.

By
huongcute
on 8/11/14, 11:25 PM 1,826 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?

 

4

Janeesh

--Janeesh--
1641
| 4 3 4
Cochin, India
--Janeesh--

Odoo Developer

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

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5975
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.

 

Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 

 

We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :

 

  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 8/12/14, 2:16 AM

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

--Jagdish Panchal--
2674
| 5 3 6
Gandhinagar, India
--Jagdish Panchal--

OpenERP Developer

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

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: 8/11/14, 11:25 PM
Seen: 1826 times
Last updated: 3/16/15, 8:10 AM