Skip to content

Commit

Permalink
dependencies: update invenio-sip2
Browse files Browse the repository at this point in the history
* Updates poetry.lock.
* Fixes missing language and translation.
* Adds alert message when item is requested.

Co-Authored-by: Lauren-D <[email protected]>
  • Loading branch information
lauren-d committed Jul 15, 2021
1 parent 4baf4db commit 1f2ec16
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 51 deletions.
25 changes: 19 additions & 6 deletions poetry.lock

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

85 changes: 40 additions & 45 deletions rero_ils/modules/selfcheck/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from flask import current_app
from flask_babelex import gettext as _
from invenio_circulation.errors import ItemNotAvailableError
from pycountry import languages

from .models import SelfcheckTerminal
from .utils import authorize_selfckeck_patron, authorize_selfckeck_terminal, \
Expand Down Expand Up @@ -52,13 +53,16 @@ def selfcheck_login(name, access_token, **kwargs):
if terminal and user:
staffer = Patron.get_librarian_by_user(user)
if staffer:
library = Library.get_record_by_pid(terminal.library_pid)
language = languages.lookup(
library.get('communication_language')).alpha_2
return {
'authenticated': terminal.active,
'terminal': terminal.name,
'transaction_user_id': staffer.pid,
'institution_id': terminal.organisation_pid,
'library_name': Library.get_record_by_pid(
terminal.library_pid).get('name')
'library_name': library.get('name'),
'library_language': language
}


Expand Down Expand Up @@ -252,7 +256,7 @@ def patron_information(barcode, **kwargs):
)


def item_information(patron_barcode, item_barcode, **kwargs):
def item_information(item_barcode, **kwargs):
"""Get item information handler.
get item information according 'item_identifier' from selfcheck user.
Expand All @@ -265,17 +269,15 @@ def item_information(patron_barcode, item_barcode, **kwargs):
from invenio_sip2.models import SelfcheckFeeType, \
SelfcheckItemInformation, SelfcheckSecurityMarkerType
org_pid = kwargs.get('institution_id')
patron = Patron.get_patron_by_barcode(
patron_barcode,
filter_by_org_pid=org_pid)
item = Item.get_item_by_barcode(item_barcode, org_pid)
if item:
document = Document.get_record_by_pid(item.document_pid)
location = item.get_location()
with current_app.test_request_context() as ctx:
language = kwargs.get('language', current_app.config
.get('BABEL_DEFAULT_LANGUAGE'))
with current_app.test_request_context() as ctx:
ctx.babel_locale = language
ctx.babel_locale = language
if item:
document = Document.get_record_by_pid(item.document_pid)
location = item.get_location()

item_information = SelfcheckItemInformation(
item_id=item.get('barcode'),
title_id=title_format_text_head(document.get('title')),
Expand All @@ -293,15 +295,12 @@ def item_information(patron_barcode, item_barcode, **kwargs):
item_information['permanent_location'] = location.get('name')
item_information['current_location'] = \
item.get_last_location().get('name')
item_information['fee_type'] = SelfcheckFeeType.OVERDUE
# get loan for item
filter_states = [
LoanState.PENDING,
LoanState.ITEM_ON_LOAN
]
loan = get_loans_by_item_pid_by_patron_pid(
item.pid, patron.pid, filter_states)
if loan:
if loan['state'] == LoanState.ITEM_ON_LOAN:
loan_pid = Item.get_loan_pid_with_item_on_loan(item.pid)
if loan_pid:
loan = Loan.get_record_by_pid(loan_pid)
if loan:
# format the end date according selfcheck language
item_information['due_date'] = format_date_filter(
loan['end_date'],
Expand All @@ -314,29 +313,24 @@ def item_information(patron_barcode, item_barcode, **kwargs):
get_last_transaction_by_loan_pid(
loan_pid=loan.pid, status='open')
if transaction:
# TODO: map transaction type
item_information['fee_type'] = \
SelfcheckFeeType.OVERDUE
item_information['fee_amount'] = \
transaction.total_amount
item_information['currency_type'] = \
transaction.currency
item_information.get('screen_messages', []) \
.append(_('overdue'))
elif loan['state'] == LoanState.PENDING:
item_information['fee_type'] = SelfcheckFeeType.OTHER
# public note
public_note = item.get_note(ItemNoteTypes.PUBLIC)
if public_note:
item_information.get('screen_messages', []) \
.append(public_note)

return item_information
else:
return SelfcheckItemInformation(
item_id=item_barcode,
screen_messages=[_('Error encountered: item not found')]
)
else:
return SelfcheckItemInformation(
item_id=item_barcode,
screen_messages=[_('Error encountered: item not found')]
)


def selfcheck_checkout(transaction_user_pid, item_barcode, patron_barcode,
Expand Down Expand Up @@ -435,18 +429,17 @@ def selfcheck_checkin(transaction_user_pid, item_barcode, **kwargs):
checkin = SelfcheckCheckin(
permanent_location=library.get('name')
)
try:
document = Document.get_record_by_pid(item.document_pid)
checkin['title_id'] = title_format_text_head(
document.get('title')
)
staffer = Patron.get_record_by_pid(transaction_user_pid)
if staffer.is_librarian:
with current_app.test_request_context() as ctx:
language = kwargs.get('language', current_app.config
.get('BABEL_DEFAULT_LANGUAGE'))
ctx.babel_locale = language

with current_app.test_request_context() as ctx:
language = kwargs.get('language', current_app.config
.get('BABEL_DEFAULT_LANGUAGE'))
ctx.babel_locale = language
try:
document = Document.get_record_by_pid(item.document_pid)
checkin['title_id'] = title_format_text_head(
document.get('title')
)
staffer = Patron.get_record_by_pid(transaction_user_pid)
if staffer.is_librarian:
# do checkin
result, data = item.checkin(
transaction_user_pid=staffer.pid,
Expand All @@ -457,17 +450,19 @@ def selfcheck_checkin(transaction_user_pid, item_barcode, **kwargs):
if data[LoanAction.CHECKIN]:
checkin['checkin'] = True
checkin['resensitize'] = True
if item.get_requests(count=True) > 0:
checkin['alert'] = True
# checkin note
checkin_note = item.get_note(ItemNoteTypes.CHECKIN)
if checkin_note:
checkin.get('screen_messages', []) \
.append(checkin_note)
# TODO: When is possible, try to return fields:
# magnetic_media
except Exception:
checkin.get('screen_messages', []).append(
_('Error encountered: please contact a librarian'))
raise SelfcheckCirculationError('self checkin failed', checkin)
except Exception:
checkin.get('screen_messages', []).append(
_('Error encountered: please contact a librarian'))
raise SelfcheckCirculationError('self checkin failed', checkin)
return checkin


Expand Down

0 comments on commit 1f2ec16

Please sign in to comment.