python - return self.browse((self._ids[key],)) IndexError: tuple index out of range : 当从 Odoo V13 中的讨论发送消息时
问题描述
每当在讨论模块上发送消息时,都会发生以下错误,我们将其配置为向用户 firebase_id 发送通知。
File "/odoo/odoo-server/addons/mail/models/mail_channel.py", line 368, in message_post
message = super(Channel, self.with_context(mail_create_nosubscribe=True)).message_post(message_type=message_type, moderation_status=moderation_status, **kwargs)**
File "/odoo/custom/addons/elite_event_management_api/controllers/message.py", line 34, in message_post
registration_id = channel_partner_id.partner_id.user_ids[0].firebase_id
File "/odoo/odoo-server/odoo/models.py", line 5624, in _getitem_
return self.browse((self._ids[key],))
IndexError: tuple index out of range
这是代码 - 所有用户都无法在讨论模块上发送消息。
import logging
from odoo import models, api
from odoo.exceptions import AccessDenied, UserError
logger = logging.getLogger(__name_)
class MailThred(models.AbstractModel):
_inherit = "mail.thread"
@api.returns('mail.message', lambda value: value.id)
def message_post(self, *,
body='', subject=None, message_type='notification',
email_from=None, author_id=None, parent_id=False,
subtype_id=False, subtype=None, partner_ids=None, channel_ids=None,
attachments=None, attachment_ids=None,
add_sign=True, record_name=False,
**kwargs):
res = super(MailThred, self).message_post(body=body, subject=subject, message_type=message_type,
email_from=email_from, author_id=author_id, parent_id=parent_id,
subtype_id=subtype_id, subtype=subtype, partner_ids=partner_ids, channel_ids=channel_ids,
attachments=attachments, attachment_ids=attachment_ids,
add_sign=add_sign, record_name=record_name,
**kwargs)
message_subtype_id = self.env['mail.message.subtype'].sudo().search([('name', 'ilike', 'Discussions')])
if res.message_type == 'comment' and res.subtype_id.id == message_subtype_id.id:
for each in res.channel_ids:
for channel_partner_id in each.channel_last_seen_partner_ids:
if channel_partner_id.partner_id.id != res.author_id.id:
from . import FCMManager as fcm
registration_id = channel_partner_id.partner_id.user_ids[0].firebase_id
if registration_id:
try:
tokens = [str(registration_id)]
message_title = "ControlE@ERP - CHAT"
message_body = res.body
fcm.sendPush(message_title, message_body, tokens)
_logger.info('ControlE@ERP Alert- NEW CHAT MESSAGE SENT')
except Exception as e:
_logger.info('not sent')
return res
解决方案
您在 channel_partner_id.partner_id.user_ids 中没有用户,因此您正在尝试从空列表中获取第 0 个元素,因此请检查您的代码并重试。
推荐阅读
- reactjs - 测试 redux 操作
- elixir - 将第二个孩子添加到主管会引发错误
- puppeteer - 如何在截屏之前使用无头 chrome / pupeteer 翻译页面语言?
- reactjs - useEffect 挂钩未正确设置状态对象
- internationalization - Wagtail 2.11.2 国际化,翻译的页面不会自动创建也无法访问
- c - 如何在 Kotlin/Native 中创建原始数据类型的 CPointer?
- reactjs - Usestate 在文本标签中不起作用并给我相同的值 React native hooks
- python - 配置 python sqlite3 模块以使用不同的(较新版本)sqlite 系统库(升级 sqlite)
- wordpress - “woocommerce_can_reduce_order_stock”过滤器在后端不起作用
- php - 在电子邮件中附加来自服务器的 .png 文件