예제 #1
0
    def _circulation_for_document_resolver(document_pid):
        """Return circulation info for the given document."""
        circulation = {}
        active_loans_count = 0
        loanable_items_count = 0
        items_count = 0
        item_pids = circulation_items_retriever(document_pid)

        for pid in item_pids:
            items_count += 1
            if not is_item_available(pid):
                active_loans_count += 1

            if circulation_is_item_available(pid):
                loanable_items_count += 1

        search = search_by_pid(
            document_pid=document_pid,
            filter_states=current_app.config.get(
                "CIRCULATION_STATES_LOAN_COMPLETED", []),
        )

        pending_loans = search_by_pid(document_pid=document_pid,
                                      filter_states=['PENDING'
                                                     ]).execute().hits.total

        circulation["number_of_past_loans"] = search.execute().hits.total
        circulation["number_of_items"] = items_count
        circulation["active_loans"] = active_loans_count
        circulation["loanable_items"] = loanable_items_count
        circulation["pending_loans"] = pending_loans
        circulation["overbooked"] = pending_loans > loanable_items_count
        return circulation
def test_item_availibility(indexed_loans):
    """Test item_availibility with various conditions."""
    assert not is_item_available(item_pid='item_pending_1')
    assert not is_item_available(item_pid='item_on_loan_2')
    assert is_item_available(item_pid='item_returned_3')
    assert not is_item_available(item_pid='item_in_transit_4')
    assert not is_item_available(item_pid='item_at_desk_5')
    assert not is_item_available(item_pid='item_pending_on_loan_6')
    assert is_item_available(item_pid='item_returned_6')
    assert is_item_available(item_pid='no_loan')
def test_item_availability(indexed_loans):
    """Test item_availability with various conditions."""
    assert is_item_available(item_pid="item_pending_1")
    assert not is_item_available(item_pid="item_on_loan_2")
    assert is_item_available(item_pid="item_returned_3")
    assert not is_item_available(item_pid="item_in_transit_4")
    assert not is_item_available(item_pid="item_at_desk_5")
    assert not is_item_available(item_pid="item_pending_on_loan_6")
    assert is_item_available(item_pid="item_returned_6")
    assert is_item_available(item_pid="no_loan")