Пример #1
0
    def payment(account_uuid, payment, time):
        account = _get_account(account_uuid)

        last_balance = AccountController.update_balances(account_uuid, time)
        principal_owed = last_balance.principal_owed
        interest_owed = last_balance.interest_owed

        try:
            principal, interest = make_payment(principal_owed, interest_owed,
                                               payment)
        except ValueError as ex:
            raise APIError(str(ex), SC.UNPROCESSABLE)

        account.balances.append(
            _create_balance(time=time,
                            principal_owed=principal,
                            interest_owed=interest,
                            max_credit=account.max_credit))

        account.payments.append(
            Payment(uuid=str(uuid.uuid4()), amount=payment, time=time))

        current_app.db.add(account)
        current_app.db.commit()
        return serialize_account(account)
Пример #2
0
def event_index(request, year=None, month=None, day=None):
    db = default_storage()
    events = Payment.objects(db).order_by("date_time", reverse=True)
    if year:
        events = events.where(date_time__year=year)
        if month:
            events = event.where(date_time__month=month)
            if day:
                events = events.where(date_time__day=day)
    return {"object_list": events}
Пример #3
0
def dashboard(request):
    db = default_storage()
    contracts = Contract.objects(db).order_by("next_date_time")
    payments = Payment.objects(db).order_by("date_time")
    return {
        "contracts": contracts,
        "payments": payments,
        "render_rel_delta": render_rel_delta,
        "chart_url_for_payments": chart_url_for_payments,
        "today": datetime.datetime.today(),
        "default_currency": get_default_currency(),
    }