Skip to content
Snippets Groups Projects
Commit 04144c68 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

FIX: deal with borrowing bad entities

parent 182ce921
No related branches found
No related tags found
1 merge request!6F borrow all
Pipeline #62048 passed with warnings
BUILD_MODULE_BOX_LOAN=ENABLED
BUILD_MODULE_EXT_LOAN_BORROW_BOOKMARKED=ENABLED
MODULE_DEPENDENCIES+=(
box_loan_config.js
box_loan.js
......
......@@ -72,7 +72,9 @@
<div class="row caosdb-form-row">
<div class="col-sm-12">
<div class="form-check">
<label class="form-check-label">Are you going to completely exhaust the contents of this box?
<label class="form-check-label">Are you going to
completely exhaust the contents of at lease one
{lentType}?
<input type="checkbox" class="form-check-input" id="exhaust-contents" value="no" />
</label>
</div>
......@@ -92,4 +94,4 @@
</div>
</body>
</html>
\ No newline at end of file
</html>
......@@ -61,7 +61,8 @@
<div class="row caosdb-form-row">
<div class="col-sm-12">
<div class="form-check">
<label class="form-check-label">Are you going to completely exhaust the contents of this box?
<label class="form-check-label">Are you going to completely
exhaust the contents of this {lentType}?
<input type="checkbox" class="form-check-input" id="exhaust-contents" value="no" />
</label>
</div>
......
......@@ -740,7 +740,8 @@ var box_loan = function(logger, box_loan_config) {
email: email,
destination: destination,
expected_return_date: exp_return,
mindate: get_formatted_date("T")
mindate: get_formatted_date("T"),
lentType: datamodel.box
});
}
......
......@@ -23,6 +23,7 @@ Creates a loan request using information provided by a web formular.
from __future__ import absolute_import
import linkahead as db
import logging
from caosadvancedtools.serverside.helper import get_timestamp, print_success
from linkahead.common.models import get_id_from_versionid, value_matches_versionid
......@@ -32,6 +33,8 @@ from .box_loan import (BORROWER, BOX, COMMENT, DESTINATION, EXHAUST_CONTENTS, EX
LOAN, LOAN_REQUESTED, assert_date_in_future, assert_key_in_data,
insert_or_update_person, main, send_loan_request_mail)
LOGGER_NAME = "box_loan"
LOGGER = logging.getLogger(LOGGER_NAME)
def create_loan(box, borrower, expected_return, exhaust_contents, comment, destination):
""" Create a new loan record. """
......@@ -92,10 +95,29 @@ def _check_data(data):
data[F_EXPECTED_RETURN_DATE]))
def _check_items(items):
""" Check whether the items have the correct RecordTypes """
if not isinstance(items, list):
items = [items]
bad_type_ids = []
for item in items:
if db.execute_query(f"COUNT {BOX.name} WITH ID='{item}'") != 1:
bad_type_ids.append(item)
if len(bad_type_ids)>0:
LOGGER.error(f"The entities with the following IDs do not have the appropriate RecordType "
f"in order to create a loan:<br>{', '.join(bad_type_ids)}<br>")
return False
return True
def _issue_loan_request(data):
""" Insert a loan record a insert/update a person record. """
data = _set_defaults(data)
_check_data(data)
if not _check_items(data[F_BOX]):
return None, None
borrower = insert_or_update_person(firstname=data[F_FIRST_NAME],
lastname=data[F_LAST_NAME],
email=data[F_EMAIL])
......@@ -126,6 +148,8 @@ def issue_loan_request(data):
identified by either email, oder firstName+lastName.
"""
borrower, loan = _issue_loan_request(data)
if borrower is None:
return 1
fn = borrower.get_property(FIRST_NAME.name).value
ln = borrower.get_property(LAST_NAME.name).value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment