Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

circulation: allow 'less than one day' checkout #1477

Merged
merged 1 commit into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ci-po: allow 'less than one day' checkout
* Changes minimum checkout duration in the circulation policy JSON
  schema to allow 'less than one day' checkouts.
* Allows a print in the console when a record is reindexed for debug.
* Corrects russian dolls script to use webpack integration instead of
invenio bundles.

Co-Authored-by: Alicia Zangger <alicia.zangger@rero.ch>
  • Loading branch information
Alicia Zangger committed Dec 10, 2020
commit d4e4814ea72ca36dd38b898f83875bc0d7763ba0
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ tests/e2e/cypress/node_modules
tests/e2e/cypress/cypress/videos
tests/e2e/cypress/cypress/screenshots
tests/e2e/cypress/cypress/integration/test

# Dependencies
/node_modules
4 changes: 2 additions & 2 deletions rero_ils/modules/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,9 @@ def reindex(self, forceindex=False):
"""Reindex record."""
indexer = self.get_indexer_class()
if forceindex:
indexer(version_type="external_gte").index(self)
return indexer(version_type="external_gte").index(self)
else:
indexer().index(self)
return indexer().index(self)

def delete_from_index(self):
"""Delete record from index."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"title": "Checkout duration in days",
"description": "The duration of the checkout in days.",
"type": "integer",
"minimum": 1,
"minimum": 0,
"default": 7
},
"allow_requests": {
Expand Down
1 change: 0 additions & 1 deletion scripts/russian_dolls
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ success_msg "UI ❯ successfully packaged."
info_msg "ILS ❯ including rero-ils-ui…"
static_folder=$(poetry run invenio shell --no-term-title -c "print('static_folder:%s' % app.static_folder)"|grep static_folder|cut -d: -f2-) || error_msg+exit "Error. Have you launched a bootstrap on this directory?"
npm i "${FRONTEND_PACKAGE}" --prefix "${static_folder}" \
&& poetry run invenio assets build \
|| error_msg+exit "ILS ❯ inclusion failed!"
success_msg "ILS ❯ successfully included."

Expand Down
24 changes: 24 additions & 0 deletions tests/data/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,30 @@
"policy_library_level": false,
"is_default": false
},
"cipo7": {
"$schema": "https://ils.rero.ch/schemas/circ_policies/circ_policy-v0.0.1.json",
"pid": "cipo7",
"name": "Less than one day",
"description": "Less than one day.",
"organisation": {
"$ref": "https://ils.rero.ch/api/organisations/org1"
},
"allow_checkout": true,
"checkout_duration": 0,
"allow_requests": false,
"policy_library_level": false,
"is_default": false,
"settings": [
{
"patron_type": {
"$ref": "https://ils.rero.ch/api/patron_types/ptty2"
},
"item_type": {
"$ref": "https://ils.rero.ch/api/item_types/itty1"
}
}
]
},
"cont_pers": {
"$schema": "https://ils.rero.ch/schemas/contributions/contribution-v0.0.1.json",
"gnd": {
Expand Down
25 changes: 24 additions & 1 deletion tests/fixtures/organisations.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,28 @@ def circ_policy_ebooks_sion(
return cipo


@pytest.fixture(scope="module")
def circ_policy_less_than_one_day_martigny_data(data):
"""Load short circ policy for organisation martigny."""
return deepcopy(data.get('cipo7'))


@pytest.fixture(scope="module")
def circ_policy_less_than_one_day_martigny(
app,
patron_type_adults_martigny,
item_type_standard_martigny,
circ_policy_less_than_one_day_martigny_data):
"""Create short circ policy for organisation martigny."""
cipo = CircPolicy.create(
data=circ_policy_less_than_one_day_martigny_data,
delete_pid=False,
dbcommit=True,
reindex=True)
flush_index(CircPoliciesSearch.Meta.index)
return cipo


@pytest.fixture(scope="module")
def circulation_policies(
circ_policy_default_martigny,
Expand All @@ -867,7 +889,8 @@ def circulation_policies(
circ_policy_short_martigny,
circ_policy_temp_martigny,
circ_policy_ebooks_martigny,
circ_policy_ebooks_sion
circ_policy_ebooks_sion,
circ_policy_less_than_one_day_martigny
AoNoOokami marked this conversation as resolved.
Show resolved Hide resolved
]


Expand Down
86 changes: 86 additions & 0 deletions tests/ui/circulation/test_inhouse_cipo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2020 RERO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""In house circulation policy tests."""

from copy import deepcopy
from datetime import datetime

import ciso8601
import pytz

from rero_ils.modules.items.api import Item
from rero_ils.modules.items.models import ItemStatus
from rero_ils.modules.libraries.api import Library
from rero_ils.modules.loans.api import Loan, LoanAction, LoanState


def test_less_than_one_day_checkout(
circ_policy_less_than_one_day_martigny,
patron_martigny_no_email,
AoNoOokami marked this conversation as resolved.
Show resolved Hide resolved
patron2_martigny_no_email,
item_lib_martigny,
loc_public_martigny,
librarian_martigny_no_email,
item_on_shelf_martigny_patron_and_loan_pending):
AoNoOokami marked this conversation as resolved.
Show resolved Hide resolved
"""Test checkout on an ON_SHELF item with 'less than one day' cipo."""
# Create a new item in ON_SHELF (without Loan)
data = deepcopy(item_lib_martigny)
data.pop('barcode')
data.setdefault('status', ItemStatus.ON_SHELF)
created_item = Item.create(
data=data, dbcommit=True, reindex=True, delete_pid=True)

# Check item is ON_SHELF and NO PENDING loan exist!
AoNoOokami marked this conversation as resolved.
Show resolved Hide resolved
assert created_item.number_of_requests() == 0
assert created_item.status == ItemStatus.ON_SHELF
assert not created_item.is_requested_by_patron(
patron2_martigny_no_email.get('patron', {}).get('barcode'))

# the following tests the circulation action CHECKOUT_1_1
# an ON_SHELF item
# WITHOUT pending loan
# CAN be CHECKOUT for less than one day
params = {
'patron_pid': patron2_martigny_no_email.pid,
'transaction_location_pid': loc_public_martigny.pid,
'transaction_user_pid': librarian_martigny_no_email.pid,
'pickup_location_pid': loc_public_martigny.pid
}
onloan_item, actions = created_item.checkout(**params)
loan = Loan.get_record_by_pid(actions[LoanAction.CHECKOUT].get('pid'))
# Check loan is ITEM_ON_LOAN and item is ON_LOAN
assert onloan_item.number_of_requests() == 0
AoNoOokami marked this conversation as resolved.
Show resolved Hide resolved
assert onloan_item.status == ItemStatus.ON_LOAN
assert loan['state'] == LoanState.ITEM_ON_LOAN

# Check due date
loan_end_date = loan.get('end_date')
lib = Library.get_record_by_pid(onloan_item.library_pid)
today = datetime.now(pytz.utc)
# Get next open day
next_open_day = lib.next_open(today)
if lib.is_open(today):
next_open_day = today
# Loan date should be in UTC.
loan_datetime = ciso8601.parse_datetime(loan_end_date)
# Compare year, month and date
fail_msg = "Check timezone for Loan and Library. \
It should be the same date, even if timezone changed."
assert loan_datetime.year == next_open_day.year, fail_msg
assert loan_datetime.month == next_open_day.month, fail_msg
assert loan_datetime.day == next_open_day.day, fail_msg