def create_loan(params, should_force_checkout): """Create a loan on behalf of a user.""" if "patron_pid" not in params: raise MissingRequiredParameterError( description="'patron_pid' is required when creating a loan") if "item_pid" not in params: raise MissingRequiredParameterError( description="'item_pid' is required when creating a loan") if patron_has_active_loan_on_item(patron_pid=params["patron_pid"], item_pid=params["item_pid"]): raise PatronHasLoanOnItemError(params["patron_pid"], params["item_pid"]) if "document_pid" not in params: document_pid = Item.get_document_pid(params["item_pid"]) if document_pid: params["document_pid"] = document_pid if should_force_checkout: _ensure_item_can_circulate(params['item_pid']) # create a new loan record_uuid = uuid.uuid4() new_loan = {"item_pid": params["item_pid"]} pid = loan_pid_minter(record_uuid, data=new_loan) loan = Loan.create(data=new_loan, id_=record_uuid) # trigger the first transition loan = current_circulation.circulation.trigger( loan, **dict(params, trigger="checkout")) return pid, loan
def index_document_after_item_indexed(item_pid): """Index document to re-compute circulation information.""" log_func = partial(_log, origin_rec_type='Item', origin_recid=item_pid, dest_rec_type='Document') log_func(msg=MSG_ORIGIN) document_pid = Item.get_document_pid(item_pid) _index_record_by_pid(Document, document_pid, log_func)