Skip to content

Commit

Permalink
public interface: request deletion by patron
Browse files Browse the repository at this point in the history
* Adds an action button to allow cancellation for patrons.

Co-Authored-by: Alicia Zangger <[email protected]>
  • Loading branch information
Alicia Zangger authored and AoNoOokami committed Feb 21, 2020
1 parent 4a626a9 commit 26229de
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 26 deletions.
35 changes: 27 additions & 8 deletions rero_ils/modules/patrons/templates/rero_ils/patron_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
{{ _('Renewals') }}
</th>
{% endif %}
{% if type == 'requests'%}
<th class="col-md-1 border-top-0" scope="col">
{{ _('Cancel') }}
</th>
{% endif %}
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -148,14 +153,28 @@
{{ loan.extension_count }}
</td>
<td>
{% if loan.can_renew %}
{%- with form = can_renew_form %}
<form action="{{ url_for('patrons.profile') }}" method="POST" name="can_renew_form">
<input type="hidden" name="loan_pid" value="{{ loan.pid }}">
<button type="submit" class="btn btn btn-primary btn-bg">{{_('Renew')}}</button>
</form>
{%- endwith %}
{% endif %}
{% if loan.can_renew %}
{%- with form = can_renew_form %}
<form action="{{ url_for('patrons.profile') }}" method="POST" name="can_renew_form">
<input type="hidden" name="type" value="renew">
<input type="hidden" name="loan_pid" value="{{ loan.pid }}">
<button type="submit" class="btn btn btn-primary btn-bg">{{_('Renew')}}</button>
</form>
{%- endwith %}
{% endif %}
</td>
{% endif %}
{% if type == 'requests' %}
<td>
{% if loan.state == 'PENDING' %}
<form action="{{ url_for('patrons.profile') }}" method="POST" name="cancel_loan">
<input type="hidden" name="type" value="cancel">
<input type="hidden" name="loan_pid" value="{{ loan.pid }}">
<button type="submit" class="btn btn btn-primary btn-bg">{{_('Cancel')}}</button>
</form>
{% else %}
&nbsp;
{% endif %}
</td>
{% endif %}
</tr>
Expand Down
34 changes: 22 additions & 12 deletions rero_ils/modules/patrons/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,28 @@ def profile(viewcode):
if request.method == 'POST':
loan = Loan.get_record_by_pid(request.values.get('loan_pid'))
item = Item.get_record_by_pid(loan.get('item_pid'))
data = {
'item_pid': item.pid,
'pid': request.values.get('loan_pid'),
'transaction_location_pid': item.location_pid
}
try:
item.extend_loan(**data)
flash(_('The item %(item_id)s has been renewed.',
item_id=item.pid), 'success')
except Exception:
flash(_('Error during the renewal of the item %(item_id)s.',
item_id=item.pid), 'danger')
if request.form.get('type') == 'cancel':
data = loan
try:
item.cancel_loan(**data)
flash(_('The request for item %(item_id)s has been canceled.',
item_id=item.pid), 'success')
except Exception:
flash(_('Error during the cancellation of the request of \
item %(item_id)s.', item_id=item.pid), 'danger')
elif request.form.get('type') == 'renew':
data = {
'item_pid': item.pid,
'pid': request.values.get('loan_pid'),
'transaction_location_pid': item.location_pid
}
try:
item.extend_loan(**data)
flash(_('The item %(item_id)s has been renewed.',
item_id=item.pid), 'success')
except Exception:
flash(_('Error during the renewal of the item %(item_id)s.',
item_id=item.pid), 'danger')

checkouts, requests, history = patron_profile_loans(patron.pid)

Expand Down
25 changes: 21 additions & 4 deletions rero_ils/translations/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: rero-ils 0.5.2\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2020-02-17 15:11+0100\n"
"POT-Creation-Date: 2020-02-17 17:19+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -70,7 +70,7 @@ msgstr ""
msgid "author__it"
msgstr ""

#: rero_ils/config.py:1014
#: rero_ils/config.py:1013
#: rero_ils/modules/documents/jsonschemas/documents/document-minimal-v0.0.1_src.json:3353
#: rero_ils/modules/documents/jsonschemas/documents/document-v0.0.1_src.json:3353
msgid "language"
Expand Down Expand Up @@ -6697,12 +6697,24 @@ msgstr ""
msgid "%(icon)s Profile"
msgstr ""

#: rero_ils/modules/patrons/views.py:113
#, python-format
msgid "The request for item %(item_id)s has been canceled."
msgstr ""

#: rero_ils/modules/patrons/views.py:116
#, python-format
msgid ""
"Error during the cancellation of the request of item "
"%(item_id)s."
msgstr ""

#: rero_ils/modules/patrons/views.py:126
#, python-format
msgid "The item %(item_id)s has been renewed."
msgstr ""

#: rero_ils/modules/patrons/views.py:119
#: rero_ils/modules/patrons/views.py:129
#, python-format
msgid "Error during the renewal of the item %(item_id)s."
msgstr ""
Expand Down Expand Up @@ -6894,7 +6906,12 @@ msgstr ""
msgid "Renewals"
msgstr ""

#: rero_ils/modules/patrons/templates/rero_ils/patron_profile.html:148
#: rero_ils/modules/patrons/templates/rero_ils/patron_profile.html:112
#: rero_ils/modules/patrons/templates/rero_ils/patron_profile.html:165
msgid "Cancel"
msgstr ""

#: rero_ils/modules/patrons/templates/rero_ils/patron_profile.html:154
msgid "Renew"
msgstr ""

Expand Down
17 changes: 15 additions & 2 deletions tests/ui/patrons/test_patrons_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from invenio_accounts.testutils import login_user_via_session
from utils import get_json, to_relative_url

from rero_ils.modules.loans.api import Loan


def test_patrons_profile(
client, librarian_martigny_no_email, loan_pending_martigny,
Expand All @@ -51,7 +53,18 @@ def test_patrons_profile(
}
loan = item_lib_martigny.request(**data)
loan_pid = loan[1].get('request').get('pid')
pending_loan = loan_pending_martigny
pending_loan_pid = pending_loan.get('pid')
assert pending_loan.get('state') == 'PENDING'

# patron successfully cancelled the request
res = client.post(
url_for('patrons.profile'),
data={'loan_pid': pending_loan_pid, 'type': 'cancel'}
)
assert res.status_code == 200
pending_loan = Loan.get_record_by_pid(pending_loan_pid)
assert pending_loan.get('state') == 'CANCELLED'
loan = item_lib_martigny.checkout(**data)

# patron visits his profile to list checked-out items
Expand All @@ -62,7 +75,7 @@ def test_patrons_profile(
# patron successfully renew the item
res = client.post(
url_for('patrons.profile'),
data={'loan_pid': loan_pid}
data={'loan_pid': loan_pid, 'type': 'renew'}
)
assert res.status_code == 200

Expand All @@ -74,7 +87,7 @@ def test_patrons_profile(
# patron fails to renew the item
res = client.post(
url_for('patrons.profile'),
data={'loan_pid': loan_pid}
data={'loan_pid': loan_pid, 'type': 'renew'}
)
assert res.status_code == 200

Expand Down

0 comments on commit 26229de

Please sign in to comment.