从xml-rpc调用@ api.onchange [英] @api.onchange called from xml-rpc

查看:88
本文介绍了从xml-rpc调用@ api.onchange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个函数f. e.

I created a function f. e.

@api.onchange('zip')
def onchange_zip(self):
   self.name = "%s %s" % (self.name, self.zip)

当我通过界面更改zip字段时,它可以完美工作.但是,当我通过xml-rpc或其他任何api执行此操作时,不会触发它.有可能解决它的方法不同于重写写入,创建方法吗?

It works perfectly when I change the zip field by interface. But when I do it by xml-rpc or any other api it is not triggered. Is it possible to solve it different than overriding write, create methods?

推荐答案

@api.onchage用于即时更新内容,例如以edit模式更改Web界面中的字段并立即更新对其他领域的影响.每当您以其他方式更改相同的字段值时,例如通过python代码或odoo shell,或在此示例xmlrpc协议中,都不会调用@onchange函数.有很多解决方法,可以使用compute函数而不是@onchange,只要在@api.depends装饰器提到的记录字段中检测到任何更改,就会从orm级别触发计算功能.或者简单地说,只要您更改字段中的值,就可以手动调用@onchange方法.

@api.onchage is meant to be used to update something on the fly, for example changing something on field in the web interface in edit mode and immediately update the effect on other field. Whenever you change the same field value by other mean, for example from python code, or odoo shell, or in this example xmlrpc protocol, there is no call made to the @onchange function. There are number of ways to fix this, you can use compute function instead of @onchange, compute function is triggered from orm level, whenever any change is detected in the records field mentioned by @api.depends decorator. Or simply, you can just make a call to the @onchange method manually whenever you are changing the value in field.

这篇关于从xml-rpc调用@ api.onchange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆