Odoo Help


Odoo 8 api onchange example | How to copy field value to other field

George Rodopoulos
on 1/31/15, 11:18 PM 18,935 views

Can you provide a simple example on how to use the new api onchange method in order to copy the value of one field to another?

Related documentation here:

Here is what I tried to do:

For every project task I want the task name (task summary) to load the name of the chosen project.

So in my custom module (in the .py file) I tried

from openerp import api
from openerp.osv import fields, osv
class custom_tasks(osv.osv):
    _inherit = "project.task"
    @api.onchange('project_id') # if these fields are changed, call method
    def check_change(self):
        self.name:value = self.project_id:value
    _columns = {
        'custom_tasks_abc': fields.char('Abc', size=30),
        'custom_tasks_xyz': fields.char('Xyz', size=30),

The documentation says there is no need to change the view in order to run something with 'onchange'.

The above code is not working. What should I do to make it work?




Akhil P Sivan

--Akhil P Sivan--

| 5 4 7
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 2/1/15, 3:01 AM

Hi George,

Try like this:

from openerp import models, fields, api
class custom_tasks(models.Model):
    _inherit = "project.task"
   custom_tasks_abc =  fields.Char('Abc', size=30)
   custom_tasks_xyz = fields.Char('Xyz', size=30)

   @api.onchange('project_id') # if these fields are changed, call method
   def _check_change(self):
        self.name = self.project_id.name

This worked as expected. Thanks! I also forgot to add from openerp import api

George Rodopoulos
on 2/1/15, 1:28 PM

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

1 follower(s)


Asked: 1/31/15, 11:18 PM
Seen: 18935 times
Last updated: 3/16/15, 8:10 AM