在 Odoo 15 中自动添加多个用户作为关注者
我创建了一个自定义模块,您可以在其中链接多对多字段中的多个联系人,我想自动将它们全部添加为关注者。我读过这篇文章:
添加关注者效果很好,但前提是字段中有一个用户或合作伙伴。在我的安装中,这些是很多字段。当我在其中一个字段中添加多个用户或合作伙伴时,代码崩溃。
当我想在其中一个字段中添加超过 1 个联系人或用户时,是否需要更改此代码中的某些内容?
我的自动操作中有这个 python 代码:
record.message_subscribe(partner_ids=[record.field1.id, record.field2.partner_id.id, record.field3.partner_id.id])
字段1 = 合作伙伴
字段2 &字段3=用户
感谢您的帮助!
I created a custom module where you can link multiple contacts in a many2many field and I want to automatically add them all as a follower. I've read this article:
Automated Action to Add Users as Followers Odoo 12
Adding followers works fine, but only when the fields have ONE user or partner in it. In my installation these are many2many fields. When I add more then one user or partner in one of the fields, the code crashes.
Do I need to change something in this code when I want to add more then 1 contact or user in one of the fields?
I have this python code in my automated action:
record.message_subscribe(partner_ids=[record.field1.id, record.field2.partner_id.id, record.field3.partner_id.id])
field1 = partner
field2 & field3 = user
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当有多个记录时,您不能使用
.id
来获取记录的id,您必须使用.ids
来返回记录id的列表。所以你的代码必须改为:所以你的代码的主要问题是,你试图访问记录可能是多个的字段(如
many2many
),但在 Odoo ORM 中你不能这样做也就是说,对于多条记录,它总是会给出Expected Singletone
错误。You can not use
.id
to get id of records when there is multiple record, you have to use.ids
which returns a list of record ids. So you code will have to changed into:So the main issue with your code was, you were trying to access field where the record could be multiple (as
many2many
), but in Odoo ORM you can not do that, it will always giveExpected Singletone
error for multiple records.