def create_order_line(record): """Create an OrderLine.""" try: item = get_item_by_barcode(record["barcode"]) document_pid = item.get("document_pid") item_medium = item.get("medium") except ItemMigrationError: document_pid = get_migration_document_pid() item_medium = DEFAULT_ITEM_MEDIUM new_order_line = dict( document_pid=document_pid, patron_pid=get_patron_pid(record), recipient=get_recipient(record), medium=item_medium, payment_mode="MIGRATED_UNKNOWN", copies_ordered=1, # default 1 because is required ) total_price = get_cost(record) if total_price: new_order_line.update(total_price=total_price) if record.get("budget_code"): new_order_line.update(budget_code=record.get("budget_code")) return new_order_line
def clean_record_json(record): """Create a record for ILS.""" document_pid = None try: item = get_item_by_barcode(record["barcode"]) document_pid = item.get("document_pid") except ItemMigrationError: document_pid = get_migration_document_pid() # library_pid library = get_library_by_legacy_id(record["id_crcLIBRARY"]) library_pid = library.pid.pid_value new_record = dict( document_pid=document_pid, legacy_id=record.get("legacy_id"), library_pid=library_pid, patron_pid=get_patron_pid(record), status=get_status(record), type=get_type(record), ) # Optional fields expected_delivery_date = record.get("expected_date") if expected_delivery_date: new_record.update( expected_delivery_date=get_date(expected_delivery_date) ) received_date = record.get("arrival_date") if received_date: new_record.update(received_date=get_date(received_date)) request_date = record.get("request_date") if request_date: new_record.update(request_date=get_date(request_date)) due_date = record.get("due_date") if due_date: new_record.update(due_date=get_date(due_date)) total = get_cost(record) if total: new_record.update(total=total) notes = get_acq_ill_notes(record) if notes: new_record.update(notes=notes) budget_code = record.get("budget_code") if budget_code: new_record.update(budget_code=budget_code) return new_record
def create_order_line(record, order_status): """Create an OrderLine.""" document_cls = current_app_ils.document_record_cls barcode = record.get("barcode").replace("No barcode associated", "") item_medium = DEFAULT_ITEM_MEDIUM try: if barcode: item = get_item_by_barcode(barcode) document_pid = item["document_pid"] item_medium = item.get("medium", DEFAULT_ITEM_MEDIUM) else: document_pid = find_correct_document_pid(record) except ItemMigrationError: document_pid = find_correct_document_pid(record) if document_pid != MIGRATION_DOCUMENT_PID: document = document_cls.get_record_by_pid(document_pid) if document["document_type"] == "BOOK": item_medium = "PAPER" if record["request_type"] == 'acq-book': item_medium = "PAPER" new_order_line = dict( document_pid=document_pid, patron_pid=get_patron_pid(record), recipient=get_recipient(record), medium=item_medium, payment_mode=get_payment_mode(record), copies_ordered=1, # default 1 because is required ) if order_status == "RECEIVED": new_order_line.update({"copies_received": 1}) total_price = get_cost(record) if total_price: new_order_line.update(total_price=total_price) if record.get("budget_code"): new_order_line.update(payment_mode="BUDGET_CODE", budget_code=record.get("budget_code")) return new_order_line
def migrate_document_request(record): """Create a document request record for ILS.""" state = "PENDING" new_docreq = dict( legacy_id=record["legacy_id"], patron_pid=get_patron_pid(record), title="Migrated record, no title provided", state=state, request_type="LOAN", medium="MIGRATED_UNKNOWN", ) if record["status"] == "proposal-put aside": state = "DECLINED" new_docreq.update(state=state, decline_reason="OTHER") note = get_acq_ill_notes(record) if note: new_docreq.update(note=note) return new_docreq
def clean_record_json(record): """Create a record for ILS.""" barcode = (record.get("barcode").replace("No barcode associated", "").replace( "No barcode asociated", "")) status = get_status(record) try: if barcode: item = get_item_by_barcode(barcode) document_pid = item.get("document_pid") else: document_pid = find_correct_document_pid(record) except ItemMigrationError: document_pid = find_correct_document_pid(record) try: # library_pid provider = get_provider_by_legacy_id(record["id_crcLIBRARY"], provider_type="LIBRARY") provider_pid = provider.pid.pid_value except ProviderError as e: provider_pid = MIGRATION_PROVIDER_PID new_record = dict( document_pid=document_pid, legacy_id=record.get("legacy_id"), provider_pid=provider_pid, patron_pid=get_patron_pid(record), status=status, type=get_type(record), ) # Optional fields if status == "CANCELLED": new_record.update(cancel_reason="MIGRATED/UNKNOWN") expected_delivery_date = record.get("expected_date") if expected_delivery_date: new_record.update( expected_delivery_date=get_date(expected_delivery_date)) received_date = record.get("arrival_date") if received_date: new_record.update(received_date=get_date(received_date)) request_date = record.get("request_date") if request_date: new_record.update(request_date=get_date(request_date)) # former return date is the new due date of the borrowing request due_date = record.get("return_date") if due_date: new_record.update(due_date=get_date(due_date)) total = get_cost(record) if total: new_record.update(total=total) notes = get_acq_ill_notes(record) if notes: new_record.update(notes=notes) budget_code = record.get("budget_code") if budget_code: new_record.update(budget_code=budget_code) validate_ill(new_record) vocabulary_validator.validate(VOCABULARIES_FIELDS, new_record) return new_record