首页 > 解决方案 > 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”

标签: pythonodooxml-rpc

解决方案


我们可以在 rpc 方法的 args 参数中发送 id!

像这样,我在颤振中使用过: Future<dynamic> backToDraft(int id) { return Constants.odooRpc!.callKw({ 'model': 'account.payment', 'method': 'action_draft', 'args': [id], 'kwargs': {} }); }


推荐阅读