Commit 1457a7bf authored by Krophil's avatar Krophil Committed by Skia
Browse files

Bilan for accounting added

parent 96c6bf80
...@@ -21,13 +21,13 @@ ...@@ -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 %}
\ No newline at end of file
...@@ -455,13 +455,8 @@ class JournalBilanNatureView(CanViewMixin, DetailView): ...@@ -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): ...@@ -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): ...@@ -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
if op.exists(): from django.db.models import Sum, DecimalField
for o in op : bilan = {}
if o.accounting_type.code in bilan : bilan = collections.OrderedDict(bilan)
bilan[o.accounting_type.code]+=o.amount
else: for at in AccountingType.objects.order_by('code').all():
bilan[o.accounting_type.code]=o.amount #bilan[at] = self.object.operations.filter(type__startswith=at.code)
sum_by_type = list((self.object.operations.filter(
if o.number == code : accounting_type__code__startswith=at.code).aggregate(Sum('amount'))).values())[0]
self.recursive_sum(o.accounting_type.code, bilan) if sum_by_type != 0:
else: bilan[at] = sum_by_type
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 """
......
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