diff --git a/privacy_consent/models/mail_mail.py b/privacy_consent/models/mail_mail.py index e0b7e37..583fa38 100644 --- a/privacy_consent/models/mail_mail.py +++ b/privacy_consent/models/mail_mail.py @@ -12,20 +12,24 @@ class MailMail(models.Model): ): """Write consent status after sending message.""" # Know if mail was successfully sent to a privacy consent - if ( - self.mail_message_id.model == "privacy.consent" - and self.state == "sent" - and success_pids - and not failure_reason - and not failure_type - ): - # Get related consent - consent = self.env["privacy.consent"].browse(self.mail_message_id.res_id) - # Set as sent if needed - if consent.state == "draft" and consent.partner_id.id in { - par.id for par in success_pids - }: - consent.write({"state": "sent"}) + res_ids = [] + for mail in self: + if ( + mail.mail_message_id.model == "privacy.consent" + and mail.state == "sent" + and success_pids + and not failure_reason + 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"}) return super()._postprocess_sent_message( success_pids=success_pids, failure_reason=failure_reason,