Skip to content

Commit

Permalink
selfcheck: fix checkin/checkout action
Browse files Browse the repository at this point in the history
There was a mistmatch in the parameters of the methods for checkin and checkout.

* Uses selfcheck terminal information to process checkin/checkout.

Co-Authored-by: Lauren-D <[email protected]>
  • Loading branch information
lauren-d committed May 5, 2021
1 parent 2c18d97 commit 39ef9ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 11 additions & 9 deletions rero_ils/modules/selfcheck/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 306,13 @@ def item_information(patron_barcode, item_pid, **kwargs):
return item_information


def selfcheck_checkout(transaction_user_pid, library_pid, patron_barcode,
def selfcheck_checkout(transaction_user_pid, institution_id, patron_barcode,
item_barcode, **kwargs):
"""SIP2 Handler to perform checkout.
perform checkout action received from the selfcheck.
:param transaction_user_pid: identifier of the staff user.
:param library_pid: library pid of the selfcheck_terminal.
:param institution_id: institution id of the selfcheck_terminal.
:param patron_barcode: barcode of the patron.
:param item_barcode: item identifier.
:return: The SelfcheckCheckout object.
Expand All @@ -336,7 336,7 @@ def selfcheck_checkout(transaction_user_pid, library_pid, patron_barcode,
if staffer.is_librarian:
patron = Patron.get_patron_by_barcode(
patron_barcode,
filter_by_org_pid=kwargs.get('institution_id'))
filter_by_org_pid=terminal.organisation_pid)
with current_app.test_request_context() as ctx:
language = kwargs.get('language', current_app.config
.get('BABEL_DEFAULT_LANGUAGE'))
Expand All @@ -347,7 347,7 @@ def selfcheck_checkout(transaction_user_pid, library_pid, patron_barcode,
result, data = item.checkout(
patron_pid=patron.pid,
transaction_user_pid=staffer.pid,
transaction_library_pid=library_pid,
transaction_library_pid=terminal.library_pid,
item_pid=item.pid,
selfcheck_terminal_id=str(terminal.id),
)
Expand Down Expand Up @@ -375,24 375,26 @@ def selfcheck_checkout(transaction_user_pid, library_pid, patron_barcode,
return checkout


def selfcheck_checkin(transaction_user_pid, library_pid, patron_barcode,
def selfcheck_checkin(transaction_user_pid, institution_id, patron_barcode,
item_barcode, **kwargs):
"""SIP2 Handler to perform checkin.
perform checkin action received from the selfcheck.
:param transaction_user_pid: identifier of the staff user.
:param library_pid: library pid of the selfcheck terminal.
:param institution_id: institution id of the selfcheck terminal.
:param patron_barcode: barcode of the patron.
:param item_barcode: item identifier.
:return: The SelfcheckCheckin object.
"""
if check_sip2_module():
from invenio_sip2.errors import SelfcheckCirculationError
from invenio_sip2.models import SelfcheckCheckin
library = Library.get_record_by_pid(library_pid)
terminal = SelfcheckTerminal.find_terminal(
name=kwargs.get('terminal'))
library = Library.get_record_by_pid(terminal.library_pid)
item = Item.get_item_by_barcode(
barcode=item_barcode,
organisation_pid=library.organisation_pid
organisation_pid=terminal.organisation_pid
)
checkin = SelfcheckCheckin(
permanent_location=library.get('name')
Expand All @@ -412,7 414,7 @@ def selfcheck_checkin(transaction_user_pid, library_pid, patron_barcode,
# do checkin
result, data = item.checkin(
transaction_user_pid=staffer.pid,
transaction_library_pid=library_pid,
transaction_library_pid=terminal.library_pid,
item_pid=item.pid,
)
if data[LoanAction.CHECKIN]:
Expand Down
4 changes: 3 additions & 1 deletion tests/api/selfcheck/test_selfcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 305,7 @@ def test_selfcheck_checkin(client, selfcheck_librarian_martigny,
item_pid=item_lib_martigny.pid,
patron_pid=selfcheck_patron_martigny.pid,
transaction_location_pid=loc_public_martigny.pid,
transaction_user_pid=librarian2_martigny.pid,
transaction_user_pid=librarian2_martigny.pid
))
assert res.status_code == 200

Expand All @@ -316,6 316,7 @@ def test_selfcheck_checkin(client, selfcheck_librarian_martigny,
library_pid=selfcheck_librarian_martigny.library_pid,
patron_barcode=patron_barcode,
item_barcode='wrong_item_barcode',
terminal=selfcheck_librarian_martigny.name
)
assert checkin
assert not checkin.is_success
Expand All @@ -326,6 327,7 @@ def test_selfcheck_checkin(client, selfcheck_librarian_martigny,
library_pid=selfcheck_librarian_martigny.library_pid,
patron_barcode=patron_barcode,
item_barcode=item_barcode,
terminal=selfcheck_librarian_martigny.name
)
assert checkin
assert checkin.is_success

0 comments on commit 39ef9ed

Please sign in to comment.