From b6d4d27ab8afd981fc63be877894daa6b79ed820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Mon, 11 Apr 2022 16:24:12 +0200 Subject: [PATCH] [FIX] privacy_consent: Avoid permissions error if the user does not have access to privacy. TT35907 --- privacy_consent/models/mail_mail.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/privacy_consent/models/mail_mail.py b/privacy_consent/models/mail_mail.py index c65e1ff..123d604 100644 --- a/privacy_consent/models/mail_mail.py +++ b/privacy_consent/models/mail_mail.py @@ -1,4 +1,5 @@ # Copyright 2018 Tecnativa - Jairo Llopis +# Copyright 2022 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo import models @@ -21,14 +22,15 @@ class MailMail(models.Model): and not failure_type ): res_ids.append(mail.mail_message_id.res_id) - consents = self.env["privacy.consent"].search([ - ("id", "in", res_ids), - ("state", "=", "draft"), - ("partner_id", "in", [par.id for par in success_pids]) - ]) - consents.write({ - "state": "sent", - }) + if res_ids: + consents = self.env["privacy.consent"].search([ + ("id", "in", res_ids), + ("state", "=", "draft"), + ("partner_id", "in", [par.id for par in success_pids]) + ]) + consents.write({ + "state": "sent", + }) return super()._postprocess_sent_message( success_pids=success_pids, failure_reason=failure_reason,