Exemplo n.º 1
0
def get_provisional_items_pids_candidate_to_delete():
    """Returns checked-in provisional items pids.

    Returns list of candidate provisional items pids to delete, based on the
    status of the item. Filtering by the status `ItemStatus.ON_SHELF` removes
    items with active loans. in addition, remove items with active fees.
    :return an item pid generator.
    """
    from rero_ils.modules.items.api import ItemsSearch

    # query ES index for open fees
    query_fees = PatronTransactionsSearch()\
        .filter('term', status='open')\
        .filter('exists', field='item')\
        .filter('range', total_amount={'gt': 0})\
        .source('item')
    # list of item pids with open fees
    item_pids_with_fees = [hit.item.pid for hit in query_fees.scan()]
    query = ItemsSearch()\
        .filter('term', type=TypeOfItem.PROVISIONAL) \
        .filter('terms', status=[ItemStatus.ON_SHELF]) \
        .exclude('terms', pid=item_pids_with_fees)\
        .source('pid')
    for hit in query.scan():
        yield hit.pid
Exemplo n.º 2
0
def index_items_with_temporary_location():
    """Index items with temporary location."""
    query = ItemsSearch() \
        .filter('exists', field='temporary_location').source(['pid'])
    ids = [(hit.meta.id, hit.pid) for hit in query.scan()]
    for id, pid in ids:
        item = Item.get_record_by_id(id)
        item.reindex()
        LOGGER.info(f'  * Reindexed item#{pid}')
Exemplo n.º 3
0
def index_items_with_temporary_location():
    """Index items with temporary location."""
    query = ItemsSearch() \
        .filter('exists', field='temporary_location').source(['pid'])
    ids = [(hit.meta.id, hit.pid) for hit in query.scan()]
    errors = 0
    for idx, (id, pid) in enumerate(ids):
        LOGGER.info(f'{idx} * Reindex item: {pid}')
        try:
            item = Item.get_record_by_id(id)
            item.reindex()
        except Exception as err:
            LOGGER.error(f'{idx} * Reindex item: {pid} {err}')
            errors += 1
    return errors
Exemplo n.º 4
0
def get_items_by_organisation_pid(organisation_pid):
    """Get items by organisation pid."""
    query = ItemsSearch().filter(
            'term', organisation__pid=organisation_pid)\
        .source('pid')
    return [item.pid for item in query.scan()]