Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

circulation: fix change pickup location on loans #1174

Merged
merged 1 commit into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion rero_ils/modules/items/api/circulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

"""API for manipulating item circulation transactions."""

from copy import deepcopy
from datetime import datetime, timezone
from functools import wraps

Expand Down Expand Up @@ -802,7 +803,10 @@ def prior_checkout_actions(self, action_params):
item, receive_actions = self.receive(**action_params)
actions.update(receive_actions)
elif loan['state'] == LoanState.ITEM_IN_TRANSIT_TO_HOUSE:
item, cancel_actions = self.cancel_loan(**action_params)
# do not pass the patron_pid when cancelling a loan
cancel_params = deepcopy(action_params)
cancel_params.pop('patron_pid')
item, cancel_actions = self.cancel_loan(**cancel_params)
actions.update(cancel_actions)
del action_params['pid']
# TODO: Check what's wrong in this case because Loan is cancel
Expand Down
2 changes: 1 addition & 1 deletion rero_ils/modules/loans/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def update_pickup_location(self, pickup_location_pid):
:return: the new updated loan.
"""
if self['state'] not in [
LoanState.PENDING, LoanState.ITEM_IN_TRANSIT_TO_HOUSE]:
LoanState.PENDING, LoanState.ITEM_IN_TRANSIT_FOR_PICKUP]:
raise NoCirculationActionIsPermitted(
'No circulation action is permitted')

Expand Down
8 changes: 4 additions & 4 deletions tests/api/circulation/test_actions_views_change_pickup.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_change_pickup_location_request_for_other_loans(
)
)
assert res.status_code == 403
# CHANGE_PICKUP_LOCATION_4: update denied on IN_TRANSIT_FOR_PICKUP loans.
# CHANGE_PICKUP_LOCATION_4: update allowed on IN_TRANSIT_FOR_PICKUP loans.
item, patron, loan = item_in_transit_martigny_patron_and_loan_for_pickup
res, data = postdata(
client,
Expand All @@ -108,8 +108,8 @@ def test_change_pickup_location_request_for_other_loans(
pickup_location_pid=loc_public_fully.pid
)
)
assert res.status_code == 403
# CHANGE_PICKUP_LOCATION_5: update is allowed on IN_TRANSIT_TO_HOUSE loans.
assert res.status_code == 200
# CHANGE_PICKUP_LOCATION_5: update denied on IN_TRANSIT_TO_HOUSE loans.
item, patron, loan = item_in_transit_martigny_patron_and_loan_to_house
res, data = postdata(
client,
Expand All @@ -119,4 +119,4 @@ def test_change_pickup_location_request_for_other_loans(
pickup_location_pid=loc_public_fully.pid
)
)
assert res.status_code == 200
assert res.status_code == 403
32 changes: 32 additions & 0 deletions tests/ui/circulation/test_actions_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,38 @@ def test_checkout_on_item_in_transit_to_house(
assert intransit_item.number_of_requests() == 0


def test_checkout_on_item_in_transit_to_house_for_another_patron(
item2_in_transit_martigny_patron_and_loan_to_house,
patron2_martigny_no_email,
librarian_martigny_no_email,
loc_public_martigny,
loc_public_saxon):
"""Test CHECKOUT on an IN_TRANSIT (to house) item."""
# Create a new item in IN_TRANSIT_TO_HOUSE
intransit_item, patron, loan = \
item2_in_transit_martigny_patron_and_loan_to_house
assert intransit_item.number_of_requests() == 0

# the following tests the circulation action CHECKOUT_5_1
# an IN_TRANSIT (to house) item
# WITHOUT pending loan
# CAN be CHECKOUT
params = {
'patron_pid': patron2_martigny_no_email.pid,
'transaction_location_pid': loc_public_saxon.pid,
'transaction_user_pid': librarian_martigny_no_email.pid,
'pickup_location_pid': loc_public_martigny.pid,
}
# Checkout it!
asked_item, actions = intransit_item.checkout(**params, pid=loan.pid)
checkout_loan = Loan.get_record_by_pid(
actions[LoanAction.CHECKOUT].get('pid'))
# Check loan is ITEM_ON_LOAN and item is ON_LOAN
assert intransit_item.status == ItemStatus.ON_LOAN
assert checkout_loan['state'] == LoanState.ITEM_ON_LOAN
assert intransit_item.number_of_requests() == 0


def test_checkout_on_item_in_transit_to_house_with_pending_loan(
item_in_transit_martigny_patron_and_loan_to_house,
item_lib_martigny,
Expand Down