From 5e83d9ebcb30ec27a81f2e837eabd65a3624da0e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Tue, 27 Jul 2021 14:34:08 +0200
Subject: [PATCH] backoffice: fix error count displayed (#55810)

---
 tests/admin_pages/test_logged_errors.py |  6 ++++++
 wcs/admin/logged_errors.py              | 18 ++++++------------
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/tests/admin_pages/test_logged_errors.py b/tests/admin_pages/test_logged_errors.py
index 523448c1..a0474867 100644
--- a/tests/admin_pages/test_logged_errors.py
+++ b/tests/admin_pages/test_logged_errors.py
@@ -136,6 +136,8 @@ def test_listing_paginations(pub):
     assert resp.text.count('Logged Error n°') == 17
 
     # formdef errors
+    resp = app.get('/backoffice/forms/%s/' % formdef.id)
+    assert '21 errors' in resp
     resp = app.get('/backoffice/forms/%s/logged-errors/' % formdef.id)
     assert '1-20/21' in resp.text
     assert resp.text.count('FormDef Workflow Logged Error n°') == 20
@@ -144,6 +146,8 @@ def test_listing_paginations(pub):
     assert resp.text.count('FormDef Workflow Logged Error n°') == 1
 
     # carddef errors
+    resp = app.get('/backoffice/cards/%s/' % carddef.id)
+    assert '21 errors' in resp
     resp = app.get('/backoffice/cards/%s/logged-errors/' % carddef.id)
     assert '1-20/21' in resp.text
     assert resp.text.count('CardDef Workflow Logged Error n°') == 20
@@ -152,6 +156,8 @@ def test_listing_paginations(pub):
     assert resp.text.count('CardDef Workflow Logged Error n°') == 1
 
     # workflows errors
+    resp = app.get('/backoffice/workflows/%s/' % workflow.id)
+    assert '63 errors' in resp
     resp = app.get('/backoffice/workflows/%s/logged-errors/' % workflow.id)
     assert '1-20/63' in resp.text
     assert resp.text.count('Workflow Logged Error n°') == 20
diff --git a/wcs/admin/logged_errors.py b/wcs/admin/logged_errors.py
index 1c08c8ac..1c3841df 100644
--- a/wcs/admin/logged_errors.py
+++ b/wcs/admin/logged_errors.py
@@ -110,9 +110,7 @@ class LoggedErrorsDirectory(Directory):
     _q_exports = ['']
 
     @classmethod
-    def get_errors(
-        cls, offset, limit, formdef_class=None, formdef_id=None, workflow_id=None, with_total=False
-    ):
+    def get_errors(cls, offset, limit, formdef_class=None, formdef_id=None, workflow_id=None):
         errors = []
         if not get_publisher().loggederror_class:
             return errors, 0
@@ -141,19 +139,16 @@ class LoggedErrorsDirectory(Directory):
                 clauses.append(NotNull('formdef_class'))
 
         errors = get_publisher().loggederror_class.select(clause=clauses, **select_kwargs)
-
-        count = 0
-        if with_total:
-            count = get_publisher().loggederror_class.count(clauses)
+        count = get_publisher().loggederror_class.count(clauses)
 
         return list(errors), count
 
     @classmethod
     def errors_block(cls, formdef_class=None, formdef_id=None, workflow_id=None):
         # select 3 + 1 last errors
-        errors = cls.get_errors(
+        errors, total = cls.get_errors(
             offset=0, limit=4, formdef_class=formdef_class, formdef_id=formdef_id, workflow_id=workflow_id
-        )[0]
+        )
         if not errors:
             return ''
 
@@ -161,8 +156,8 @@ class LoggedErrorsDirectory(Directory):
         r += htmltext('<div class="bo-block logged-errors">')
         r += (
             htmltext('<h3><a href="logged-errors/">%s</a></h3>')
-            % ngettext('%(count)d error', '%(count)d errors', len(errors))
-            % {'count': len(errors)}
+            % ngettext('%(count)d error', '%(count)d errors', total)
+            % {'count': total}
         )
         r += htmltext('<ul>')
         for error in errors[:3]:
@@ -208,7 +203,6 @@ class LoggedErrorsDirectory(Directory):
             formdef_class=self.formdef_class,
             formdef_id=self.formdef_id,
             workflow_id=self.workflow_id,
-            with_total=True,
         )
         links = ''
         if get_publisher().is_using_postgresql():
-- 
2.30.2

