Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
680 views
in Technique[技术] by (71.8m points)

python - ODOO XMLRPC calling custom method which create a record on the same model

ODOO(V11) XMLRPC calling on custom model method (test) is through an error if a create method is uncommitted and client expect "self" as argument. (I am using 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

Client 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"])

Error res = self._obj.execute(query, params) psycopg2.ProgrammingError: column "test_b" of relation "data_parser" does not exist LINE 1: INSERT INTO "data_parser" ("id", "test_b", "test_a

question from:https://stackoverflow.com/questions/66060811/odoo-xmlrpc-calling-custom-method-which-create-a-record-on-the-same-model

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You probably did not update the module.

When you called test method you passed test as the first parameter in the place of the id, odoo will evaluate it to the following recordset:

data.parser('self',)

Calling the create method using that record set will not raise an error and the new created record will be returned. No error will be raised.

When we try to call the create method with an unknown field, we get the following error in the log:

data.parser.create() includes unknown fields: field_name

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...