mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-26 02:54:20 +00:00
bilan added
This commit is contained in:
parent
5cd64fb384
commit
96c6bf8067
@ -0,0 +1,33 @@
|
|||||||
|
{% extends "core/base.jinja" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
{% trans %}General journal:{% endtrans %} {{ object.name }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>{% trans %}Accounting bilan: {% endtrans %} {{ object.name }}</h2>
|
||||||
|
|
||||||
|
<h3>{% trans %}Credit{% endtrans %}</h3>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<td>{% trans %}Type of operations{% endtrans %}</td>
|
||||||
|
<td>{% trans %}Sum{% endtrans %}</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for key in bilan.keys() %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ key }}</td>
|
||||||
|
<td>{{bilan[key]}}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p>Total : {{total_credit}}</p>
|
||||||
|
|
||||||
|
{% endblock %}
|
@ -545,41 +545,38 @@ class JournalBilanAccountingView(CanViewMixin, DetailView):
|
|||||||
pk_url_kwarg = "j_id"
|
pk_url_kwarg = "j_id"
|
||||||
template_name='accounting/journal_bilan_accounting.jinja'
|
template_name='accounting/journal_bilan_accounting.jinja'
|
||||||
|
|
||||||
def sum_by_code(self, target_id):
|
def recursive_sum(self, code, bilan):
|
||||||
from decimal import Decimal
|
op = Operation.objects.filter(accounting_type__code__startswith=code)
|
||||||
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):
|
if op.exists():
|
||||||
|
for o in op :
|
||||||
|
if o.accounting_type.code in bilan :
|
||||||
|
bilan[o.accounting_type.code]+=o.amount
|
||||||
|
else:
|
||||||
|
bilan[o.accounting_type.code]=o.amount
|
||||||
|
|
||||||
|
if o.number == code :
|
||||||
|
self.recursive_sum(o.accounting_type.code, bilan)
|
||||||
|
else:
|
||||||
|
return bilan
|
||||||
|
|
||||||
|
|
||||||
|
def bilan(self):
|
||||||
bilan = {}
|
bilan = {}
|
||||||
for el in Operation.objects.filter(accounting_type__movement_type='CREDIT'):
|
self.recursive_sum('6', bilan)
|
||||||
bilan[el.target] = self.sum_by_code(el.target_id)
|
print(bilan)
|
||||||
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
|
return bilan
|
||||||
|
|
||||||
def total_credit(self):
|
def total_credit(self):
|
||||||
return sum(self.bilan_credit().values())
|
return sum(self.bilan().values())
|
||||||
|
|
||||||
def total_debit(self):
|
def total_debit(self):
|
||||||
return sum(self.bilan_debit().values())
|
return sum(self.bilan().values())
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
""" Add journal to the context """
|
""" Add journal to the context """
|
||||||
kwargs = super(JournalBilanAccountingView, self).get_context_data(**kwargs)
|
kwargs = super(JournalBilanAccountingView, self).get_context_data(**kwargs)
|
||||||
kwargs['bilan_credit'] = self.bilan_credit()
|
kwargs['bilan'] = self.bilan()
|
||||||
kwargs['bilan_debit'] = self.bilan_debit()
|
|
||||||
kwargs['total_credit'] = self.total_credit()
|
kwargs['total_credit'] = self.total_credit()
|
||||||
kwargs['total_debit'] = self.total_debit()
|
kwargs['total_debit'] = self.total_debit()
|
||||||
return kwargs
|
return kwargs
|
||||||
|
Loading…
Reference in New Issue
Block a user