在 Odoo 15 中自动添加多个用户作为关注者

发布于 2025-01-11 22:34:21 字数 639 浏览 0 评论 0原文

我创建了一个自定义模块,您可以在其中链接多对多字段中的多个联系人,我想自动将它们全部添加为关注者。我读过这篇文章:

将用户添加为关注者的自动操作Odoo 12

添加关注者效果很好,但前提是字段中有一个用户或合作伙伴。在我的安装中,这些是很多字段。当我在其中一个字段中添加多个用户或合作伙伴时,代码崩溃。

当我想在其中一个字段中添加超过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

极致的悲 2025-01-18 22:34:21

当有多个记录时,您不能使用.id来获取记录的id,您必须使用.ids来返回记录id的列表。所以你的代码必须改为:

field1_ids = record.field1.ids
field2_ids = record.field2.mapped('partner_id').ids
field3_ids = record.field3.mapped('partner_id').ids
record.message_subscribe(partner_ids=field1_ids+field2_ids+field3_ids)

所以你的代码的主要问题是,你试图访问记录可能是多个的字段(如 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:

field1_ids = record.field1.ids
field2_ids = record.field2.mapped('partner_id').ids
field3_ids = record.field3.mapped('partner_id').ids
record.message_subscribe(partner_ids=field1_ids+field2_ids+field3_ids)

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 give Expected Singletone error for multiple records.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文