python - ODOO XMLRPC 调用自定义方法在同一模型上创建记录
问题描述
如果未提交创建方法并且客户端期望“self”作为参数,ODOO(V11) XMLRPC 调用自定义模型方法(测试)会出错。(我正在使用python)
class DataParser(models.Modle):
_name = "data.parser"
test_a: fields.Char()
test_b: fields.Char()
@api.one
def test(self):
obj = self.env['data.parser'].create({'test_a':"test a", 'test_b': "Test B "})
return True
客户端 XMLRPC
url = 'http://localhost:8069'
db = 'test'
username = 'admin'
password = 'admin'
logging.info("url {}, db {}".format(url, db))
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url), allow_none=True)
print(common.version())
val = common.login(db, username, password)
uid = common.authenticate(db, username, password, {})
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
val = models.execute_kw(db, uid, password, "data.parser", "test", ["self"])
错误 res = self._obj.execute(query, params)\npsycopg2.ProgrammingError: 关系“data_parser”的列“test_b”不存在\n第 1 行:插入到“data_parser”(“id”、“test_b”、“test_a”
解决方案
我们可以在 rpc 方法的 args 参数中发送 id!
像这样,我在颤振中使用过:
Future<dynamic> backToDraft(int id) { return Constants.odooRpc!.callKw({ 'model': 'account.payment', 'method': 'action_draft', 'args': [id], 'kwargs': {} }); }
推荐阅读
- powershell - 如何使用 Invoke-Sqlcmd (powershell) 在 Azure Sql 数据库中创建用户?
- c# - 从其他进程 C# 获取输入和输出
- javascript - 如何使用生成器函数作为事件侦听器内部的回调
- xcode - 找不到“Frameworks/App.framework/flutter_assets”的资产路径
- python - tkinter - 单选按钮可以控制多个变量吗?
- java - 如何为我的手机中安装的 whatsapp、facebook 或其他应用程序创建共享按钮
- java - 如何有效地比较两个产品列表
- linux - rm 命令未通过 cron 执行
- kubernetes - Windows pod 的名称解析在 1.18.1 上不起作用
- javascript - 修改嵌套对象中的值