Commit d244618d authored by Skia's avatar Skia

Improve accounting views

parent d0654008
Pipeline #44 passed with stage
in 1 minute and 16 seconds
# -*- 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),
),
]
# -*- 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,
),
]
# -*- 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),
),
]
# -*- 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),
),
]
# -*- 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),
),
]
......@@ -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,29 +126,19 @@ class GeneralJournal(models.Model):
def __str__(self):
return self.name
class AccountingType(models.Model):
"""
Class describing the accounting types.
Thoses are numbers used in accounting to classify operations
"""
code = models.CharField(_('code'), max_length=16) # TODO: add number validator
label = models.CharField(_('label'), max_length=60)
movement_type = models.CharField(_('movement type'), choices=[('credit', 'Credit'), ('debit', 'Debit'), ('neutral', 'Neutral')], max_length=12)
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
return False
def get_absolute_url(self):
return reverse('accounting:type_list')
def __str__(self):
return self.movement_type+" - "+self.code+" - "+self.label
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):
"""
......@@ -156,12 +147,21 @@ class Operation(models.Model):
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'))
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)
type = models.ForeignKey(AccountingType, related_name="operations")
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):
"""
......@@ -182,10 +182,35 @@ class Operation(models.Model):
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)
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.
Thoses are numbers used in accounting to classify operations
"""
code = models.CharField(_('code'), max_length=16) # TODO: add number validator
label = models.CharField(_('label'), max_length=60)
movement_type = models.CharField(_('movement type'), choices=[('credit', 'Credit'), ('debit', 'Debit'), ('neutral', 'Neutral')], max_length=12)
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
return False
def get_absolute_url(self):
return reverse('accounting:type_list')
def __str__(self):
return self.movement_type+" - "+self.code+" - "+self.label
{% extends "core/base.jinja" %}
{% block content %}
<p>
<a href="{{ url('accounting:bank_list') }}">Accounting</a> >
{{ object.name }}
</p>
<h2>View account</h2>
<ul>
{% for k,v in object.__dict__.items() %}
......
{% extends "core/base.jinja" %}
{% block content %}
<p>
<a href="{{ url('accounting:bank_list') }}">Accounting</a> >
<a href="{{ url('accounting:bank_details', b_account_id=object.bank_account.id) }}">{{object.bank_account }}</a> >
{{ object }}
<h2>View account: {{ object.name }}</h2>
<ul>
{% for k,v in object.__dict__.items() %}
......
{% extends "core/base.jinja" %}
{% block content %}
<h2>View journal: {{ object.name }}</h2>
<ul>
{% for k,v in object.__dict__.items() %}
<li>{{ k }} - {{ v }}</li>
{% endfor %}
</ul>
<p>
<a href="{{ url('accounting:bank_list') }}">Accounting</a> >
<a href="{{ url('accounting:bank_details', b_account_id=object.club_account.bank_account.id) }}">{{object.club_account.bank_account }}</a> >
<a href="{{ url('accounting:club_details', c_account_id=object.club_account.id) }}">{{ object.club_account }}</a> >
{{ object.name }}
</p>
<p><strong>Amount: </strong>{{ object.amount }} € - <strong>Effective amount: </strong>{{ object.effective_amount }}</p>
<p><a href="{{ url('accounting:op_new') }}">New operation</a></p>
<ul>
<table>
<tr>
<td>Nb</td>
<td>Date</td>
<td>Label</td>
<td>Amount</td>
<td>Payment mode</td>
<!-- <td>Target</td> -->
<td>Code</td>
<td>Nature</td>
<td>Done</td>
<td>Comment</td>
<td>Actions</td>
</tr>
{% for o in object.operations.all() %}
<li>
<a href="{{ url('accounting:op_edit', op_id=o.id) }}">{{ o }}</a>
</li>
<tr>
<td>{{ o.id }}</td>
<td>{{ o.date }}</td>
<td>{{ o.label }}</td>
<td>{{ o.amount }}</td>
<td>{{ o.mode }}</td>
<td>{{ o.accounting_type.code }}</td>
<td>{{ o.accounting_type.label }}</td>
{% if o.done %}
<td>Yes</td>
{% else %}
<td>No</td>
{% endif %}
<td>{{ o.remark }}</td>
<td><a href="{{ url('accounting:op_edit', op_id=o.id) }}">Edit</a></td>
</tr>
{% endfor %}
</ul>
</table>
{% endblock %}
......
......@@ -147,7 +147,7 @@ class OperationCreateView(CanEditMixin, CreateView):
Create an operation
"""
model = Operation
fields = ['amount', 'journal', 'date', 'cheque_number', 'type']
fields = ['type', 'amount', 'label', 'remark', 'journal', 'date', 'cheque_number', 'accounting_type', 'done']
template_name = 'accounting/account_edit.jinja'
class OperationEditView(CanViewMixin, UpdateView):
......@@ -156,6 +156,6 @@ class OperationEditView(CanViewMixin, UpdateView):
"""
model = Operation
pk_url_kwarg = "op_id"
fields = ['journal', 'date', 'cheque_number', 'type']
fields = ['amount', 'label', 'remark', 'date', 'cheque_number', 'accounting_type', 'done']
template_name = 'accounting/account_edit.jinja'
......@@ -132,7 +132,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
Club(name="Woenzel'UT", unix_name="woenzel",
address="Woenzel", parent=guyut).save()
Club(name="BdF", unix_name="bdf",
address="Guyéuéyuéyuyé").save()
address="6 Bd Anatole France").save()
Membership(user=skia, club=ae, role=3, description="").save()
troll = Club(name="Troll Penché", unix_name="troll",
address="Terre Du Milieu", parent=ae)
......@@ -166,6 +166,6 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
ba.save()
ca = ClubAccount(name="Troll Penché", bank_account=ba, club=troll)
ca.save()
AccountingType(code=666, label="Guy credit", movement_type='credit').save()
AccountingType(code=4000, label="Guy debit", movement_type='debit').save()
AccountingType(code=756, label="Someone gave us money", movement_type='credit').save()
AccountingType(code=8570, label="Had to pay for food", movement_type='debit').save()
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