mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
person bilan added and renamed classes
This commit is contained in:
parent
147287f9a9
commit
6bb1e0e418
@ -1,33 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}General journal:{% endtrans %} {{ object.name }}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<h2>{% trans %}Nature bilan: {% endtrans %} {{ object.name }}</h2>
|
||||
|
||||
<h3>{% trans %}Credit{% endtrans %}</h3>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Nature of operation{% endtrans %}</td>
|
||||
<td>{% trans %}Sum{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for key in bilan.keys() %}
|
||||
<tr>
|
||||
<td>{{object.operations.get(accounting_type__code=key).accounting_type.label}}</td>
|
||||
<td>{{bilan[key]}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
<h3>{% trans %}Debit{% endtrans %}</h3>
|
||||
|
||||
{% endblock %}
|
55
accounting/templates/accounting/journal_bilan_nature.jinja
Normal file
55
accounting/templates/accounting/journal_bilan_nature.jinja
Normal file
@ -0,0 +1,55 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}General journal:{% endtrans %} {{ object.name }}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<h2>{% trans %}Nature bilan: {% endtrans %} {{ object.name }}</h2>
|
||||
|
||||
<h3>{% trans %}Credit{% endtrans %}</h3>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Nature of operation{% endtrans %}</td>
|
||||
<td>{% trans %}Sum{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for key in bilan_credit.keys() %}
|
||||
<tr>
|
||||
<td>{{key}}</td>
|
||||
<td>{{bilan_credit[key]}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
<p>Total : {{total_credit}}</p>
|
||||
|
||||
<h3>{% trans %}Debit{% endtrans %}</h3>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Nature of operation{% endtrans %}</td>
|
||||
<td>{% trans %}Sum{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for key in bilan_debit.keys() %}
|
||||
<tr>
|
||||
<td>{{key}}</td>
|
||||
<td>{{bilan_debit[key]}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
<p>Total : {{total_debit}}</p>
|
||||
|
||||
{% endblock %}
|
63
accounting/templates/accounting/journal_bilan_person.jinja
Normal file
63
accounting/templates/accounting/journal_bilan_person.jinja
Normal file
@ -0,0 +1,63 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}General journal:{% endtrans %} {{ object.name }}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<h2>{% trans %}Person bilan: {% endtrans %} {{ object.name }}</h2>
|
||||
|
||||
<h3>{% trans %}Credit{% endtrans %}</h3>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Target of the operation{% endtrans %}</td>
|
||||
<td>{% trans %}Sum{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for key in bilan_credit.keys() %}
|
||||
<tr>
|
||||
{% if key.target_type == "OTHER" %}
|
||||
<td>{{ o.target_label }}</td>
|
||||
{% else %}
|
||||
<td><a href="{{ key.get_absolute_url() }}">{{ key.get_display_name() }}</a></td>
|
||||
{% endif %}
|
||||
<td>{{bilan_credit[key]}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
<p>Total : {{total_credit}}</p>
|
||||
|
||||
<h3>{% trans %}Debit{% endtrans %}</h3>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Target of the operation{% endtrans %}</td>
|
||||
<td>{% trans %}Sum{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for key in bilan_debit.keys() %}
|
||||
<tr>
|
||||
{% if key.target_type == "OTHER" %}
|
||||
<td>{{ o.target_label }}</td>
|
||||
{% else %}
|
||||
<td><a href="{{ key.get_absolute_url() }}">{{ key.get_display_name() }}</a></td>
|
||||
{% endif %}
|
||||
<td>{{bilan_debit[key]}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
<p>Total : {{total_debit}}</p>
|
||||
|
||||
{% endblock %}
|
@ -22,7 +22,9 @@
|
||||
<p>{% trans %}Journal is closed, you can not create operation{% endtrans %}</p>
|
||||
{% else %}
|
||||
<p><a href="{{ url('accounting:op_new', j_id=object.id) }}">{% trans %}New operation{% endtrans %}</a></p>
|
||||
<p><a href="{{ url('accounting:journal_bilan', j_id=object.id) }}">{% trans %}Journal Bilan{% endtrans %}</a></p>
|
||||
<p><a href="{{ url('accounting:journal_bilan_nature', j_id=object.id) }}">{% trans %}Journal Bilan Nature{% endtrans %}</a></p>
|
||||
<p><a href="{{ url('accounting:journal_bilan_person', j_id=object.id) }}">{% trans %}Journal Bilan Person{% endtrans %}</a></p>
|
||||
<p><a href="{{ url('accounting:journal_bilan_accounting', j_id=object.id) }}">{% trans %}Journal Bilan Accounting{% endtrans %}</a></p>
|
||||
{% endif %}
|
||||
<table>
|
||||
<thead>
|
||||
|
@ -26,7 +26,10 @@ urlpatterns = [
|
||||
url(r'^journal/create$', JournalCreateView.as_view(), name='journal_new'),
|
||||
url(r'^journal/(?P<j_id>[0-9]+)$', JournalDetailView.as_view(), name='journal_details'),
|
||||
url(r'^journal/(?P<j_id>[0-9]+)/edit$', JournalEditView.as_view(), name='journal_edit'),
|
||||
url(r'^journal/(?P<j_id>[0-9]+)/bilan$', JournalBilanView.as_view(), name='journal_bilan'),
|
||||
url(r'^journal/(?P<j_id>[0-9]+)/bilan/nature$', JournalBilanNatureView.as_view(), name='journal_bilan_nature'),
|
||||
url(r'^journal/(?P<j_id>[0-9]+)/bilan/person$', JournalBilanPersonView.as_view(), name='journal_bilan_person'),
|
||||
url(r'^journal/(?P<j_id>[0-9]+)/bilan/accounting$', JournalBilanAccountingView.as_view(), name='journal_bilan_accounting'),
|
||||
|
||||
# Operations
|
||||
url(r'^operation/create/(?P<j_id>[0-9]+)$', OperationCreateView.as_view(), name='op_new'),
|
||||
url(r'^operation/(?P<op_id>[0-9]+)$', OperationEditView.as_view(), name='op_edit'),
|
||||
|
@ -444,34 +444,145 @@ class OperationPDFView(CanViewMixin, DetailView):
|
||||
p.save()
|
||||
return response
|
||||
|
||||
class JournalBilanView(CanViewMixin, DetailView):
|
||||
class JournalBilanNatureView(CanViewMixin, DetailView):
|
||||
"""
|
||||
Calculate a dictionary with operation code and sum of operations
|
||||
"""
|
||||
model = GeneralJournal
|
||||
pk_url_kwarg = "j_id"
|
||||
template_name='accounting/journal_bilan.jinja'
|
||||
template_name='accounting/journal_bilan_nature.jinja'
|
||||
|
||||
def sum_by_code(self, code):
|
||||
from decimal import Decimal
|
||||
from django.db.models import Sum, DecimalField
|
||||
amount_sum = Decimal(0)
|
||||
for amount in self.get_object().operations.filter(accounting_type__code=code).values('amount'):
|
||||
amount_sum += amount['amount']
|
||||
return amount_sum
|
||||
print(self.object.operations.filter(
|
||||
accounting_type__code=code).values('amount').annotate(
|
||||
sum = Sum('amount')).values('sum').first()['sum'])
|
||||
return(self.object.operations.filter(
|
||||
accounting_type__code=code).values('amount').annotate(
|
||||
sum = Sum('amount')).values('sum').first()['sum'])
|
||||
|
||||
def bilan(self):
|
||||
def bilan_credit(self):
|
||||
bilan = {}
|
||||
for el in AccountingType.objects.values('code').distinct():
|
||||
bilan[el['code']] = self.sum_by_code(el['code'])
|
||||
print(bilan)
|
||||
for el in AccountingType.objects.filter(movement_type='CREDIT'):
|
||||
bilan["%s - %s" % (el.code, el.label)] = self.sum_by_code(el.code)
|
||||
return bilan
|
||||
|
||||
def bilan_debit(self):
|
||||
bilan = {}
|
||||
for el in AccountingType.objects.filter(movement_type='DEBIT'):
|
||||
bilan["%s - %s" % (el.code, el.label)] = self.sum_by_code(el.code)
|
||||
return bilan
|
||||
|
||||
def total_credit(self):
|
||||
return sum(self.bilan_credit().values())
|
||||
|
||||
def total_debit(self):
|
||||
return sum(self.bilan_debit().values())
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
""" Add journal to the context """
|
||||
kwargs = super(JournalBilanView, self).get_context_data(**kwargs)
|
||||
kwargs['bilan'] = self.bilan()
|
||||
kwargs = super(JournalBilanNatureView, self).get_context_data(**kwargs)
|
||||
kwargs['bilan_credit'] = self.bilan_credit()
|
||||
kwargs['bilan_debit'] = self.bilan_debit()
|
||||
kwargs['total_credit'] = self.total_credit()
|
||||
kwargs['total_debit'] = self.total_debit()
|
||||
return kwargs
|
||||
|
||||
class JournalBilanPersonView(CanViewMixin, DetailView):
|
||||
"""
|
||||
Calculate a dictionary with operation target and sum of operations
|
||||
"""
|
||||
model = GeneralJournal
|
||||
pk_url_kwarg = "j_id"
|
||||
template_name='accounting/journal_bilan_person.jinja'
|
||||
|
||||
def sum_by_target(self, target_id):
|
||||
from decimal import Decimal
|
||||
from django.db.models import Sum, DecimalField
|
||||
amount_sum = Decimal(0)
|
||||
print(self.object.operations.filter(
|
||||
target_id=target_id).values('amount').annotate(
|
||||
sum = Sum('amount')).values('sum').first()['sum'])
|
||||
return(self.object.operations.filter(
|
||||
target_id=target_id).values('amount').annotate(
|
||||
sum = Sum('amount')).values('sum').first()['sum'])
|
||||
|
||||
def bilan_credit(self):
|
||||
|
||||
bilan = {}
|
||||
for el in Operation.objects.filter(accounting_type__movement_type='CREDIT'):
|
||||
bilan[el.target] = self.sum_by_target(el.target_id)
|
||||
return bilan
|
||||
|
||||
def bilan_debit(self):
|
||||
bilan = {}
|
||||
for el in Operation.objects.filter(accounting_type__movement_type='DEBIT'):
|
||||
bilan[el.target] = self.sum_by_target(el.target_id)
|
||||
return bilan
|
||||
|
||||
def total_credit(self):
|
||||
return sum(self.bilan_credit().values())
|
||||
|
||||
def total_debit(self):
|
||||
return sum(self.bilan_debit().values())
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
""" Add journal to the context """
|
||||
kwargs = super(JournalBilanPersonView, self).get_context_data(**kwargs)
|
||||
kwargs['bilan_credit'] = self.bilan_credit()
|
||||
kwargs['bilan_debit'] = self.bilan_debit()
|
||||
kwargs['total_credit'] = self.total_credit()
|
||||
kwargs['total_debit'] = self.total_debit()
|
||||
return kwargs
|
||||
|
||||
class JournalBilanAccountingView(CanViewMixin, DetailView):
|
||||
"""
|
||||
Calculate a dictionary with operation type and sum of operations
|
||||
"""
|
||||
model = GeneralJournal
|
||||
pk_url_kwarg = "j_id"
|
||||
template_name='accounting/journal_bilan_person.jinja'
|
||||
|
||||
def sum_by_code(self, target_id):
|
||||
from decimal import Decimal
|
||||
from django.db.models import Sum, DecimalField
|
||||
amount_sum = Decimal(0)
|
||||
print(self.object.operations.filter(
|
||||
target_id=target_id).values('amount').annotate(
|
||||
sum = Sum('amount')).values('sum').first()['sum'])
|
||||
return(self.object.operations.filter(
|
||||
target_id=target_id).values('amount').annotate(
|
||||
sum = Sum('amount')).values('sum').first()['sum'])
|
||||
|
||||
def bilan_credit(self):
|
||||
|
||||
bilan = {}
|
||||
for el in Operation.objects.filter(accounting_type__movement_type='CREDIT'):
|
||||
bilan[el.target] = self.sum_by_code(el.target_id)
|
||||
return bilan
|
||||
|
||||
def bilan_debit(self):
|
||||
bilan = {}
|
||||
for el in Operation.objects.filter(accounting_type__movement_type='DEBIT'):
|
||||
bilan[el.target] = self.sum_by_code(el.target_id)
|
||||
return bilan
|
||||
|
||||
def total_credit(self):
|
||||
return sum(self.bilan_credit().values())
|
||||
|
||||
def total_debit(self):
|
||||
return sum(self.bilan_debit().values())
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
""" Add journal to the context """
|
||||
kwargs = super(JournalBilanAccountingView, self).get_context_data(**kwargs)
|
||||
kwargs['bilan_credit'] = self.bilan_credit()
|
||||
kwargs['bilan_debit'] = self.bilan_debit()
|
||||
kwargs['total_credit'] = self.total_credit()
|
||||
kwargs['total_debit'] = self.total_debit()
|
||||
return kwargs
|
||||
|
||||
# Company views
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user