Bilan for accounting added

This commit is contained in:
Pierre Brunet 2016-12-21 00:43:54 +01:00 committed by Skia
parent 96c6bf8067
commit 1457a7bf74
2 changed files with 22 additions and 34 deletions

View File

@ -21,13 +21,13 @@
{% for key in bilan.keys() %} {% for key in bilan.keys() %}
<tr> <tr>
<td>{{ key }}</td> <td>{{ key }}</td>
<td>{{bilan[key]}}</td> <td>{{ bilan[key] }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<p>Total : {{total_credit}}</p> <p>Total : {{ total_credit }}</p>
{% endblock %} {% endblock %}

View File

@ -455,13 +455,8 @@ class JournalBilanNatureView(CanViewMixin, DetailView):
def sum_by_code(self, code): def sum_by_code(self, code):
from decimal import Decimal from decimal import Decimal
from django.db.models import Sum, DecimalField from django.db.models import Sum, DecimalField
amount_sum = Decimal(0) return(list((self.object.operations.filter(
print(self.object.operations.filter( accounting_type__code=code).aggregate(Sum('amount'))).values())[0])
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_credit(self): def bilan_credit(self):
bilan = {} bilan = {}
@ -501,13 +496,8 @@ class JournalBilanPersonView(CanViewMixin, DetailView):
def sum_by_target(self, target_id): def sum_by_target(self, target_id):
from decimal import Decimal from decimal import Decimal
from django.db.models import Sum, DecimalField from django.db.models import Sum, DecimalField
amount_sum = Decimal(0) return(list((self.object.operations.filter(
print(self.object.operations.filter( target_id=target_id).aggregate(Sum('amount'))).values())[0])
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 bilan_credit(self):
@ -545,33 +535,31 @@ 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 recursive_sum(self, code, bilan): def recursive_sum(self, max_length):
op = Operation.objects.filter(accounting_type__code__startswith=code) import collections
from decimal import Decimal
from django.db.models import Sum, DecimalField
bilan = {}
bilan = collections.OrderedDict(bilan)
if op.exists(): for at in AccountingType.objects.order_by('code').all():
for o in op : #bilan[at] = self.object.operations.filter(type__startswith=at.code)
if o.accounting_type.code in bilan : sum_by_type = list((self.object.operations.filter(
bilan[o.accounting_type.code]+=o.amount accounting_type__code__startswith=at.code).aggregate(Sum('amount'))).values())[0]
else: if sum_by_type != 0:
bilan[o.accounting_type.code]=o.amount bilan[at] = sum_by_type
if o.number == code :
self.recursive_sum(o.accounting_type.code, bilan)
else:
return bilan return bilan
def bilan(self): def bilan(self):
bilan = {} bilan = self.recursive_sum(3)
self.recursive_sum('6', bilan)
print(bilan)
return bilan return bilan
def total_credit(self): def total_credit(self):
return sum(self.bilan().values()) return self.bilan().get('6')#sum(self.bilan().values())
def total_debit(self): def total_debit(self):
return sum(self.bilan().values()) return self.bilan().get('6')#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 """