Skip to content

Commit

Permalink
selfcheck: improve circulation error messages
Browse files Browse the repository at this point in the history
* Returns circulation error message instead exception.
* Bumps to invenio-sip2 v0.6.13.

Co-Authored-by: Lauren-D <[email protected]>
  • Loading branch information
lauren-d authored and iGor milhit committed Aug 26, 2021
1 parent 30d10ab commit 1bf9629
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
26 changes: 24 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions rero_ils/modules/selfcheck/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

from flask import current_app
from flask_babelex import gettext as _
from invenio_circulation.errors import ItemNotAvailableError
from invenio_circulation.errors import CirculationException, \
ItemNotAvailableError

from .models import SelfcheckTerminal
from .utils import authorize_selfckeck_patron, authorize_selfckeck_terminal, \
Expand Down Expand Up @@ -389,7 +390,7 @@ def selfcheck_checkout(transaction_user_pid, item_barcode, patron_barcode,
item_pid=item.pid,
selfcheck_terminal_id=str(terminal.id),
)
if data[LoanAction.CHECKOUT]:
if LoanAction.CHECKOUT in data:
loan = data[LoanAction.CHECKOUT]
checkout['checkout'] = True
checkout['desensitize'] = True
Expand All @@ -406,6 +407,12 @@ def selfcheck_checkout(transaction_user_pid, item_barcode, patron_barcode,
checkout.get('screen_messages', []).append(
_('Checkout impossible: the item is requested by '
'another patron'))
except NoCirculationAction as circ_no_action:
checkout.get('screen_messages', []).append(
_(circ_no_action.description))
except CirculationException as circ_err:
checkout.get('screen_messages', []).append(
_(circ_err.description))
except Exception:
checkout.get('screen_messages', []).append(
_('Error encountered: please contact a librarian'))
Expand Down Expand Up @@ -452,7 +459,7 @@ def selfcheck_checkin(transaction_user_pid, item_barcode, **kwargs):
item_pid=item.pid,
selfcheck_terminal_id=str(terminal.id),
)
if data[LoanAction.CHECKIN]:
if LoanAction.CHECKIN in data:
checkin['checkin'] = True
checkin['resensitize'] = True
if item.get_requests(count=True) > 0:
Expand All @@ -465,6 +472,12 @@ def selfcheck_checkin(transaction_user_pid, item_barcode, **kwargs):
# TODO: When is possible, try to return fields:
# magnetic_media
# TODO: implements `print_line`
except NoCirculationAction as circ_no_action:
checkin.get('screen_messages', []).append(
_(circ_no_action.description))
except CirculationException as circ_err:
checkin.get('screen_messages', []).append(
_(circ_err.description))
except Exception:
checkin.get('screen_messages', []).append(
_('Error encountered: please contact a librarian'))
Expand Down Expand Up @@ -509,7 +522,7 @@ def selfcheck_renew(transaction_user_pid, item_barcode, **kwargs):
item_pid=item.pid,
selfcheck_terminal_id=str(terminal.id),
)
if data[LoanAction.EXTEND]:
if LoanAction.EXTEND in data:
loan = data[LoanAction.EXTEND]
renew['success'] = True
renew['renewal'] = True
Expand All @@ -530,6 +543,9 @@ def selfcheck_renew(transaction_user_pid, item_barcode, **kwargs):
except NoCirculationAction:
renew.get('screen_messages', []).append(
_('No circulation action is possible'))
except CirculationException as circ_err:
renew.get('screen_messages', []).append(
_(circ_err.description))
except Exception:
renew.get('screen_messages', []).append(
_('Error encountered: please contact a librarian'))
Expand Down

0 comments on commit 1bf9629

Please sign in to comment.