mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +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"
|
||||
template_name='accounting/journal_bilan_accounting.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 recursive_sum(self, code, bilan):
|
||||
op = Operation.objects.filter(accounting_type__code__startswith=code)
|
||||
|
||||
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
|
||||
|
||||
bilan = {}
|
||||
for el in Operation.objects.filter(accounting_type__movement_type='CREDIT'):
|
||||
bilan[el.target] = self.sum_by_code(el.target_id)
|
||||
if o.number == code :
|
||||
self.recursive_sum(o.accounting_type.code, bilan)
|
||||
else:
|
||||
return bilan
|
||||
|
||||
def bilan_debit(self):
|
||||
|
||||
def bilan(self):
|
||||
bilan = {}
|
||||
for el in Operation.objects.filter(accounting_type__movement_type='DEBIT'):
|
||||
bilan[el.target] = self.sum_by_code(el.target_id)
|
||||
self.recursive_sum('6', bilan)
|
||||
print(bilan)
|
||||
return bilan
|
||||
|
||||
def total_credit(self):
|
||||
return sum(self.bilan_credit().values())
|
||||
return sum(self.bilan().values())
|
||||
|
||||
def total_debit(self):
|
||||
return sum(self.bilan_debit().values())
|
||||
return sum(self.bilan().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['bilan'] = self.bilan()
|
||||
kwargs['total_credit'] = self.total_credit()
|
||||
kwargs['total_debit'] = self.total_debit()
|
||||
return kwargs
|
||||
|
Loading…
Reference in New Issue
Block a user