From 2718b801465253e3b2a578ded49e0790a276ba7d Mon Sep 17 00:00:00 2001 From: Uku Lagle Date: Mon, 30 Mar 2020 19:41:27 +0300 Subject: [PATCH] [FIX] mail_tracking: do not warn not found if already opened The state will be 'opened' after first time email is opened. Each successive open triggered warning, because state was already 'opened' and thus did not match domain state in (sent, delivered). Forward-port #d9ad3464 --- mail_tracking/controllers/main.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/mail_tracking/controllers/main.py b/mail_tracking/controllers/main.py index cf111c3..ec6f641 100644 --- a/mail_tracking/controllers/main.py +++ b/mail_tracking/controllers/main.py @@ -81,18 +81,14 @@ class MailTrackingController(MailController): with db_env(db) as env: try: tracking_email = env["mail.tracking.email"].search( - [ - ("id", "=", tracking_email_id), - ("state", "in", ["sent", "delivered"]), - ("token", "=", token), - ] + [("id", "=", tracking_email_id), ("token", "=", token)] ) - if tracking_email: - tracking_email.event_create("open", metadata) - else: + if not tracking_email: _logger.warning( "MailTracking email '%s' not found", tracking_email_id ) + elif tracking_email.state in ("sent", "delivered"): + tracking_email.event_create("open", metadata) except Exception: pass