mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Improve accounting ease of use
This commit is contained in:
parent
ace58f54b5
commit
1396f2ca84
18
accounting/migrations/0010_remove_operation_type.py
Normal file
18
accounting/migrations/0010_remove_operation_type.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('accounting', '0009_auto_20160622_1030'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='operation',
|
||||||
|
name='type',
|
||||||
|
),
|
||||||
|
]
|
@ -130,7 +130,7 @@ class GeneralJournal(models.Model):
|
|||||||
self.amount = 0
|
self.amount = 0
|
||||||
self.effective_amount = 0
|
self.effective_amount = 0
|
||||||
for o in self.operations.all():
|
for o in self.operations.all():
|
||||||
if o.type == "credit":
|
if o.accounting_type.movement_type == "credit":
|
||||||
if o.done:
|
if o.done:
|
||||||
self.effective_amount += o.amount
|
self.effective_amount += o.amount
|
||||||
self.amount += o.amount
|
self.amount += o.amount
|
||||||
@ -154,10 +154,6 @@ class Operation(models.Model):
|
|||||||
invoice = models.FileField(upload_to='invoices', null=True, blank=True)
|
invoice = models.FileField(upload_to='invoices', null=True, blank=True)
|
||||||
done = models.BooleanField(_('is done'), default=False)
|
done = models.BooleanField(_('is done'), default=False)
|
||||||
accounting_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):
|
def save(self):
|
||||||
super(Operation, self).save()
|
super(Operation, self).save()
|
||||||
@ -186,8 +182,8 @@ class Operation(models.Model):
|
|||||||
return reverse('accounting:journal_details', kwargs={'j_id': self.journal.id})
|
return reverse('accounting:journal_details', kwargs={'j_id': self.journal.id})
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%d | %s | %d € | %s | %s | %s" % (
|
return "%d | %d € | %s | %s | %s" % (
|
||||||
self.id, self.type, self.amount, self.date, self.accounting_type, self.done,
|
self.id, self.amount, self.date, self.accounting_type, self.done,
|
||||||
)
|
)
|
||||||
|
|
||||||
class AccountingType(models.Model):
|
class AccountingType(models.Model):
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
<li>{{ k }} - {{ v }}</li>
|
<li>{{ k }} - {{ v }}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
<p><a href="{{ url('accounting:club_new') }}">New club account</a></p>
|
<p><a href="{{ url('accounting:club_new') }}?parent={{ object.id }}">New club account</a></p>
|
||||||
<ul>
|
<ul>
|
||||||
{% for c in object.club_accounts.all() %}
|
{% for c in object.club_accounts.all() %}
|
||||||
<li><a href="{{ url('accounting:club_details', c_account_id=c.id) }}">{{ c }}</a> -
|
<li><a href="{{ url('accounting:club_details', c_account_id=c.id) }}">{{ c }}</a> -
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
<li>{{ k }} - {{ v }}</li>
|
<li>{{ k }} - {{ v }}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
<p><a href="{{ url('accounting:journal_new') }}">New journal</a></p>
|
<p><a href="{{ url('accounting:journal_new') }}?parent={{ object.id }}">New journal</a></p>
|
||||||
<ul>
|
<ul>
|
||||||
{% for j in object.journals.all() %}
|
{% for j in object.journals.all() %}
|
||||||
<li>
|
<li>
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
{{ object.name }}
|
{{ object.name }}
|
||||||
</p>
|
</p>
|
||||||
<p><strong>Amount: </strong>{{ object.amount }} € - <strong>Effective amount: </strong>{{ object.effective_amount }} €</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') }}?parent={{ object.id }}">New operation</a></p>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Nb</td>
|
<td>Nb</td>
|
||||||
|
@ -24,7 +24,7 @@ class AccountingTypeEditView(CanViewMixin, UpdateView):
|
|||||||
model = AccountingType
|
model = AccountingType
|
||||||
pk_url_kwarg = "type_id"
|
pk_url_kwarg = "type_id"
|
||||||
fields = ['code', 'label', 'movement_type']
|
fields = ['code', 'label', 'movement_type']
|
||||||
template_name = 'accounting/account_edit.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
|
|
||||||
class AccountingTypeCreateView(CanEditPropMixin, CreateView): # TODO: move to CanCreateMixin
|
class AccountingTypeCreateView(CanEditPropMixin, CreateView): # TODO: move to CanCreateMixin
|
||||||
"""
|
"""
|
||||||
@ -32,7 +32,7 @@ class AccountingTypeCreateView(CanEditPropMixin, CreateView): # TODO: move to Ca
|
|||||||
"""
|
"""
|
||||||
model = AccountingType
|
model = AccountingType
|
||||||
fields = ['code', 'label', 'movement_type']
|
fields = ['code', 'label', 'movement_type']
|
||||||
template_name = 'accounting/account_edit.jinja'
|
template_name = 'core/create.jinja'
|
||||||
|
|
||||||
# BankAccount views
|
# BankAccount views
|
||||||
|
|
||||||
@ -49,8 +49,8 @@ class BankAccountEditView(CanViewMixin, UpdateView):
|
|||||||
"""
|
"""
|
||||||
model = BankAccount
|
model = BankAccount
|
||||||
pk_url_kwarg = "b_account_id"
|
pk_url_kwarg = "b_account_id"
|
||||||
fields = ['name', 'rib', 'number']
|
fields = ['name', 'iban', 'number']
|
||||||
template_name = 'accounting/account_edit.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
|
|
||||||
class BankAccountDetailView(CanViewMixin, DetailView):
|
class BankAccountDetailView(CanViewMixin, DetailView):
|
||||||
"""
|
"""
|
||||||
@ -65,8 +65,8 @@ class BankAccountCreateView(CanEditPropMixin, CreateView): # TODO: move to CanCr
|
|||||||
Create a bank account (for the admins)
|
Create a bank account (for the admins)
|
||||||
"""
|
"""
|
||||||
model = BankAccount
|
model = BankAccount
|
||||||
fields = ['name', 'rib', 'number']
|
fields = ['name', 'iban', 'number']
|
||||||
template_name = 'accounting/account_edit.jinja'
|
template_name = 'core/create.jinja'
|
||||||
|
|
||||||
class BankAccountDeleteView(CanEditPropMixin, DeleteView): # TODO change Delete to Close
|
class BankAccountDeleteView(CanEditPropMixin, DeleteView): # TODO change Delete to Close
|
||||||
"""
|
"""
|
||||||
@ -86,7 +86,7 @@ class ClubAccountEditView(CanViewMixin, UpdateView):
|
|||||||
model = ClubAccount
|
model = ClubAccount
|
||||||
pk_url_kwarg = "c_account_id"
|
pk_url_kwarg = "c_account_id"
|
||||||
fields = ['name', 'club', 'bank_account']
|
fields = ['name', 'club', 'bank_account']
|
||||||
template_name = 'accounting/account_edit.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
|
|
||||||
class ClubAccountDetailView(CanViewMixin, DetailView):
|
class ClubAccountDetailView(CanViewMixin, DetailView):
|
||||||
"""
|
"""
|
||||||
@ -102,7 +102,15 @@ class ClubAccountCreateView(CanEditPropMixin, CreateView): # TODO: move to CanCr
|
|||||||
"""
|
"""
|
||||||
model = ClubAccount
|
model = ClubAccount
|
||||||
fields = ['name', 'club', 'bank_account']
|
fields = ['name', 'club', 'bank_account']
|
||||||
template_name = 'accounting/account_edit.jinja'
|
template_name = 'core/create.jinja'
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
ret = super(ClubAccountCreateView, self).get_initial()
|
||||||
|
if 'parent' in self.request.GET.keys():
|
||||||
|
obj = BankAccount.objects.filter(id=int(self.request.GET['parent'])).first()
|
||||||
|
if obj is not None:
|
||||||
|
ret['bank_account'] = obj.id
|
||||||
|
return ret
|
||||||
|
|
||||||
class ClubAccountDeleteView(CanEditPropMixin, DeleteView): # TODO change Delete to Close
|
class ClubAccountDeleteView(CanEditPropMixin, DeleteView): # TODO change Delete to Close
|
||||||
"""
|
"""
|
||||||
@ -120,8 +128,16 @@ class JournalCreateView(CanCreateMixin, CreateView):
|
|||||||
Create a general journal
|
Create a general journal
|
||||||
"""
|
"""
|
||||||
model = GeneralJournal
|
model = GeneralJournal
|
||||||
template_name = 'accounting/account_edit.jinja'
|
|
||||||
fields = ['name', 'start_date', 'club_account']
|
fields = ['name', 'start_date', 'club_account']
|
||||||
|
template_name = 'core/create.jinja'
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
ret = super(JournalCreateView, self).get_initial()
|
||||||
|
if 'parent' in self.request.GET.keys():
|
||||||
|
obj = ClubAccount.objects.filter(id=int(self.request.GET['parent'])).first()
|
||||||
|
if obj is not None:
|
||||||
|
ret['club_account'] = obj.id
|
||||||
|
return ret
|
||||||
|
|
||||||
class JournalDetailView(CanViewMixin, DetailView):
|
class JournalDetailView(CanViewMixin, DetailView):
|
||||||
"""
|
"""
|
||||||
@ -138,7 +154,7 @@ class JournalEditView(CanEditMixin, UpdateView):
|
|||||||
model = GeneralJournal
|
model = GeneralJournal
|
||||||
pk_url_kwarg = "j_id"
|
pk_url_kwarg = "j_id"
|
||||||
fields = ['name', 'start_date', 'club_account']
|
fields = ['name', 'start_date', 'club_account']
|
||||||
template_name = 'accounting/account_edit.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
|
|
||||||
# Operation views
|
# Operation views
|
||||||
|
|
||||||
@ -147,8 +163,19 @@ class OperationCreateView(CanEditMixin, CreateView): # TODO: move to CanCreateMi
|
|||||||
Create an operation
|
Create an operation
|
||||||
"""
|
"""
|
||||||
model = Operation
|
model = Operation
|
||||||
fields = ['type', 'amount', 'label', 'remark', 'journal', 'date', 'cheque_number', 'accounting_type', 'done']
|
# fields = ['type', 'amount', 'label', 'remark', 'journal', 'date', 'cheque_number', 'accounting_type', 'done']
|
||||||
template_name = 'accounting/account_edit.jinja'
|
form_class = modelform_factory(Operation,
|
||||||
|
fields=['amount', 'label', 'remark', 'journal', 'date', 'cheque_number', 'accounting_type', 'done'],
|
||||||
|
widgets={'journal': HiddenInput})
|
||||||
|
template_name = 'core/create.jinja'
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
ret = super(OperationCreateView, self).get_initial()
|
||||||
|
if 'parent' in self.request.GET.keys():
|
||||||
|
obj = GeneralJournal.objects.filter(id=int(self.request.GET['parent'])).first()
|
||||||
|
if obj is not None:
|
||||||
|
ret['journal'] = obj.id
|
||||||
|
return ret
|
||||||
|
|
||||||
class OperationEditView(CanViewMixin, UpdateView):
|
class OperationEditView(CanViewMixin, UpdateView):
|
||||||
"""
|
"""
|
||||||
@ -157,5 +184,5 @@ class OperationEditView(CanViewMixin, UpdateView):
|
|||||||
model = Operation
|
model = Operation
|
||||||
pk_url_kwarg = "op_id"
|
pk_url_kwarg = "op_id"
|
||||||
fields = ['amount', 'label', 'remark', 'date', 'cheque_number', 'accounting_type', 'done']
|
fields = ['amount', 'label', 'remark', 'date', 'cheque_number', 'accounting_type', 'done']
|
||||||
template_name = 'accounting/account_edit.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{% extends "core/base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>Edit account</h2>
|
<h2>Create</h2>
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_p() }}
|
{{ form.as_p() }}
|
||||||
@ -11,3 +11,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
13
core/templates/core/edit.jinja
Normal file
13
core/templates/core/edit.jinja
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{% extends "core/base.jinja" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>Edit {{ object }}</h2>
|
||||||
|
<form action="" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p() }}
|
||||||
|
<p><input type="submit" value="Save!" /></p>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user