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

ENH: added a check that a loan does not reference the same box twice

parent ba490b98
No related branches found
No related tags found
1 merge request!3ENH: allow multiple items to be borrowed
Pipeline #60396 passed with warnings
......@@ -24,6 +24,7 @@ from __future__ import absolute_import
import linkahead as db
from caosadvancedtools.serverside.helper import get_timestamp, print_success
from linkahead.common.models import get_id_from_versionid, value_matches_versionid
from .box_loan import (BORROWER, BOX, COMMENT, DESTINATION, EXHAUST_CONTENTS, EXPECTED_RETURN,
F_BOX, F_COMMENT, F_DESTINATION, F_EMAIL, F_EXHAUST_CONTENTS,
......@@ -32,13 +33,17 @@ from .box_loan import (BORROWER, BOX, COMMENT, DESTINATION, EXHAUST_CONTENTS, EX
insert_or_update_person, main, send_loan_request_mail)
def create_loan(box, borrower, expected_return, exhaust_contents, comment,
destination):
def create_loan(box, borrower, expected_return, exhaust_contents, comment, destination):
""" Create a new loan record. """
if isinstance(box, list):
ids = [get_id_from_versionid(val) if value_matches_versionid(val) else val for val in box]
ids = [str(val) for val in ids]
if len(ids) != len(set(ids)):
raise ValueError("The loan must not reference the same item twice")
loan = db.Record().add_parent(LOAN)
loan.add_property(BOX, box, datatype=(db.LIST(BOX.name) if isinstance(box, list) else BOX.name))
loan.add_property(BOX, box, datatype=(
db.LIST(BOX.name) if isinstance(box, list) else BOX.name))
loan.add_property(BORROWER, borrower)
loan.add_property(EXPECTED_RETURN, expected_return)
loan.add_property(EXHAUST_CONTENTS, exhaust_contents)
......
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