Skip to content

Commit

Permalink
feat(loan): add temporary location on item
Browse files Browse the repository at this point in the history
* Closes rero#3611.

Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
Garfield-fr committed Mar 5, 2024
1 parent acf40ef commit 3366da2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 9 additions & 1 deletion rero_ils/modules/loans/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def requested_loans_to_validate(cls, library_pid):
:param library_pid: the library pid.
"""
# TODO: Refactor this with a dump
from ..item_types.api import ItemTypesSearch
from ..items.api import ItemsSearch

Expand Down Expand Up @@ -364,7 +365,7 @@ def item_by_pid(pid, known_items):
fields = ['pid', 'barcode', 'call_number',
'second_call_number', 'library', 'location',
'temporary_item_type', 'holding',
'enumerationAndChronology']
'enumerationAndChronology', 'temporary_location']
if pid not in known_items:
results = ItemsSearch()\
.filter('term', pid=pid)\
Expand Down Expand Up @@ -421,6 +422,13 @@ def item_type_by_pid(pid, known_ittys):
item_data['location']['pid'],
locations
)['name']
if 'temporary_location' in item_data:
location = location_by_pid(
item_data['temporary_location']['pid'],
locations
)
item_data['temporary_location']['name'] = \
location.get('name')
patron_data = patron_by_pid(loan_data['patron_pid'],
patrons)
loan_data['patron'] = {
Expand Down
11 changes: 9 additions & 2 deletions tests/api/items/test_items_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,8 +904,9 @@ def test_items_notes(client, librarian_martigny, item_lib_martigny,

def test_requested_loans_to_validate(
client, librarian_martigny, loc_public_martigny,
item_type_standard_martigny, item2_lib_martigny, json_header,
item_type_missing_martigny, patron_sion, circulation_policies):
loc_restricted_martigny, item_type_standard_martigny,
item2_lib_martigny, json_header, item_type_missing_martigny,
patron_sion, circulation_policies):
"""Test requested loans to validate."""

holding_pid = item2_lib_martigny.holding_pid
Expand All @@ -925,6 +926,9 @@ def test_requested_loans_to_validate(
item2_lib_martigny['temporary_item_type'] = {
'$ref': get_ref_for_pid('itty', item_type_standard_martigny.pid)
}
item2_lib_martigny['temporary_location'] = {
'$ref': get_ref_for_pid('loc', loc_restricted_martigny.pid)
}

holding.update(holding, dbcommit=True, reindex=True)
item2_lib_martigny.update(item2_lib_martigny, dbcommit=True, reindex=True)
Expand Down Expand Up @@ -956,8 +960,11 @@ def test_requested_loans_to_validate(
assert LoanState.PENDING == requested_loan['loan']['state']
assert patron_sion.pid == requested_loan['loan']['patron_pid']

assert requested_loan['item']['temporary_location']['name']

# RESET - the item
del item2_lib_martigny['temporary_item_type']
del item2_lib_martigny['temporary_location']
holding.update(original_holding, dbcommit=True, reindex=True)
item2_lib_martigny.update(original_item, dbcommit=True, reindex=True)

Expand Down

0 comments on commit 3366da2

Please sign in to comment.