diff --git a/rero_ils/modules/selfcheck/api.py b/rero_ils/modules/selfcheck/api.py index af3343d3ed..36b4f2a463 100644 --- a/rero_ils/modules/selfcheck/api.py +++ b/rero_ils/modules/selfcheck/api.py @@ -48,6 +48,7 @@ def selfcheck_login(name, access_token, **kwargs): """ terminal = SelfcheckTerminal.find_terminal(name=name) user = authorize_selfckeck_terminal(terminal, access_token, **kwargs) + print('user', user) if terminal and user: staffer = Patron.get_librarian_by_user(user) if staffer: @@ -152,7 +153,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 @@ -161,7 +162,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( @@ -185,14 +186,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'), @@ -226,7 +231,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 @@ -304,7 +309,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', []) \ @@ -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 diff --git a/rero_ils/modules/selfcheck/utils.py b/rero_ils/modules/selfcheck/utils.py index 72fe81b0e6..61b44f22a2 100644 --- a/rero_ils/modules/selfcheck/utils.py +++ b/rero_ils/modules/selfcheck/utils.py @@ -83,18 +83,24 @@ 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 + formated_address = formated_address.replace(r'\n', ' ') + formated_address = formated_address.replace(r'\r', ' ') + formated_address = formated_address.replace('\n', ' ') + formated_address = formated_address.replace('\r', ' ') + return formated_address def get_patron_status(patron):