Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
def migrate_order(record):
    """Create a order record for ILS."""
    new_order = dict(
        legacy_id=record["legacy_id"],
        order_lines=[create_order_line(record)],
        status=get_status(record),
    )

    order_date = record["request_date"]
    if order_date:
        new_order.update(order_date=get_date(order_date))
    else:
        new_order.update(order_date="1970-01-01")

    # Optional fields
    grand_total = get_cost(record)
    if grand_total:
        new_order.update(grand_total=grand_total)

    vendor_pid = get_vendor_pid_by_legacy_id(record["id_crcLIBRARY"],
                                             grand_total)
    new_order.update(vendor_pid=vendor_pid)

    expected_delivery_date = record.get("expected_date")
    if expected_delivery_date:
        new_order.update(
            expected_delivery_date=get_date(expected_delivery_date))

    received_date = record.get("arrival_date")
    if received_date:
        new_order.update(received_date=get_date(received_date))

    notes = get_acq_ill_notes(record)
    if notes:
        new_order.update(notes=notes)

    return new_order
Beispiel #4
0
def migrate_order(record):
    """Create a order record for ILS."""
    status = get_status(record)

    new_order = dict(
        legacy_id=record["legacy_id"],
        order_lines=[create_order_line(record, status)],
        status=status,
    )

    order_date = record["request_date"]
    if order_date:
        new_order.update(order_date=get_date(order_date))
    else:
        new_order.update(order_date="1970-01-01")

    # Optional fields
    if status == "CANCELLED":
        new_order.update(cancel_reason="MIGRATED/UNKNOWN")

    grand_total = get_cost(record)
    if grand_total:
        new_order.update(grand_total=grand_total)
    try:

        provider_type = 'VENDOR'

        # due to migrating the article requests as orders
        # (formerly treated as ILLs)
        if record['request_type'] == 'article':
            provider_type = 'LIBRARY'

        provider_legacy_id = record["id_crcLIBRARY"]

        # perform merge of libraries and vendors by legacy id
        vendor_merge_mapper = {"63": 19, "47": 20, "48": 37}
        library_merge_mapper = {"72": 33, "74": 42}

        if provider_type == 'VENDOR' and provider_legacy_id in [63, 47, 48]:
            provider_legacy_id = vendor_merge_mapper[str(provider_legacy_id)]
            provider_type = 'LIBRARY'

        elif provider_type == 'LIBRARY' and provider_legacy_id in [72, 74]:
            provider_type = 'VENDOR'
            provider_legacy_id = library_merge_mapper[str(provider_legacy_id)]

        provider = get_provider_by_legacy_id(provider_legacy_id,
                                             provider_type=provider_type,
                                             grand_total=grand_total)
        provider_pid = provider.pid.pid_value
    except ProviderError as e:
        provider_pid = MIGRATION_PROVIDER_PID
    new_order.update(provider_pid=provider_pid)

    expected_delivery_date = record.get("expected_date")
    if expected_delivery_date:
        new_order.update(
            expected_delivery_date=get_date(expected_delivery_date))

    received_date = record.get("arrival_date")
    if received_date:
        new_order.update(received_date=get_date(received_date))

    notes = get_acq_ill_notes(record)
    if notes:
        new_order.update(notes=notes)

    validate_order(new_order)

    vocabulary_validator.validate(VOCABULARIES_FIELDS, new_order)

    return new_order
Beispiel #5
0
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