跳至內容
選單
此問題已被標幟
1 回覆
33795 瀏覽次數

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?

 

 

頭像
捨棄
最佳答案

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