Skip to content

Commit

Permalink
selfcheck: fix patron informations
Browse files Browse the repository at this point in the history
* Sets `institution_id` to the patron organisation `pid`.
* Rounds the fees to cents.
* Fixes patron language, email, phone.
* Removes CR chars `\n`, `\r` from the patron address.
* Adds the `due_date` in a checkout response even if the item has been
  already checked out.

Co-Authored-by: Johnny Mariéthoz <[email protected]>
Co-Authored-by: Igor Milhit <[email protected]>
  • Loading branch information
3 people committed Jul 28, 2021
1 parent 6c1cfe6 commit b80b7a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
24 changes: 15 additions & 9 deletions rero_ils/modules/selfcheck/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def patron_status(barcode, **kwargs):
language=patron.get('communication_language', 'und'),
patron_id=barcode,
patron_name=patron.formatted_name,
institution_id=patron.library_pid,
institution_id=patron.organisation_pid,
currency_type=patron.get_organisation().get(
'default_currency'),
valid_patron=patron.is_patron
Expand All @@ -161,7 +161,7 @@ def patron_status(barcode, **kwargs):
fee_amount = PatronTransaction \
.get_transactions_total_amount_for_patron(
patron.pid, status='open', with_subscription=False)
patron_status_response['fee_amount'] = fee_amount
patron_status_response['fee_amount'] = '%.2f' % fee_amount
return patron_status_response
else:
return SelfcheckPatronStatus(
Expand All @@ -185,14 +185,18 @@ def patron_information(barcode, **kwargs):
patron = Patron.get_patron_by_barcode(
barcode, filter_by_org_pid=institution_id)
if patron:
patron_dumps = patron.dumps()
patron_account_information = SelfcheckPatronInformation(
patron_id=barcode,
patron_name=patron.formatted_name,
patron_status=get_patron_status(patron),
institution_id=patron.library_pid,
language=patron.get('communication_language', 'und'),
email=patron.get('email'),
home_phone=patron.get('phone'),
institution_id=patron.organisation_pid,
language=patron.get(
'patron', {}).get('communication_language', 'und'),
email=patron.get('patron', {}).get(
'additional_communication_email',
patron_dumps.get('email')),
home_phone=patron_dumps.get('home_phone'),
home_address=format_patron_address(patron),
currency_type=patron.get_organisation().get(
'default_currency'),
Expand Down Expand Up @@ -226,7 +230,7 @@ def patron_information(barcode, **kwargs):
fee_amount = PatronTransaction \
.get_transactions_total_amount_for_patron(
patron.pid, status='open', with_subscription=False)
patron_account_information['fee_amount'] = fee_amount
patron_account_information['fee_amount'] = '%.2f' % fee_amount
# check for fine items
if fee_amount > 0:
# Check if fine items exist
Expand Down Expand Up @@ -304,7 +308,7 @@ def item_information(item_barcode, **kwargs):
loan_pid=loan.pid, status='open')
if transaction:
item_information['fee_amount'] = \
transaction.total_amount
'%.2f' % transaction.total_amount
item_information['currency_type'] = \
transaction.currency
item_information.get('screen_messages', []) \
Expand Down Expand Up @@ -364,6 +368,7 @@ def selfcheck_checkout(transaction_user_pid, item_barcode, patron_barcode,
if loan:
checkout['renewal'] = True
checkout['desensitize'] = True
checkout['due_date'] = loan['end_date']
else:
# do checkout
result, data = item.checkout(
Expand Down Expand Up @@ -505,7 +510,8 @@ def selfcheck_renew(transaction_user_pid, item_barcode, **kwargs):
if transaction:
# TODO: map transaction type
renew['fee_type'] = SelfcheckFeeType.OVERDUE
renew['fee_amount'] = transaction.total_amount
renew['fee_amount'] = \
'%.2f' % transaction.total_amount
renew['currency_type'] = transaction.currency
# TODO: When is possible, try to return fields:
# magnetic_media
Expand Down
7 changes: 5 additions & 2 deletions rero_ils/modules/selfcheck/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,21 @@ def format_patron_address(patron):
"""
address = patron.get('second_address')
if address:
return '{street}, {postal_code} {city}'.format(
formated_address = '{street}, {postal_code} {city}'.format(
street=address.get('street'),
postal_code=address.get('postal_code'),
city=address.get('city')
)
else:
profile = patron.user.profile
return '{street}, {postal_code} {city}'.format(
formated_address = '{street}, {postal_code} {city}'.format(
street=profile.street.strip(),
postal_code=profile.postal_code.strip(),
city=profile.city.strip()
)
# Should never append, but can be imported from an old system
return formated_address.replace(r'\n', ' ').replace(r'\r', ' ')\
.replace('\n', ' ').replace('\r', ' ')


def get_patron_status(patron):
Expand Down

0 comments on commit b80b7a8

Please sign in to comment.