diff --git a/accounting/migrations/0012_auto_20160720_1847.py b/accounting/migrations/0012_auto_20160720_1847.py new file mode 100644 index 00000000..23322935 --- /dev/null +++ b/accounting/migrations/0012_auto_20160720_1847.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounting', '0011_auto_20160718_1805'), + ] + + operations = [ + migrations.AlterModelOptions( + name='operation', + options={'ordering': ['-number']}, + ), + migrations.AddField( + model_name='operation', + name='number', + field=models.IntegerField(default=1, verbose_name='number'), + preserve_default=False, + ), + migrations.AlterUniqueTogether( + name='operation', + unique_together=set([('number', 'journal')]), + ), + ] diff --git a/accounting/models.py b/accounting/models.py index 7b590e77..616b5352 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -1,7 +1,10 @@ from django.core.urlresolvers import reverse +from django.core.exceptions import ValidationError +from django.db.models import Count from django.db import models from django.conf import settings from django.utils.translation import ugettext_lazy as _ +from django.template import defaultfilters from decimal import Decimal from core.models import User @@ -128,6 +131,7 @@ class Operation(models.Model): """ An operation is a line in the journal, a debit or a credit """ + number = models.IntegerField(_('number')) journal = models.ForeignKey(GeneralJournal, related_name="operations", null=False) amount = CurrencyField(_('amount')) date = models.DateField(_('date')) @@ -139,7 +143,19 @@ class Operation(models.Model): done = models.BooleanField(_('is done'), default=False) accounting_type = models.ForeignKey('AccountingType', related_name="operations") + class Meta: + unique_together = ('number', 'journal') + ordering = ['-number'] + + def clean(self): + super(Operation, self).clean() + if self.date < self.journal.start_date: + raise ValidationError(_("""The date can not be before the start date of the journal, which is +%(start_date)s.""") % {'start_date': defaultfilters.date(self.journal.start_date, settings.DATE_FORMAT)}) + def save(self): + if self.number is None: + self.number = self.journal.operations.count() + 1 super(Operation, self).save() self.journal.update_amounts() diff --git a/accounting/templates/accounting/club_account_details.jinja b/accounting/templates/accounting/club_account_details.jinja index c2bd5f13..4c0eff9b 100644 --- a/accounting/templates/accounting/club_account_details.jinja +++ b/accounting/templates/accounting/club_account_details.jinja @@ -17,6 +17,7 @@
{% trans %}You can not create new journal while you still have one opened{% endtrans %}
{% endif %}{% trans %}Name{% endtrans %} | {% trans %}Start{% endtrans %} | @@ -24,7 +25,10 @@{% trans %}Amount{% endtrans %} | {% trans %}Effective amount{% endtrans %} | {% trans %}Closed{% endtrans %} | +{% trans %}Actions{% endtrans %} |
{{ j.name }} | @@ -45,5 +49,6 @@ {% trans %}Edit{% endtrans %}
{% trans %}New operation{% endtrans %}
{% endif %}{% trans %}Nb{% endtrans %} | {% trans %}Date{% endtrans %} | @@ -28,9 +29,11 @@{% trans %}Comment{% endtrans %} | {% trans %}Actions{% endtrans %} | |
{{ o.id }} | +{{ o.number }} | {{ o.date }} | {{ o.label }} | {{ o.amount }} € | @@ -50,5 +53,6 @@