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

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

By
George Rodopoulos
on 1/31/15, 11:18 PM 8,876 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:
https://www.odoo.com/documentation/8.0/reference/orm.html#onchange-updating-ui-on-the-fly

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),
    }
dietech_tasks()

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?

 

 

3

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
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

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: 1/31/15, 11:18 PM
Seen: 8876 times
Last updated: 3/16/15, 8:10 AM