Skip to content

Commit

Permalink
pricing stats: fix number of ill requests
Browse files Browse the repository at this point in the history
* Fix the count of number of ILL request to be coherent with RERO+'s
pricing criteria. All ILL requests created within the timeframe
except those with the status "denied" are counted.
* The calculation is simplified and does not use operation logs, which
created problems.

Co-Authored-by: Pascal Repond <pascal.repond@rero.ch>
  • Loading branch information
PascalRepond committed Oct 24, 2023
1 parent 63376d9 commit 158793e
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions rero_ils/modules/stats/api/pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
from rero_ils.modules.acquisition.acq_order_lines.api import \
AcqOrderLinesSearch
from rero_ils.modules.documents.api import DocumentsSearch
from rero_ils.modules.ill_requests.api import ILLRequestsSearch
from rero_ils.modules.ill_requests.models import ILLRequestStatus
from rero_ils.modules.items.api import ItemsSearch
from rero_ils.modules.items.models import ItemCirculationAction
from rero_ils.modules.libraries.api import LibrariesSearch
from rero_ils.modules.loans.logs.api import LoanOperationLogsSearch
from rero_ils.modules.operation_logs.api import OperationLog, \
OperationLogsSearch
from rero_ils.modules.operation_logs.api import OperationLog
from rero_ils.modules.patrons.api import PatronsSearch
from rero_ils.modules.stats.api.api import StatsSearch
from rero_ils.modules.users.models import UserRole
Expand Down Expand Up @@ -114,9 +114,9 @@ def process(self, library):
'number_of_renewals':
self.number_of_circ_operations(
library.pid, ItemCirculationAction.EXTEND),
'number_of_validated_ill_requests':
self.number_of_ill_requests_operations(
library.pid, [ILLRequestStatus.VALIDATED]),
'number_of_ill_requests':
self.number_of_ill_requests(
library.pid, [ILLRequestStatus.DENIED]),
'number_of_items': self.number_of_items(library.pid),
'number_of_new_items': self.number_of_new_items(library.pid),
'number_of_deleted_items': self.number_of_deleted_items(
Expand Down Expand Up @@ -209,20 +209,18 @@ def number_of_circ_operations(self, library_pid, trigger):
).filter('term', loan__item__library_pid=library_pid)\
.count()

def number_of_ill_requests_operations(self, library_pid, status):
"""Number of ILL requests creation or update operations.
def number_of_ill_requests(self, library_pid, status):
"""Number of existing ILL requests for a time range and a library.
:param library_pid: string - the library to filter with
:param status: list of status to filter with
:return: the number of matched inter library loan request
:param status: list of statuses to exclude from the count
:return: the number of matched inter library loan requests
:rtype: integer
"""
query = OperationLogsSearch()\
.filter('term', record__type='illr')\
.filter('terms', operation=['update', 'create'])\
query = ILLRequestsSearch()\
.filter('range', _created=self.date_range)\
.filter('term', ill_request__library_pid=library_pid)\
.filter('terms', ill_request__status=status)
.filter('term', library__pid=library_pid)\
.exclude('terms', status=status)
return query.count()

# -------- optional -----------
Expand Down

0 comments on commit 158793e

Please sign in to comment.