Browse Source
Merge pull request #26 from Tecnativa/10.0-privacy_consent-fix_race_with_mail_queue
[FIX] privacy_consent: Avoid race condition with mail queue cron
pull/29/head
Pedro M. Baeza
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with
5 additions and
26 deletions
-
privacy_consent/__init__.py
-
privacy_consent/models/mail_mail.py
-
privacy_consent/models/privacy_activity.py
-
privacy_consent/models/privacy_consent.py
-
privacy_consent/wizards/__init__.py
-
privacy_consent/wizards/mail_compose_message.py
|
|
@ -1,3 +1,2 @@ |
|
|
|
from . import controllers |
|
|
|
from . import models |
|
|
|
from . import wizards |
|
|
@ -10,7 +10,7 @@ class MailMail(models.Model): |
|
|
|
|
|
|
|
def _postprocess_sent_message(self, mail_sent=True): |
|
|
|
"""Write consent status after sending message.""" |
|
|
|
if mail_sent and self.env.context.get('mark_consent_sent'): |
|
|
|
if mail_sent: |
|
|
|
# Get all mails sent to consents |
|
|
|
consent_mails = self.filtered( |
|
|
|
lambda one: one.mail_message_id.model == "privacy.consent" |
|
|
@ -37,7 +37,7 @@ class MailMail(models.Model): |
|
|
|
""" |
|
|
|
result = super(MailMail, self).send_get_mail_body(partner=partner) |
|
|
|
# Avoid polluting other model mails |
|
|
|
if self.env.context.get("active_model") != "privacy.consent": |
|
|
|
if self.model != "privacy.consent": |
|
|
|
return result |
|
|
|
# Tokenize consent links |
|
|
|
consent = self.env["privacy.consent"] \ |
|
|
|
|
|
@ -120,11 +120,10 @@ class PrivacyActivity(models.Model): |
|
|
|
# Skip activitys where consent is not required |
|
|
|
for one in self.with_context(active_test=False) \ |
|
|
|
.filtered("consent_required"): |
|
|
|
domain = safe_eval(one.subject_domain) |
|
|
|
domain += [ |
|
|
|
domain = [ |
|
|
|
("id", "not in", one.mapped("consent_ids.partner_id").ids), |
|
|
|
("email", "!=", False), |
|
|
|
] |
|
|
|
] + safe_eval(one.subject_domain) |
|
|
|
# Create missing consent requests |
|
|
|
for missing in self.env["res.partner"].search(domain): |
|
|
|
consents |= consents.create({ |
|
|
|
|
|
@ -104,8 +104,7 @@ class PrivacyConsent(models.Model): |
|
|
|
consents_by_template = {} |
|
|
|
for one in self.with_context(tpl_force_default_to=True, |
|
|
|
mail_notify_user_signature=False, |
|
|
|
mail_auto_subscribe_no_notify=True, |
|
|
|
mark_consent_sent=True): |
|
|
|
mail_auto_subscribe_no_notify=True): |
|
|
|
# Group consents by template, to send in batch where possible |
|
|
|
template_id = one.activity_id.consent_template_id.id |
|
|
|
consents_by_template.setdefault(template_id, one) |
|
|
@ -168,7 +167,6 @@ class PrivacyConsent(models.Model): |
|
|
|
"default_res_id": self.id, |
|
|
|
"default_template_id": self.activity_id.consent_template_id.id, |
|
|
|
"default_use_template": True, |
|
|
|
"mark_consent_sent": True, |
|
|
|
"tpl_force_default_to": True, |
|
|
|
}, |
|
|
|
"force_email": True, |
|
|
|
|
|
@ -1 +0,0 @@ |
|
|
|
from . import mail_compose_message |
|
|
@ -1,16 +0,0 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
# Copyright 2018 Tecnativa - Jairo Llopis |
|
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
|
|
|
|
|
|
|
from odoo import api, models |
|
|
|
|
|
|
|
|
|
|
|
class MailComposeMessage(models.TransientModel): |
|
|
|
_inherit = "mail.compose.message" |
|
|
|
|
|
|
|
@api.multi |
|
|
|
def send_mail(self, auto_commit=False): |
|
|
|
"""Force auto commit when sending consent emails.""" |
|
|
|
if self.env.context.get('mark_consent_sent'): |
|
|
|
auto_commit = True |
|
|
|
return super(MailComposeMessage, self).send_mail(auto_commit) |