Exemplo n.º 1
0
def add_account(request):
    if request.method == "POST":
        form = AddAccount(request.POST)
        if form.is_valid():
            data = {}
            data['name'] = form.cleaned_data['name']
            data['kind'] = form.cleaned_data['kind']
            account = Account(**data)
            account.save()
            savings = SavingTotal.objects.all()
            for saving in savings:
                data = {}
                data['saving_total'] = saving
                data['account'] = account
                new_saving = Saving(**data)
                new_saving.save()
            messages.success(request,
                             u"Рахунок %s успішно доданий" % account.name)
    url = reverse("home") + "?list=accounts"
    return HttpResponseRedirect(url)
Exemplo n.º 2
0
    def create_account(self, member, account_type):
        """
        account_type: debit/debt
        """
        if account_type == 'debit':
            name = 'Debit {}'.format(member.name)
            acc_type = Account.CHECKING
            balance = random.randint(300, 2000)
        else:
            name = 'Credit {}'.format(member.name)
            acc_type = Account.LOAN
            balance = -random.randint(50000, 100000)

        a = Account(member=member)
        a.guid = uuid.uuid4().hex
        a.uid = uuid.uuid4().hex
        a.name = name
        a.type = acc_type
        a.updated_at = timezone.now()
        a.balance = balance
        a.available_balance = a.balance
        a.save()