From a3509d282d59b38e9b4c032c287e1d779000ba64 Mon Sep 17 00:00:00 2001
From: Damien Bouvy <dbo@odoo.com>
Date: Wed, 12 Oct 2016 11:21:25 +0200
Subject: [PATCH] [FIX] mail: use explicit 'active' domain for user count in
 ping

Before the migration to the new API of this code, the context was
not propagated to the update_notification call.

This is now the case, which is unfortunate since the context of the
cron action has an 'active_test'=False key, which causes the ping
to count user differently when the cron is triggered from the form
view.

This commit adds explicit ('active','=',True) domain to ensure we
only count active users when pinging.
---
 addons/mail/models/update.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/addons/mail/models/update.py b/addons/mail/models/update.py
index a5717353a79e..7e2abfcbfd81 100644
--- a/addons/mail/models/update.py
+++ b/addons/mail/models/update.py
@@ -31,13 +31,13 @@ class PublisherWarrantyContract(AbstractModel):
         limit_date = datetime.datetime.now()
         limit_date = limit_date - datetime.timedelta(15)
         limit_date_str = limit_date.strftime(misc.DEFAULT_SERVER_DATETIME_FORMAT)
-        nbr_users = Users.search_count([])
-        nbr_active_users = Users.search_count([("login_date", ">=", limit_date_str)])
+        nbr_users = Users.search_count([('active', '=', True)])
+        nbr_active_users = Users.search_count([("login_date", ">=", limit_date_str), ('active', '=', True)])
         nbr_share_users = 0
         nbr_active_share_users = 0
         if "share" in Users._fields:
-            nbr_share_users = Users.search_count([("share", "=", True)])
-            nbr_active_share_users = Users.search_count([("share", "=", True), ("login_date", ">=", limit_date_str)])
+            nbr_share_users = Users.search_count([("share", "=", True), ('active', '=', True)])
+            nbr_active_share_users = Users.search_count([("share", "=", True), ("login_date", ">=", limit_date_str), ('active', '=', True)])
         user = self.env.user
         domain = [('application', '=', True), ('state', 'in', ['installed', 'to upgrade', 'to remove'])]
         apps = self.env['ir.module.module'].sudo().search_read(domain, ['name'])
-- 
GitLab