Commit 28aa143f authored by Skia's avatar Skia

Improve Operation numbering in accounting

parent 150147c6
Pipeline #60 failed with stage
in 1 minute and 18 seconds
# -*- 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')]),
),
]
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()
......
......@@ -17,6 +17,7 @@
<p>{% trans %}You can not create new journal while you still have one opened{% endtrans %}</p>
{% endif %}
<table>
<thead>
<tr>
<td>{% trans %}Name{% endtrans %}</td>
<td>{% trans %}Start{% endtrans %}</td>
......@@ -24,7 +25,10 @@
<td>{% trans %}Amount{% endtrans %}</td>
<td>{% trans %}Effective amount{% endtrans %}</td>
<td>{% trans %}Closed{% endtrans %}</td>
<td>{% trans %}Actions{% endtrans %}</td>
</tr>
</thead>
<tbody>
{% for j in object.journals.all() %}
<tr>
<td>{{ j.name }}</td>
......@@ -45,5 +49,6 @@
<a href="{{ url('accounting:journal_edit', j_id=j.id) }}">{% trans %}Edit{% endtrans %}</a> </td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
......@@ -15,6 +15,7 @@
<p><a href="{{ url('accounting:op_new') }}?parent={{ object.id }}">{% trans %}New operation{% endtrans %}</a></p>
{% endif %}
<table>
<thead>
<tr>
<td>{% trans %}Nb{% endtrans %}</td>
<td>{% trans %}Date{% endtrans %}</td>
......@@ -28,9 +29,11 @@
<td>{% trans %}Comment{% endtrans %}</td>
<td>{% trans %}Actions{% endtrans %}</td>
</tr>
</thead>
<tbody>
{% for o in object.operations.all() %}
<tr>
<td>{{ o.id }}</td>
<td>{{ o.number }}</td>
<td>{{ o.date }}</td>
<td>{{ o.label }}</td>
<td>{{ o.amount }}</td>
......@@ -50,5 +53,6 @@
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
......@@ -180,9 +180,3 @@ select[multiple]
vertical-align: top;
}
/* Tables
-----------------------------------------------*/
tbody>tr{
display: block;
margin: 3px;
}
......@@ -111,6 +111,24 @@ ul, ol {
display: inline-block;
margin: 4px;
}
table {
width: 100%;
}
td {
padding: 4px;
border: solid 1px black;
border-collapse: collapse;
}
thead {
font-weight: bold;
}
tbody>tr:nth-child(even) {
background: lightgrey;
}
tbody>tr:hover {
background: yellow;
width: 100%;
}
/*-----------------------------USER PROFILE----------------------------*/
.user_profile {
......
......@@ -65,7 +65,7 @@ class Product(models.Model):
icon = models.ImageField(upload_to='products', null=True, blank=True)
club = models.ForeignKey(Club, related_name="products")
def is_owned_by(self, user): # TODO do this for all models
def is_owned_by(self, user):
"""
Method to see if that object can be edited by the given user
"""
......
......@@ -144,9 +144,9 @@ DATABASES = {
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'fr-FR'
TIME_ZONE = 'UTC'
TIME_ZONE = 'Europe/Paris'
USE_I18N = True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment