Skip to content

Commit

Permalink
fix(stats): make active patrons period 12 months
Browse files Browse the repository at this point in the history
- The correct date range for number_of_active_patrons in the pricing stats
should be 12 months and not the default `RERO_ILS_STATS_BILLING_TIMEFRAME_IN_MONTHS`.
- Fix isort 6.0.0 compatibility and update black formatter.

Co-Authored-by: Pascal Repond <[email protected]>
  • Loading branch information
PascalRepond committed Feb 4, 2025
1 parent 9d7de8c commit a674297
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 38 deletions.
69 changes: 40 additions & 29 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rero_ils/dojson/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def remove_trailing_punctuation(data, punctuation=",", spaced_punctuation=":;/-"
).rstrip()


def remove_special_characters(value, chars=["\u0098", "\u009C"]):
def remove_special_characters(value, chars=["\u0098", "\u009c"]):
"""Remove special characters from a string.
:params value: string to clean.
Expand Down
4 changes: 3 additions & 1 deletion rero_ils/modules/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

"""RERO ILS Record serialization."""

from invenio_records_rest.serializers.response import record_responsify
from invenio_records_rest.serializers.response import (
record_responsify,
)
from invenio_records_rest.serializers.response import (
search_responsify as _search_responsify,
)
Expand Down
7 changes: 6 additions & 1 deletion rero_ils/modules/stats/api/pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,16 @@ def number_of_active_patrons(self, library_pid):
:return: the number of matched active patrons
:rtype: integer
"""
_to = self.to_date.format(fmt="YYYY-MM-DDT23:59:59")
_from = (self.to_date - relativedelta(months=12)).format(
fmt="YYYY-MM-DDT00:00:00"
)
date_range = {"gte": _from, "lte": _to}
op_logs_query = (
LoanOperationLogsSearch()
.get_logs_by_trigger(
triggers=[ItemCirculationAction.CHECKOUT, ItemCirculationAction.EXTEND],
date_range=self.date_range,
date_range=date_range,
)
.filter("term", loan__item__library_pid=library_pid)
)
Expand Down
2 changes: 1 addition & 1 deletion rero_ils/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ def get_objects(record_class, query):

def strip_chars(string, extra=""):
"""Remove control characters from string."""
remove_re = re.compile("[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F%s]" % extra)
remove_re = re.compile("[\x00-\x08\x0b-\x0c\x0e-\x1f\x7f%s]" % extra)
new_string, _ = remove_re.subn("", string)
return new_string

Expand Down
4 changes: 3 additions & 1 deletion rero_ils/modules/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
manage_role_permissions,
)
from .permissions import permission_management as permission_management_action
from .permissions import record_permissions
from .permissions import (
record_permissions,
)

api_blueprint = Blueprint("api_blueprint", __name__, url_prefix="")

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/locations/test_locations_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

"""Other location Record tests.
Some tests cannot be added in other files for several reason such as
scope level fixtures.
Some tests cannot be added in other files for several reason such as
scope level fixtures.
"""

from rero_ils.modules.items.api import ItemsSearch
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/patron_transactions/test_patron_transactions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

import pytest

from rero_ils.modules.patron_transactions.api import PatronTransaction
from rero_ils.modules.patron_transactions.api import (
PatronTransaction,
)
from rero_ils.modules.patron_transactions.api import (
patron_transaction_id_fetcher as fetcher,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

""""Test permissions."""
"""Test permissions."""
from utils import login_user_for_view

from rero_ils.modules.permissions import has_superuser_access
Expand Down

0 comments on commit a674297

Please sign in to comment.