From e6e0d7ae78e0277b4a3956dbdb79546a63e7da8b Mon Sep 17 00:00:00 2001 From: Swapnesh Shah Date: Sat, 13 Oct 2018 11:58:11 +0000 Subject: [PATCH] [FIX] base,mail: do not include field attachments in attachment_count The _search was already excluding these attachments but not the read_group Avoid the read_group from mail to search on all existing attachments Fixes odoo/odoo#27673 closes odoo/odoo#27698 --- addons/mail/models/mail_thread.py | 2 +- odoo/addons/base/models/ir_attachment.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 5083773bbea..93a99011520 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -239,7 +239,7 @@ class MailThread(models.AbstractModel): @api.multi def _compute_message_attachment_count(self): - read_group_var = self.env['ir.attachment'].read_group([('res_model', '=', self._name)], + read_group_var = self.env['ir.attachment'].read_group([('res_id', 'in', self.ids), ('res_model', '=', self._name)], fields=['res_id'], groupby=['res_id']) diff --git a/odoo/addons/base/models/ir_attachment.py b/odoo/addons/base/models/ir_attachment.py index 40acf9be995..535605d9fe7 100644 --- a/odoo/addons/base/models/ir_attachment.py +++ b/odoo/addons/base/models/ir_attachment.py @@ -381,6 +381,15 @@ class IrAttachment(models.Model): if not (self.env.user._is_admin() or self.env.user.has_group('base.group_user')): raise AccessError(_("Sorry, you are not allowed to access this document.")) + @api.model + def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True): + """Override read_group to add res_field=False in domain if not present.""" + if not any(item[0] in ('id', 'res_field') for item in domain): + domain.insert(0, ('res_field', '=', False)) + return super(IrAttachment, self).read_group(domain, fields, groupby, + offset=offset, limit=limit, + orderby=orderby, lazy=lazy) + @api.model def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None): # add res_field=False in domain if not present; the arg[0] trick below