Ejemplo n.º 1
0
def resolve_item_from_loan(item_pid):
    """Resolve the item referenced in loan based on its PID type."""
    if item_pid["type"] == ITEM_PID_TYPE:
        rec_cls = current_app_ils.item_record_cls
    elif item_pid["type"] == BORROWING_REQUEST_PID_TYPE:
        rec_cls = current_ils_ill.borrowing_request_record_cls
    else:
        raise UnknownItemPidTypeError(pid_type=item_pid["type"])
    return rec_cls.get_record_by_pid(item_pid["value"])
Ejemplo n.º 2
0
def can_item_circulate(item_pid):
    """Return True if Item can circulate."""
    if item_pid["type"] not in [BORROWING_REQUEST_PID_TYPE, ITEM_PID_TYPE]:
        raise UnknownItemPidTypeError(pid_type=item_pid["type"])

    if item_pid["type"] == BORROWING_REQUEST_PID_TYPE:
        return True

    Item = current_app_ils.item_record_cls
    item = Item.get_record_by_pid(item_pid["value"])
    if item:
        return item["status"] == "CAN_CIRCULATE"
    return False
Ejemplo n.º 3
0
def get_location_pid_by_item_pid(item_pid):
    """Retrieve Location PID given an Item PID."""
    if item_pid["type"] not in [BORROWING_REQUEST_PID_TYPE, ITEM_PID_TYPE]:
        raise UnknownItemPidTypeError(pid_type=item_pid["type"])

    if item_pid["type"] == BORROWING_REQUEST_PID_TYPE:
        # return a fake location in case of ILL
        return BORROWING_REQUEST_PID_TYPE

    Item = current_app_ils.item_record_cls
    item_rec = Item.get_record_by_pid(item_pid["value"])
    item = item_rec.replace_refs()
    return item["internal_location"]["location"]["pid"]
Ejemplo n.º 4
0
def resolve_item_from_loan(item_pid):
    """Resolve the item referenced in loan based on its PID type."""
    from invenio_app_ils.ill.api import BORROWING_REQUEST_PID_TYPE
    from invenio_app_ils.ill.proxies import current_ils_ill
    from invenio_app_ils.items.api import ITEM_PID_TYPE
    from invenio_app_ils.proxies import current_app_ils

    if item_pid["type"] == ITEM_PID_TYPE:
        rec_cls = current_app_ils.item_record_cls
    elif item_pid["type"] == BORROWING_REQUEST_PID_TYPE:
        rec_cls = current_ils_ill.borrowing_request_record_cls
    else:
        from invenio_app_ils.errors import UnknownItemPidTypeError
        raise UnknownItemPidTypeError(pid_type=item_pid["type"])
    return rec_cls.get_record_by_pid(item_pid["value"])
Ejemplo n.º 5
0
def validate_item_pid(item_pid):
    """Validate item or raise and return an obj to easily distinguish them."""
    from invenio_app_ils.items.api import ITEM_PID_TYPE

    if item_pid["type"] not in [BORROWING_REQUEST_PID_TYPE, ITEM_PID_TYPE]:
        raise UnknownItemPidTypeError(pid_type=item_pid["type"])

    # inline object with properties
    return type(
        "obj",
        (object, ),
        {
            "is_item": item_pid["type"] == ITEM_PID_TYPE,
            "is_brw_req": item_pid["type"] == BORROWING_REQUEST_PID_TYPE,
        },
    )