def location(): """Create library location.""" click.echo("Creating locations...") weekdays = [ "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday", ] closed = ["saturday", "sunday"] times = [ { "start_time": "08:30", "end_time": "18:00" }, ] opening_weekdays = [] for weekday in weekdays: is_open = weekday not in closed opening_weekdays.append({ "weekday": weekday, "is_open": weekday not in closed, **({ "times": times } if is_open else {}), }) location = { "pid": RecordIdProviderV2.create().pid.pid_value, "name": "CERN Central Library", "address": "Rue de Meyrin", "email": "*****@*****.**", "opening_weekdays": opening_weekdays, "opening_exceptions": [], } record = current_app_ils.location_record_cls.create(location) minter(LOCATION_PID_TYPE, "pid", record) db.session.commit() current_app_ils.location_indexer.index(record)
def create_pid(self): """Create a new persistent identifier.""" return RecordIdProviderV2.create().pid.pid_value
def create_loan(user_email, is_past_loan): """Create a loan.""" # hardcode doc/item pids from the demo_data jsons ongoing_loan_item_pid = "vgrh9-jvj8E" past_loan_item_pid = "678e3-an678A" ongoing_loan_doc_pid = "67186-5rs9E" past_loan_doc_pid = "qaywb-gfe4B" active_loan = (get_active_loan_by_item_pid({ "type": "pitmid", "value": ongoing_loan_item_pid }).execute().hits) lt_es7 = ES_VERSION[0] < 7 total = active_loan.total if lt_es7 else active_loan.total.value if total > 0 and not is_past_loan: click.secho( "Item for ongoing loan is already loaned by patron with email {0}." .format(active_loan[0].patron.email), fg="red", ) return patron = User.query.filter_by(email=user_email).one() patron_pid = patron.get_id() loc_pid, _ = current_app_ils.get_default_location_pid delivery = list( current_app.config["ILS_CIRCULATION_DELIVERY_METHODS"].keys())[randint( 0, 1)] loan_dict = { "pid": RecordIdProviderV2.create().pid.pid_value, "patron_pid": "{}".format(patron_pid), "pickup_location_pid": "{}".format(loc_pid), "transaction_location_pid": "{}".format(loc_pid), "transaction_user_pid": "{}".format(patron_pid), "delivery": { "method": delivery }, } if is_past_loan: loan_dict["state"] = "ITEM_RETURNED" loan_dict["document_pid"] = past_loan_doc_pid transaction_date = start_date = arrow.utcnow() - timedelta(days=365) end_date = start_date + timedelta(weeks=4) item_pid = past_loan_item_pid else: loan_dict["state"] = "ITEM_ON_LOAN" loan_dict["document_pid"] = ongoing_loan_doc_pid transaction_date = start_date = arrow.utcnow( ) - (timedelta(weeks=4) - timedelta( days=current_app.config["ILS_CIRCULATION_LOAN_WILL_EXPIRE_DAYS"])) end_date = start_date + timedelta(weeks=4) item_pid = ongoing_loan_item_pid loan_dict["transaction_date"] = transaction_date.isoformat() loan_dict["start_date"] = start_date.date().isoformat() loan_dict["end_date"] = end_date.date().isoformat() loan_dict["extension_count"] = randint(0, 3) loan_dict["item_pid"] = {"type": ITEM_PID_TYPE, "value": item_pid} loan = current_circulation.loan_record_cls.create(loan_dict) minter(CIRCULATION_LOAN_PID_TYPE, "pid", loan) db.session.commit() current_circulation.loan_indexer().index(loan) item = current_app_ils.item_record_cls.get_record_by_pid(item_pid) current_app_ils.item_indexer.index(item) current_search.flush_and_refresh(index="*") doc = current_app_ils.document_record_cls.get_record_by_pid( loan_dict["document_pid"]) click.secho( "Loan with pid '{0}' on document '{1}' was created.".format( loan_dict["pid"], doc["title"]), fg="blue", )