Skip to content

Commit

Permalink
circulation : fix checkin of item that should go in transit
Browse files Browse the repository at this point in the history
* Fixes an existing issue, may closes rero#462

Co-Authored-by: Benoit Erken <erken.benoit@gmail.com>
  • Loading branch information
benerken authored and lauren-d committed Sep 27, 2019
1 parent 62c8ee5 commit 54351bc
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 9 deletions.
3 changes: 1 addition & 2 deletions rero_ils/modules/items/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,7 @@ def item_location_retriever(cls, item_pid, **kwargs):
# to deal with multiple pickup locations for a library
item = cls.get_record_by_pid(item_pid)
if item:
library = item.get_library_of_last_location()
return library.get_pickup_location_pid()
return item.get_owning_pickup_location_pid()

@add_loans_parameters_and_flush_indexes
def validate_request(self, current_loan, **kwargs):
Expand Down
69 changes: 63 additions & 6 deletions tests/api/test_items_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1410,12 +1410,14 @@ def test_items_extend_end_date(client, librarian_martigny_no_email,
assert res.status_code == 200


def test_items_in_transit(client, librarian_martigny_no_email,
patron_martigny_no_email,
loc_public_martigny, item_type_standard_martigny,
loc_restricted_martigny,
item_lib_martigny, json_header,
circulation_policies):
def test_items_in_transit_between_locations(client,
librarian_martigny_no_email,
patron_martigny_no_email,
loc_public_martigny,
item_type_standard_martigny,
loc_restricted_martigny,
item_lib_martigny, json_header,
circulation_policies):
"""Test item in-transit scenarios."""
login_user_via_session(client, librarian_martigny_no_email.user)
item = item_lib_martigny
Expand Down Expand Up @@ -1545,6 +1547,61 @@ def test_items_in_transit(client, librarian_martigny_no_email,
assert res.status_code == 200


def test_items_in_transit_between_libraries(client,
librarian_martigny_no_email,
librarian_saxon_no_email,
patron_martigny_no_email,
loc_public_martigny,
item_type_standard_martigny,
loc_public_saxon,
item_lib_martigny, json_header,
circulation_policies):
"""Test item in-transit scenarios."""
login_user_via_session(client, librarian_martigny_no_email.user)
item = item_lib_martigny
item_pid = item.pid
patron_pid = patron_martigny_no_email.pid
location = loc_public_martigny

# checkout the item at location A
res = client.post(
url_for('api_item.checkout'),
data=json.dumps(
dict(
item_pid=item.pid,
patron_pid=patron_pid,
transaction_location_pid=loc_public_saxon.pid
)
),
content_type='application/json',
)
assert res.status_code == 200
data = get_json(res)
assert Item.get_record_by_pid(item.pid).get('status') == ItemStatus.ON_LOAN
item_data = data.get('metadata')
actions = data.get('action_applied')
assert item_data.get('status') == ItemStatus.ON_LOAN
loan_pid = actions[LoanAction.CHECKOUT].get('pid')

# checkin the item at location B
res = client.post(
url_for('api_item.checkin'),
data=json.dumps(
dict(
item_pid=item.pid,
pid=loan_pid,
transaction_location_pid=loc_public_saxon.pid
)
),
content_type='application/json',
)
assert res.status_code == 200
data = get_json(res)
item_data = data.get('metadata')
item = Item.get_record_by_pid(item_data.get('pid'))
assert item.get('status') == ItemStatus.IN_TRANSIT


def test_multiple_loans_on_item_error(client,
patron_martigny_no_email,
patron2_martigny_no_email,
Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_items_rest_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def test_auto_checkin_else(client, librarian_martigny_no_email, lib_martigny,
assert res.status_code == 200

item = Item.get_record_by_pid(item_lib_martigny.pid)
assert item.status == ItemStatus.AT_DESK
assert item.status == ItemStatus.IN_TRANSIT

record, actions = item.automatic_checkin()
assert actions == {'no': None}
Expand Down

0 comments on commit 54351bc

Please sign in to comment.