diff --git a/accounting/migrations/0005_auto_20160622_0953.py b/accounting/migrations/0005_auto_20160622_0953.py new file mode 100644 index 00000000..73e88983 --- /dev/null +++ b/accounting/migrations/0005_auto_20160622_0953.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import accounting.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounting', '0004_auto_20160620_1307'), + ] + + operations = [ + migrations.RenameField( + model_name='operation', + old_name='type', + new_name='accounting_type', + ), + migrations.AddField( + model_name='generaljournal', + name='effective_amount', + field=accounting.models.CurrencyField(default=0, decimal_places=2, verbose_name='effective_amount', max_digits=12), + ), + ] diff --git a/accounting/migrations/0006_operation_type.py b/accounting/migrations/0006_operation_type.py new file mode 100644 index 00000000..0f944a18 --- /dev/null +++ b/accounting/migrations/0006_operation_type.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounting', '0005_auto_20160622_0953'), + ] + + operations = [ + migrations.AddField( + model_name='operation', + name='type', + field=models.CharField(verbose_name='operation type', choices=[('DEBIT', 'Debit'), ('CREDIT', 'Credit')], max_length=10, default='DEBIT'), + preserve_default=False, + ), + ] diff --git a/accounting/migrations/0007_auto_20160622_0959.py b/accounting/migrations/0007_auto_20160622_0959.py new file mode 100644 index 00000000..90eee6b9 --- /dev/null +++ b/accounting/migrations/0007_auto_20160622_0959.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounting', '0006_operation_type'), + ] + + operations = [ + migrations.AlterField( + model_name='operation', + name='cheque_number', + field=models.IntegerField(verbose_name='cheque number', default=-1), + ), + ] diff --git a/accounting/migrations/0008_auto_20160622_1005.py b/accounting/migrations/0008_auto_20160622_1005.py new file mode 100644 index 00000000..95b77f6a --- /dev/null +++ b/accounting/migrations/0008_auto_20160622_1005.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounting', '0007_auto_20160622_0959'), + ] + + operations = [ + migrations.AlterField( + model_name='operation', + name='type', + field=models.CharField(verbose_name='operation type', choices=[('debit', 'Debit'), ('credit', 'Credit')], max_length=10), + ), + ] diff --git a/accounting/migrations/0009_auto_20160622_1030.py b/accounting/migrations/0009_auto_20160622_1030.py new file mode 100644 index 00000000..1bbd59d0 --- /dev/null +++ b/accounting/migrations/0009_auto_20160622_1030.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounting', '0008_auto_20160622_1005'), + ] + + operations = [ + migrations.AddField( + model_name='operation', + name='label', + field=models.CharField(verbose_name='label', default='', max_length=50), + preserve_default=False, + ), + migrations.AlterField( + model_name='operation', + name='type', + field=models.CharField(verbose_name='operation type', choices=[('debit', 'Debit'), ('credit', 'Credit')], max_length=8), + ), + ] diff --git a/accounting/models.py b/accounting/models.py index cfc37fc2..87c62dd4 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -86,6 +86,7 @@ class GeneralJournal(models.Model): closed = models.BooleanField(_('is closed'), default=False) club_account = models.ForeignKey(ClubAccount, related_name="journals", null=False) amount = CurrencyField(_('amount'), default=0) + effective_amount = CurrencyField(_('effective_amount'), default=0) def __init__(self, *args, **kwargs): super(GeneralJournal, self).__init__(*args, **kwargs) @@ -125,6 +126,70 @@ class GeneralJournal(models.Model): def __str__(self): return self.name + def update_amounts(self): + self.amount = 0 + self.effective_amount = 0 + for o in self.operations.all(): + if o.type == "credit": + if o.done: + self.effective_amount += o.amount + self.amount += o.amount + else: + if o.done: + self.effective_amount -= o.amount + self.amount -= o.amount + self.save() + +class Operation(models.Model): + """ + An operation is a line in the journal, a debit or a credit + """ + journal = models.ForeignKey(GeneralJournal, related_name="operations", null=False) + amount = CurrencyField(_('amount')) + date = models.DateField(_('date')) + label = models.CharField(_('label'), max_length=50) + remark = models.TextField(_('remark'), max_length=255) + mode = models.CharField(_('payment method'), max_length=255, choices=settings.SITH_ACCOUNTING_PAYMENT_METHOD) + cheque_number = models.IntegerField(_('cheque number'), default=-1) + invoice = models.FileField(upload_to='invoices', null=True, blank=True) + done = models.BooleanField(_('is done'), default=False) + accounting_type = models.ForeignKey('AccountingType', related_name="operations") + type = models.CharField(_('operation type'), max_length=8, choices=[ + ('debit', _('Debit')), + ('credit', _('Credit')), + ]) + + def save(self): + super(Operation, self).save() + self.journal.update_amounts() + + def is_owned_by(self, user): + """ + Method to see if that object can be edited by the given user + """ + if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): + return True + m = self.journal.club_account.get_membership_for(user) + if m is not None and m.role >= 7: + return True + return False + + def can_be_edited_by(self, user): + """ + Method to see if that object can be edited by the given user + """ + if self.journal.can_be_edited_by(user): + return True + return False + + def get_absolute_url(self): + return reverse('accounting:journal_details', kwargs={'j_id': self.journal.id}) + + def __str__(self): + return "%d | %s | %d € | %s | %s | %s" % ( + self.id, self.type, self.amount, self.date, self.accounting_type, self.done, + ) + class AccountingType(models.Model): """ Class describing the accounting types. @@ -149,43 +214,3 @@ class AccountingType(models.Model): def __str__(self): return self.movement_type+" - "+self.code+" - "+self.label -class Operation(models.Model): - """ - An operation is a line in the journal, a debit or a credit - """ - journal = models.ForeignKey(GeneralJournal, related_name="operations", null=False) - amount = CurrencyField(_('amount')) - date = models.DateField(_('date')) - remark = models.TextField(_('remark'), max_length=255) - mode = models.CharField(_('payment method'), max_length=255, choices=settings.SITH_ACCOUNTING_PAYMENT_METHOD) - cheque_number = models.IntegerField(_('cheque number')) - invoice = models.FileField(upload_to='invoices', null=True, blank=True) - done = models.BooleanField(_('is done'), default=False) - type = models.ForeignKey(AccountingType, related_name="operations") - - def is_owned_by(self, user): - """ - Method to see if that object can be edited by the given user - """ - if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): - return True - m = self.journal.club_account.get_membership_for(user) - if m is not None and m.role >= 7: - return True - return False - - def can_be_edited_by(self, user): - """ - Method to see if that object can be edited by the given user - """ - if self.journal.can_be_edited_by(user): - return True - return False - - - def get_absolute_url(self): - return reverse('accounting:journal_details', kwargs={'j_id': self.journal.id}) - - def __str__(self): - return str(self.id)+" - "+str(self.date) - diff --git a/accounting/templates/accounting/bank_account_details.jinja b/accounting/templates/accounting/bank_account_details.jinja index afe9c357..74695755 100644 --- a/accounting/templates/accounting/bank_account_details.jinja +++ b/accounting/templates/accounting/bank_account_details.jinja @@ -1,6 +1,10 @@ {% extends "core/base.jinja" %} {% block content %} +
+Accounting > +{{ object.name }} +
+Accounting > +{{object.bank_account }} > +{{ object }}
+Accounting > +{{object.club_account.bank_account }} > +{{ object.club_account }} > +{{ object.name }} +
+Amount: {{ object.amount }} € - Effective amount: {{ object.effective_amount }} €
-Nb | +Date | +Label | +Amount | +Payment mode | + +Code | +Nature | +Done | +Comment | +Actions | +|
{{ o.id }} | +{{ o.date }} | +{{ o.label }} | +{{ o.amount }} € | +{{ o.mode }} | +{{ o.accounting_type.code }} | +{{ o.accounting_type.label }} | + {% if o.done %} +Yes | + {% else %} +No | + {% endif %} +{{ o.remark }} | +Edit | +