问题
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