Improve accounting views

This commit is contained in:
Skia 2016-06-22 13:19:35 +02:00
parent d06540086d
commit d244618dd0
11 changed files with 224 additions and 56 deletions

View File

@ -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),
),
]

View File

@ -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,
),
]

View File

@ -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),
),
]

View File

@ -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),
),
]

View File

@ -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),
),
]

View File

@ -86,6 +86,7 @@ class GeneralJournal(models.Model):
closed = models.BooleanField(_('is closed'), default=False) closed = models.BooleanField(_('is closed'), default=False)
club_account = models.ForeignKey(ClubAccount, related_name="journals", null=False) club_account = models.ForeignKey(ClubAccount, related_name="journals", null=False)
amount = CurrencyField(_('amount'), default=0) amount = CurrencyField(_('amount'), default=0)
effective_amount = CurrencyField(_('effective_amount'), default=0)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(GeneralJournal, self).__init__(*args, **kwargs) super(GeneralJournal, self).__init__(*args, **kwargs)
@ -125,6 +126,70 @@ class GeneralJournal(models.Model):
def __str__(self): def __str__(self):
return self.name 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 AccountingType(models.Model):
""" """
Class describing the accounting types. Class describing the accounting types.
@ -149,43 +214,3 @@ class AccountingType(models.Model):
def __str__(self): def __str__(self):
return self.movement_type+" - "+self.code+" - "+self.label 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)

View File

@ -1,6 +1,10 @@
{% extends "core/base.jinja" %} {% extends "core/base.jinja" %}
{% block content %} {% block content %}
<p>
<a href="{{ url('accounting:bank_list') }}">Accounting</a> >
{{ object.name }}
</p>
<h2>View account</h2> <h2>View account</h2>
<ul> <ul>
{% for k,v in object.__dict__.items() %} {% for k,v in object.__dict__.items() %}

View File

@ -1,6 +1,10 @@
{% extends "core/base.jinja" %} {% extends "core/base.jinja" %}
{% block content %} {% 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> <h2>View account: {{ object.name }}</h2>
<ul> <ul>
{% for k,v in object.__dict__.items() %} {% for k,v in object.__dict__.items() %}

View File

@ -1,20 +1,47 @@
{% extends "core/base.jinja" %} {% extends "core/base.jinja" %}
{% block content %} {% block content %}
<h2>View journal: {{ object.name }}</h2> <p>
<ul> <a href="{{ url('accounting:bank_list') }}">Accounting</a> >
{% for k,v in object.__dict__.items() %} <a href="{{ url('accounting:bank_details', b_account_id=object.club_account.bank_account.id) }}">{{object.club_account.bank_account }}</a> >
<li>{{ k }} - {{ v }}</li> <a href="{{ url('accounting:club_details', c_account_id=object.club_account.id) }}">{{ object.club_account }}</a> >
{% endfor %} {{ object.name }}
</ul> </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> <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() %} {% for o in object.operations.all() %}
<li> <tr>
<a href="{{ url('accounting:op_edit', op_id=o.id) }}">{{ o }}</a> <td>{{ o.id }}</td>
</li> <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 %} {% endfor %}
</ul> </table>
{% endblock %} {% endblock %}

View File

@ -147,7 +147,7 @@ class OperationCreateView(CanEditMixin, CreateView):
Create an operation Create an operation
""" """
model = 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' template_name = 'accounting/account_edit.jinja'
class OperationEditView(CanViewMixin, UpdateView): class OperationEditView(CanViewMixin, UpdateView):
@ -156,6 +156,6 @@ class OperationEditView(CanViewMixin, UpdateView):
""" """
model = Operation model = Operation
pk_url_kwarg = "op_id" 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' template_name = 'accounting/account_edit.jinja'

View File

@ -132,7 +132,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
Club(name="Woenzel'UT", unix_name="woenzel", Club(name="Woenzel'UT", unix_name="woenzel",
address="Woenzel", parent=guyut).save() address="Woenzel", parent=guyut).save()
Club(name="BdF", unix_name="bdf", 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() Membership(user=skia, club=ae, role=3, description="").save()
troll = Club(name="Troll Penché", unix_name="troll", troll = Club(name="Troll Penché", unix_name="troll",
address="Terre Du Milieu", parent=ae) address="Terre Du Milieu", parent=ae)
@ -166,6 +166,6 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
ba.save() ba.save()
ca = ClubAccount(name="Troll Penché", bank_account=ba, club=troll) ca = ClubAccount(name="Troll Penché", bank_account=ba, club=troll)
ca.save() ca.save()
AccountingType(code=666, label="Guy credit", movement_type='credit').save() AccountingType(code=756, label="Someone gave us money", movement_type='credit').save()
AccountingType(code=4000, label="Guy debit", movement_type='debit').save() AccountingType(code=8570, label="Had to pay for food", movement_type='debit').save()