diff --git a/accounting/migrations/0003_auto_20160617_1520.py b/accounting/migrations/0003_auto_20160617_1520.py new file mode 100644 index 00000000..d8fcf4d9 --- /dev/null +++ b/accounting/migrations/0003_auto_20160617_1520.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import accounting.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounting', '0002_auto_20160530_1001'), + ] + + operations = [ + migrations.RemoveField( + model_name='bankaccount', + name='rib', + ), + migrations.AddField( + model_name='bankaccount', + name='iban', + field=models.CharField(blank=True, verbose_name='iban', max_length=255), + ), + migrations.AddField( + model_name='generaljournal', + name='amount', + field=accounting.models.CurrencyField(default=0, max_digits=12, decimal_places=2, verbose_name='amount'), + preserve_default=False, + ), + ] diff --git a/accounting/migrations/0004_auto_20160620_1307.py b/accounting/migrations/0004_auto_20160620_1307.py new file mode 100644 index 00000000..bc137e48 --- /dev/null +++ b/accounting/migrations/0004_auto_20160620_1307.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import accounting.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounting', '0003_auto_20160617_1520'), + ] + + operations = [ + migrations.AlterField( + model_name='generaljournal', + name='amount', + field=accounting.models.CurrencyField(max_digits=12, verbose_name='amount', default=0, decimal_places=2), + ), + ] diff --git a/accounting/models.py b/accounting/models.py index f6776774..cfc37fc2 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -27,7 +27,7 @@ class CurrencyField(models.DecimalField): class BankAccount(models.Model): name = models.CharField(_('name'), max_length=30) - rib = models.CharField(_('rib'), max_length=255, blank=True) + iban = models.CharField(_('iban'), max_length=255, blank=True) number = models.CharField(_('account number'), max_length=255, blank=True) club = models.ForeignKey(Club, related_name="bank_accounts") @@ -85,6 +85,23 @@ class GeneralJournal(models.Model): name = models.CharField(_('name'), max_length=30) closed = models.BooleanField(_('is closed'), default=False) club_account = models.ForeignKey(ClubAccount, related_name="journals", null=False) + amount = CurrencyField(_('amount'), default=0) + + def __init__(self, *args, **kwargs): + super(GeneralJournal, self).__init__(*args, **kwargs) + + def save(self, *args, **kwargs): + if self.id == None: + amount = 0 + super(GeneralJournal, self).save(*args, **kwargs) + + def can_be_created_by(user): + """ + Method to see if an object can be created by the given user + """ + if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): # TODO: add the treasurer of the club + return True + return False def is_owned_by(self, user): """ diff --git a/accounting/views.py b/accounting/views.py index e6e758b4..199a27ee 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -2,8 +2,10 @@ from django.views.generic import ListView, DetailView, RedirectView from django.views.generic.edit import UpdateView, CreateView, DeleteView from django.shortcuts import render from django.core.urlresolvers import reverse_lazy +from django.forms.models import modelform_factory +from django.forms import HiddenInput -from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin +from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin from accounting.models import BankAccount, ClubAccount, GeneralJournal, Operation, AccountingType # Accounting types @@ -113,13 +115,13 @@ class ClubAccountDeleteView(CanEditPropMixin, DeleteView): # TODO change Delete # Journal views -class JournalCreateView(CanEditMixin, CreateView): +class JournalCreateView(CanCreateMixin, CreateView): # FIXME: anonymous user has been able to create a journal """ Create a general journal """ model = GeneralJournal - fields = ['name', 'start_date', 'club_account'] template_name = 'accounting/account_edit.jinja' + fields = ['name', 'start_date', 'club_account'] class JournalDetailView(CanViewMixin, DetailView): """ @@ -145,7 +147,7 @@ class OperationCreateView(CanEditMixin, CreateView): Create an operation """ model = Operation - fields = ['journal', 'date', 'cheque_number', 'type'] + fields = ['amount', 'journal', 'date', 'cheque_number', 'type'] template_name = 'accounting/account_edit.jinja' class OperationEditView(CanViewMixin, UpdateView): diff --git a/club/templates/club/club_tools.jinja b/club/templates/club/club_tools.jinja index 9649c8da..37b93368 100644 --- a/club/templates/club/club_tools.jinja +++ b/club/templates/club/club_tools.jinja @@ -4,7 +4,9 @@