Beispiel #1
0
def save_new_debt(form):
    name = form.cleaned_data['name']
    money = form.cleaned_data['money']
    owner = form.cleaned_data['owner']
    spendingType = form.cleaned_data['spendingType']
    comment = form.cleaned_data['comment']
    periodic = form.cleaned_data['periodic']

    s = StaticDebt(name=name,
                   money=money,
                   owner=owner,
                   spendingType=spendingType,
                   comment=comment)
    s.save()

    if periodic:
        p = PeriodicDebt(
            period=periodic,
            staticDebt=s,
            last_generation_date=date.today(),
        )
        p.save()
    else:
        p = None

    Debt(staticDebt=s, periodicDebt=p).save()

    if not DebtAccount.objects.count():
        DebtAccount(id=1, name='Долги', money=0).save()
    debt_account = DebtAccount.objects.get(pk=1)
    debt_account.money -= money
    debt_account.save()
Beispiel #2
0
def update_old_debt(form, pk):
    name = form.cleaned_data['name']
    money = form.cleaned_data['money']
    owner = form.cleaned_data['owner']
    spendingType = form.cleaned_data['spendingType']
    comment = form.cleaned_data['comment']
    periodic = form.cleaned_data['periodic']

    old_debt = Debt.objects.get(pk=pk)
    difference = money - old_debt.staticDebt.money

    s = StaticDebt(
        id=old_debt.staticDebt_id,
        name=name,
        money=money,
        owner=owner,
        spendingType=spendingType,
        comment=comment
    )
    s.save()

    if periodic:
        if old_debt.is_periodic():
            periodic_debt_id = old_debt.periodicDebt_id
        else:
            periodic_debt_id = None

        p = PeriodicDebt(
            id=periodic_debt_id,
            period=periodic,
            staticDebt=s,
            last_generation_date=date.today(),
        )
        p.save()
    else:
        p = None
        if old_debt.is_periodic():
            PeriodicDebt.objects.get(debt__id=pk).delete()

    Debt(
        id=pk,
        staticDebt=s,
        periodicDebt=p
    ).save()

    debt_account = DebtAccount.objects.get(pk=1)
    debt_account.money -= difference
    debt_account.save()
Beispiel #3
0
def update_old_debt(form, pk):
    name = form.cleaned_data['name']
    money = form.cleaned_data['money']
    owner = form.cleaned_data['owner']
    spendingType = form.cleaned_data['spendingType']
    comment = form.cleaned_data['comment']
    periodic = form.cleaned_data['periodic']

    old_debt = Debt.objects.get(pk=pk)
    difference = money - old_debt.staticDebt.money

    s = StaticDebt(id=old_debt.staticDebt_id,
                   name=name,
                   money=money,
                   owner=owner,
                   spendingType=spendingType,
                   comment=comment)
    s.save()

    if periodic:
        if old_debt.is_periodic():
            periodic_debt_id = old_debt.periodicDebt_id
        else:
            periodic_debt_id = None

        p = PeriodicDebt(
            id=periodic_debt_id,
            period=periodic,
            staticDebt=s,
            last_generation_date=date.today(),
        )
        p.save()
    else:
        p = None
        if old_debt.is_periodic():
            PeriodicDebt.objects.get(debt__id=pk).delete()

    Debt(id=pk, staticDebt=s, periodicDebt=p).save()

    debt_account = DebtAccount.objects.get(pk=1)
    debt_account.money -= difference
    debt_account.save()
Beispiel #4
0
def save_new_debt(form):
    name = form.cleaned_data['name']
    money = form.cleaned_data['money']
    owner = form.cleaned_data['owner']
    spendingType = form.cleaned_data['spendingType']
    comment = form.cleaned_data['comment']
    periodic = form.cleaned_data['periodic']

    s = StaticDebt(
        name=name,
        money=money,
        owner=owner,
        spendingType=spendingType,
        comment=comment
    )
    s.save()

    if periodic:
        p = PeriodicDebt(
            period=periodic,
            staticDebt=s,
            last_generation_date=date.today(),
        )
        p.save()
    else:
        p = None

    Debt(
        staticDebt=s,
        periodicDebt=p
    ).save()

    if not DebtAccount.objects.count():
        DebtAccount(
            id=1,
            name='Долги',
            money=0
        ).save()
    debt_account = DebtAccount.objects.get(pk=1)
    debt_account.money -= money
    debt_account.save()