@api.onchange called from xml-rpc

拥有回忆 提交于 2019-12-23 10:28:27

问题


I created a function f. e.

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

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?


回答1:


@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.



来源:https://stackoverflow.com/questions/54307066/api-onchange-called-from-xml-rpc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!