Commit 96c6bf80 authored by Krophil's avatar Krophil Committed by Skia

bilan added

parent 5cd64fb3
{% 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 %}
\ No newline at end of file
......@@ -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 bilan_credit(self):
def recursive_sum(self, code, bilan):
op = Operation.objects.filter(accounting_type__code__startswith=code)
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
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):
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment