Пример #1
0
def edittransaction(request, transaction_id):
    if request.method == 'POST':
        spending = request.POST['spending']
        weekly_expenses = request.POST['weekly_expenses']
        item = request.POST['item']
        price = request.POST['price']
        get_spending = Spending.objects.get(id=spending)
        get_weekly_expenses = WeeklyExpenses.objects.get(id=weekly_expenses)

        updated_date = timezone.now()

        update_transaction = Transaction.objects.get(
            id=transaction_id)

        update_transaction.item = item
        update_transaction.price = price
        update_transaction.spending = get_spending
        update_transaction.weekly_expenses = get_weekly_expenses

        update_transaction.updated_date = updated_date
        update_transaction.save()

        return redirect('backoffice-list-transaction')
    else:
        list_spending = Spending.get_spending_list()
        list_weekly_expenses = WeeklyExpenses.get_list_weekly_expenses()
        list_transaction = Transaction.get_detail_transaction(
            transaction_id)
        return render(request, 'backoffice/edit-transaction.html', {'list_transaction': list_transaction, 'transaction_id': transaction_id,
                                                                    'list_spending': list_spending, 'list_weekly_expenses': list_weekly_expenses})
Пример #2
0
def addtransaction(request):
    if request.method == 'POST':
        active_schedule = Period.objects.filter(completed=False).first()
        item = request.POST['item']
        price = request.POST['price']
        spending = request.POST['spending']
        weekly_expenses = request.POST['weekly_expenses']
        get_spending = Spending.objects.get(id=spending)
        get_weekly_expenses = WeeklyExpenses.objects.get(id=weekly_expenses)
        created_date = timezone.now()
        updated_date = timezone.now()
        add_transaction = Transaction(item=item, price=price, spending=get_spending, weekly_expenses=get_weekly_expenses, period=active_schedule,
                                      created_date=created_date, updated_date=updated_date)

        add_transaction.save()
        return redirect('backoffice-list-transaction')
    else:
        list_spending = Spending.get_spending_list()
        list_weekly_expenses = WeeklyExpenses.get_list_weekly_expenses()
        return render(request, 'backoffice/add-transaction.html', {
            'list_spending': list_spending,
            'list_weekly_expenses': list_weekly_expenses,
        })
Пример #3
0
def listsweeklyexpenses(request):
    list_weekly_expenses = WeeklyExpenses.get_list_weekly_expenses()
    return render(request, 'backoffice/backoffice-weekly-expenses.html', {'list_weekly_expenses': list_weekly_expenses})