Пример #1
0
 def _test(start_date, expected_next_open_date):
     next_open = find_next_open_date(_LOCATION_PID,
                                     _date_from_string(start_date))
     if expected_next_open_date:
         assert next_open == _date_from_string(expected_next_open_date)
     else:
         assert next_open is None
Пример #2
0
def _update_loan_end_date(loan):
    """Update the end date to the next opening day."""
    loan["end_date"] = arrow.get(
        find_next_open_date(
            circulation_item_location_retriever(loan["item_pid"]),
            loan["end_date"].date(),
        ))
Пример #3
0
def extend_active_loans_location_closure(location_pid):
    """Extends all ongoing loans that would end on a closure."""
    modified_count = 0
    for hit in get_active_loans().scan():
        if circulation_item_location_retriever(hit.item_pid) == location_pid:
            current_end_date = arrow.get(hit.end_date).date()
            new_end_date = find_next_open_date(location_pid, current_end_date)
            if new_end_date != current_end_date:  # Update loan
                modified_count += 1
                loan = current_circulation.loan_record_cls.get_record_by_pid(
                    hit.pid
                )
                _log("extend_loan_closure_before", loan)
                loan.update(end_date=new_end_date.isoformat())
                loan.commit()
                current_circulation.loan_indexer().index(loan)
                _log("extend_loan_closure_after", loan)
                send_loan_end_date_updated_mail.apply_async((loan,))
    db.session.commit()
    _log("extend_loan_closure_end", dict(modified_count=modified_count))