Odoo Help


How to copy the value of one field to another on client side ..?

Nishant Kashyap
on 5/23/13, 4:16 AM 2,420 views

Hi, I have a char field name home_number and a Boolean field same_as_above and a char field name present_number, I was looking foe something, as I click the same_as_above field I want to copy the above value i.e home_number to the char field present_number.

Can I achieve this in Openerp V7 in views(XML). ..?

Nishant Kashyap
On 5/23/13, 5:12 AM

Okay I got the answer. In .py file

class MyFields(osv.osv):
         'home_number':fields.char('Home Number',size=100),
         'present_number':fields.char('Present Number',size=100)
def onchange_same_as_above(self,cr, uid, ids,same_as_above,home_number,context=None):
    if same_as_above:
        return {'value':{'present_number':home_number,}}
    return {'value':{}}

In XML file

<field name="home_number"/>
<field name="same_as_above" on_change="onchange_same_as_above(same_as_above,present_number)"/>
<field name="present_number"/>


| 5 4 7
Baarn, Netherlands
On 5/23/13, 4:22 AM

You want to use the boolean field to behave like a button?

To answer your question: No you cannot do this in XML (only). You need to write some code, and link that code to the field (probably on_change_<name field="">). The linking is done in XML, but the code in your custom python module.

On 5/29/14, 5:24 AM

Thanks for reply, I want when boolean field is True, then copy the value . In on_change I can use the values from the database , but I cant use the values that are on views , before saving the form ....

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.


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

0 follower(s)


Asked: 5/23/13, 4:16 AM
Seen: 2420 times
Last updated: 3/16/15, 8:10 AM