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

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): ...@@ -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) if op.exists():
print(self.object.operations.filter( for o in op :
target_id=target_id).values('amount').annotate( if o.accounting_type.code in bilan :
sum = Sum('amount')).values('sum').first()['sum']) bilan[o.accounting_type.code]+=o.amount
return(self.object.operations.filter( else:
target_id=target_id).values('amount').annotate( bilan[o.accounting_type.code]=o.amount
sum = Sum('amount')).values('sum').first()['sum'])
if o.number == code :
def bilan_credit(self): 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 = {} bilan = {}
for el in Operation.objects.filter(accounting_type__movement_type='DEBIT'): self.recursive_sum('6', bilan)
bilan[el.target] = self.sum_by_code(el.target_id) print(bilan)
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
......
Supports Markdown
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