Skip to content

Commit

Permalink
issue: fix creation of late issue
Browse files Browse the repository at this point in the history
Closes #1807.

Co-Authored-by: Renaud Michotte <renaud.michotte@gmail.com>
  • Loading branch information
zannkukai committed May 4, 2021
1 parent f33319e commit 85eca4a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"second_call_number",
"holdings_type",
"enumerationAndChronology",
"acquisition_status",
"patterns",
"vendor",
"supplementaryContent",
"index",
"missing_issues",
"issue_binding",
"acquisition_status",
"acquisition_method",
"acquisition_expected_end_date",
"general_retention_policy",
Expand Down Expand Up @@ -666,6 +666,7 @@
"acquisition_status": {
"title": "Acquisition status",
"type": "string",
"default": "currently_received",
"enum": [
"unknown",
"other_receipt_or_acquisition_status",
Expand Down Expand Up @@ -705,7 +706,10 @@
"label": "unknown",
"value": "unknown"
}
]
],
"expressionProperties": {
"templateOptions.required": "model.holdings_type === 'serial'"
}
}
},
"acquisition_method": {
Expand Down
15 changes: 8 additions & 7 deletions rero_ils/modules/items/api/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,19 @@ def get_issues_by_status(cls, issue_status, holdings_pid=None):
def get_late_serial_holdings_pids(cls):
"""Return pids for all late holdings.
The holdings is considered late if the it is of type serial and the
next expected date has passed (greater than current datetime).
The holdings is considered late if :
* it is of type serial
* it is considerate as alive (acq_status='currently_received')
* next expected date has passed (greater than current datetime).
:return a generator of holdings pid.
"""
from ...holdings.api import HoldingsSearch
current_date = datetime.now(timezone.utc).strftime('%Y-%m-%d')
query = HoldingsSearch() \
today = datetime.now(timezone.utc).strftime('%Y-%m-%d')
results = HoldingsSearch() \
.filter('term', holdings_type='serial') \
.filter('range',
patterns__next_expected_date={'lte': current_date})
results = query\
.filter('term', acquisition_status='currently_received') \
.filter('range', patterns__next_expected_date={'lte': today}) \
.params(preserve_order=True) \
.sort({'_created': {'order': 'asc'}}) \
.source(['pid']).scan()
Expand Down
1 change: 1 addition & 0 deletions tests/data/holdings.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"$ref": "https://ils.rero.ch/api/locations/loc7"
},
"holdings_type": "serial",
"acquisition_status": "currently_received",
"patterns": {
"template": "no {{first_enumeration.level_1}} {{first_chronology.level_2}} {{first_chronology.level_1}}",
"frequency": "rdafr:1010",
Expand Down
47 changes: 34 additions & 13 deletions tests/ui/holdings/test_serial_claims.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

from __future__ import absolute_import, print_function

from copy import deepcopy
from datetime import datetime, timedelta, timezone

from rero_ils.modules.holdings.api import Holding
from rero_ils.modules.items.api import Item
from rero_ils.modules.items.models import ItemIssueStatus
from rero_ils.modules.items.tasks import process_late_claimed_issues
Expand All @@ -40,19 +42,23 @@ def count_issues(holding):
output format: [late_issues_count, claimed_issues_count]
"""
late_issues = len(list(Item.get_issues_by_status(
issue_status=ItemIssueStatus.LATE, holdings_pid=holding.pid)))
claimed_issues = len(list(Item.get_issues_by_status(
issue_status=ItemIssueStatus.CLAIMED, holdings_pid=holding.pid)))
return [late_issues, claimed_issues]
late_issues = list(Item.get_issues_by_status(
issue_status=ItemIssueStatus.LATE,
holdings_pid=holding.pid
))
claimed_issues = list(Item.get_issues_by_status(
issue_status=ItemIssueStatus.CLAIMED,
holdings_pid=holding.pid
))
return [len(late_issues), len(claimed_issues)]

# these two holdings has no late or claimed issues
assert count_issues(martigny) == [0, 0]
assert count_issues(sion) == [0, 0]

# for these holdings records, the next expected date is already passed
# system will receive the issue and change its status to late
msg = process_late_claimed_issues(dbcommit=True, reindex=True)
process_late_claimed_issues(dbcommit=True, reindex=True)
assert count_issues(martigny) == [1, 0]
assert count_issues(sion) == [1, 0]

Expand All @@ -63,12 +69,25 @@ def count_issues(holding):
martigny['patterns']['next_expected_date'] = yesterday.strftime('%Y-%m-%d')
martigny.update(martigny, dbcommit=True, reindex=True)

msg = process_late_claimed_issues(dbcommit=True, reindex=True)
process_late_claimed_issues(dbcommit=True, reindex=True)
assert count_issues(martigny) == [2, 0]
assert count_issues(sion) == [1, 0]

# test the claiming process
# change the acq_status of Martigny holding.
# as Martigny holding isn't yet considerate as alive, no new issue should
# be generated. The late issue count still the same (=2)
martigny = Holding.get_record_by_pid(martigny.pid)
martigny_data = deepcopy(martigny)
date2 = datetime.now() - timedelta(days=1)
martigny['patterns']['next_expected_date'] = date2.strftime('%Y-%m-%d')
martigny['acquisition_status'] = 'not_currently_received'
martigny.update(martigny, dbcommit=True, reindex=True)
process_late_claimed_issues(dbcommit=True, reindex=True)
assert count_issues(martigny) == [2, 0] # no new late issue than before
# reset Martigny holding
martigny.update(martigny_data, dbcommit=True, reindex=True)

# -- test the claiming process
# create a first claim for an issue and the claim_counts will increment
late_issue = list(Item.get_issues_by_status(
issue_status=ItemIssueStatus.LATE, holdings_pid=martigny.pid))[0]
Expand All @@ -79,9 +98,11 @@ def count_issues(holding):
late_issue.update(late_issue, dbcommit=True, reindex=True)

assert late_issue.claims_count == 0

msg = process_late_claimed_issues(
create_next_claim=False, dbcommit=True, reindex=True)
process_late_claimed_issues(
create_next_claim=False,
dbcommit=True,
reindex=True
)
assert count_issues(martigny) == [1, 1]
assert count_issues(sion) == [1, 0]
late_issue = Item.get_record_by_pid(late_issue.pid)
Expand All @@ -93,13 +114,13 @@ def count_issues(holding):
- timedelta(days=martigny.days_before_next_claim + 1)
).isoformat()
late_issue.update(late_issue, dbcommit=True, reindex=True)
msg = process_late_claimed_issues(dbcommit=True, reindex=True)
process_late_claimed_issues(dbcommit=True, reindex=True)
assert count_issues(martigny) == [1, 1]
late_issue = Item.get_record_by_pid(late_issue.pid)
assert late_issue.claims_count == 2

# No more claims will be generated because the max claims reached
msg = process_late_claimed_issues(dbcommit=True, reindex=True)
process_late_claimed_issues(dbcommit=True, reindex=True)
assert count_issues(martigny) == [1, 1]
late_issue = Item.get_record_by_pid(late_issue.pid)
assert late_issue.claims_count == 2

0 comments on commit 85eca4a

Please sign in to comment.