在Odoo 13中,使用XML-RPC,如何更新多个记录的字段?

huangapple go评论49阅读模式
英文:

In Odoo 13, XML-RPC, how can I update a field for multiple records?

问题

I'm attempting to update a field for multiple records.

尝试更新多个记录的字段。

The Odoo 13 Developer API document reads that it is possible, but does not give an example how.

Odoo 13开发者API文档中提到这是可能的,但没有提供示例。

"Multiple records can be updated simultaneously, but they will all get the same values for the fields being set."

"可以同时更新多个记录,但它们将获得相同的字段值。"

The below does not work:

以下代码不起作用:

models.execute_kw(db, uid, pw, 'table.name', 'write',
[[records_to_update], {'field': value}])

records_to_update is a list of the record ids.

records_to_update是记录ID的列表。

I receive this error:

我收到以下错误消息:

"-> message_values = dict((message_id, {}) for message_id in self.ids)"

I have spent quite some time searching for an answer and have come up blank so far.

我花了相当多的时间搜索答案,但迄今为止一无所获。

英文:

I'm attempting to update a field for multiple records.

The Odoo 13 Developer API document reads that it is possible, but does not give an example how.

https://www.odoo.com/documentation/13.0/developer/api/odoo.html#update-records

"Multiple records can be updated simultaneously, but they will all get the same values for the fields being set."

The below does not work:

    models.execute_kw(db, uid, pw, 'table.name', 'write',
                                   [[records_to_update], {'field': value}])

records_to_update is a list of the record ids.

I receive this error:

"-> message_values = dict((message_id, {}) for message_id in self.ids)"

I have spent quite some time searching for an answer and have come up blank so far.

答案1

得分: 1

应该看到以下错误消息:

不可哈希类型:'list'

records_to_update 是记录标识的列表,应该是 write 函数的第一个参数

示例:

models.execute_kw(db, uid, pw, 'table.name', 'write',
                                   [records_to_update, {'field': value}])
英文:

You should see the following error message:

unhashable type: 'list' 

records_to_update is a list of the record ids and it should be the first argument to the write function

Example:

models.execute_kw(db, uid, pw, 'table.name', 'write',
                                   [records_to_update, {'field': value}])

huangapple
  • 本文由 发表于 2023年6月12日 22:36:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76457722.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定