From bfa09c0bcd5af626cb45a89d5f5d36d6c94dac81 Mon Sep 17 00:00:00 2001 From: Krophil Date: Tue, 22 Nov 2016 18:25:29 +0100 Subject: [PATCH 01/13] template added for bilan --- .../templates/accounting/journal_bilan.jinja | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 accounting/templates/accounting/journal_bilan.jinja diff --git a/accounting/templates/accounting/journal_bilan.jinja b/accounting/templates/accounting/journal_bilan.jinja new file mode 100644 index 00000000..41da8041 --- /dev/null +++ b/accounting/templates/accounting/journal_bilan.jinja @@ -0,0 +1,30 @@ +{% extends "core/base.jinja" %} + +{% block title %} +{% trans %}General journal:{% endtrans %} {{ object.name }} +{% endblock %} + + +{% block content %} +

{% trans %}Nature bilan: {% endtrans %} {{ object.name }}

+ +

{% trans %}Credit{% endtrans %}

+ + + + + + + + + + + + + + +
{% trans %}Nature of operation{% endtrans %}{% trans %}Amount{% endtrans %}
bla{{self.get_test()}}
+ +

{% trans %}Debit{% endtrans %}

+ +{% endblock %} \ No newline at end of file From 147287f9a9c7145b0c96adea37f40c8ada75e431 Mon Sep 17 00:00:00 2001 From: Krophil Date: Wed, 14 Dec 2016 01:04:38 +0100 Subject: [PATCH 02/13] Now, I understand how ORM works... or not --- .../templates/accounting/journal_bilan.jinja | 13 +++++---- .../accounting/journal_details.jinja | 1 + accounting/urls.py | 1 + accounting/views.py | 29 +++++++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/accounting/templates/accounting/journal_bilan.jinja b/accounting/templates/accounting/journal_bilan.jinja index 41da8041..7e3dc461 100644 --- a/accounting/templates/accounting/journal_bilan.jinja +++ b/accounting/templates/accounting/journal_bilan.jinja @@ -14,13 +14,16 @@ {% trans %}Nature of operation{% endtrans %} - {% trans %}Amount{% endtrans %} + {% trans %}Sum{% endtrans %} - - bla - {{self.get_test()}} - + + {% for key in bilan.keys() %} + + {{object.operations.get(accounting_type__code=key).accounting_type.label}} + {{bilan[key]}} + + {% endfor %} diff --git a/accounting/templates/accounting/journal_details.jinja b/accounting/templates/accounting/journal_details.jinja index 37b0741f..4e22eb1a 100644 --- a/accounting/templates/accounting/journal_details.jinja +++ b/accounting/templates/accounting/journal_details.jinja @@ -22,6 +22,7 @@

{% trans %}Journal is closed, you can not create operation{% endtrans %}

{% else %}

{% trans %}New operation{% endtrans %}

+

{% trans %}Journal Bilan{% endtrans %}

{% endif %} diff --git a/accounting/urls.py b/accounting/urls.py index d0d4e76a..02033b2e 100644 --- a/accounting/urls.py +++ b/accounting/urls.py @@ -26,6 +26,7 @@ urlpatterns = [ url(r'^journal/create$', JournalCreateView.as_view(), name='journal_new'), url(r'^journal/(?P[0-9]+)$', JournalDetailView.as_view(), name='journal_details'), url(r'^journal/(?P[0-9]+)/edit$', JournalEditView.as_view(), name='journal_edit'), + url(r'^journal/(?P[0-9]+)/bilan$', JournalBilanView.as_view(), name='journal_bilan'), # Operations url(r'^operation/create/(?P[0-9]+)$', OperationCreateView.as_view(), name='op_new'), url(r'^operation/(?P[0-9]+)$', OperationEditView.as_view(), name='op_edit'), diff --git a/accounting/views.py b/accounting/views.py index fb390585..83b3fbcf 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -444,6 +444,35 @@ class OperationPDFView(CanViewMixin, DetailView): p.save() return response +class JournalBilanView(CanViewMixin, DetailView): + """ + Calculate a dictionary with operation code and sum of operations + """ + model = GeneralJournal + pk_url_kwarg = "j_id" + template_name='accounting/journal_bilan.jinja' + + def sum_by_code(self, code): + from decimal import Decimal + amount_sum = Decimal(0) + for amount in self.get_object().operations.filter(accounting_type__code=code).values('amount'): + amount_sum += amount['amount'] + return amount_sum + + def bilan(self): + bilan = {} + for el in AccountingType.objects.values('code').distinct(): + bilan[el['code']] = self.sum_by_code(el['code']) + print(bilan) + return bilan + + def get_context_data(self, **kwargs): + """ Add journal to the context """ + kwargs = super(JournalBilanView, self).get_context_data(**kwargs) + kwargs['bilan'] = self.bilan() + return kwargs + + # Company views class CompanyListView(CanViewMixin, ListView): From 6bb1e0e41807d63f4de01d2e3ec56c5eec1fcd76 Mon Sep 17 00:00:00 2001 From: Krophil Date: Wed, 14 Dec 2016 18:04:57 +0100 Subject: [PATCH 03/13] person bilan added and renamed classes --- .../templates/accounting/journal_bilan.jinja | 33 ----- .../accounting/journal_bilan_nature.jinja | 55 ++++++++ .../accounting/journal_bilan_person.jinja | 63 +++++++++ .../accounting/journal_details.jinja | 4 +- accounting/urls.py | 5 +- accounting/views.py | 133 ++++++++++++++++-- 6 files changed, 247 insertions(+), 46 deletions(-) delete mode 100644 accounting/templates/accounting/journal_bilan.jinja create mode 100644 accounting/templates/accounting/journal_bilan_nature.jinja create mode 100644 accounting/templates/accounting/journal_bilan_person.jinja diff --git a/accounting/templates/accounting/journal_bilan.jinja b/accounting/templates/accounting/journal_bilan.jinja deleted file mode 100644 index 7e3dc461..00000000 --- a/accounting/templates/accounting/journal_bilan.jinja +++ /dev/null @@ -1,33 +0,0 @@ -{% extends "core/base.jinja" %} - -{% block title %} -{% trans %}General journal:{% endtrans %} {{ object.name }} -{% endblock %} - - -{% block content %} -

{% trans %}Nature bilan: {% endtrans %} {{ object.name }}

- -

{% trans %}Credit{% endtrans %}

- -
- - - - - - - - {% for key in bilan.keys() %} - - - - - {% endfor %} - - -
{% trans %}Nature of operation{% endtrans %}{% trans %}Sum{% endtrans %}
{{object.operations.get(accounting_type__code=key).accounting_type.label}}{{bilan[key]}}
- -

{% trans %}Debit{% endtrans %}

- -{% endblock %} \ No newline at end of file diff --git a/accounting/templates/accounting/journal_bilan_nature.jinja b/accounting/templates/accounting/journal_bilan_nature.jinja new file mode 100644 index 00000000..d8de0864 --- /dev/null +++ b/accounting/templates/accounting/journal_bilan_nature.jinja @@ -0,0 +1,55 @@ +{% extends "core/base.jinja" %} + +{% block title %} +{% trans %}General journal:{% endtrans %} {{ object.name }} +{% endblock %} + + +{% block content %} +

{% trans %}Nature bilan: {% endtrans %} {{ object.name }}

+ +

{% trans %}Credit{% endtrans %}

+ + + + + + + + + + {% for key in bilan_credit.keys() %} + + + + + {% endfor %} + + +
{% trans %}Nature of operation{% endtrans %}{% trans %}Sum{% endtrans %}
{{key}}{{bilan_credit[key]}}
+ +

Total : {{total_credit}}

+ +

{% trans %}Debit{% endtrans %}

+ + + + + + + + + + {% for key in bilan_debit.keys() %} + + + + + {% endfor %} + + +
{% trans %}Nature of operation{% endtrans %}{% trans %}Sum{% endtrans %}
{{key}}{{bilan_debit[key]}}
+ +

Total : {{total_debit}}

+ +{% endblock %} \ No newline at end of file diff --git a/accounting/templates/accounting/journal_bilan_person.jinja b/accounting/templates/accounting/journal_bilan_person.jinja new file mode 100644 index 00000000..8b913123 --- /dev/null +++ b/accounting/templates/accounting/journal_bilan_person.jinja @@ -0,0 +1,63 @@ +{% extends "core/base.jinja" %} + +{% block title %} +{% trans %}General journal:{% endtrans %} {{ object.name }} +{% endblock %} + + +{% block content %} +

{% trans %}Person bilan: {% endtrans %} {{ object.name }}

+ +

{% trans %}Credit{% endtrans %}

+ + + + + + + + + + {% for key in bilan_credit.keys() %} + + {% if key.target_type == "OTHER" %} + + {% else %} + + {% endif %} + + + {% endfor %} + + +
{% trans %}Target of the operation{% endtrans %}{% trans %}Sum{% endtrans %}
{{ o.target_label }}{{ key.get_display_name() }}{{bilan_credit[key]}}
+ +

Total : {{total_credit}}

+ +

{% trans %}Debit{% endtrans %}

+ + + + + + + + + + {% for key in bilan_debit.keys() %} + + {% if key.target_type == "OTHER" %} + + {% else %} + + {% endif %} + + + {% endfor %} + + +
{% trans %}Target of the operation{% endtrans %}{% trans %}Sum{% endtrans %}
{{ o.target_label }}{{ key.get_display_name() }}{{bilan_debit[key]}}
+ +

Total : {{total_debit}}

+ +{% endblock %} \ No newline at end of file diff --git a/accounting/templates/accounting/journal_details.jinja b/accounting/templates/accounting/journal_details.jinja index 4e22eb1a..7fa34111 100644 --- a/accounting/templates/accounting/journal_details.jinja +++ b/accounting/templates/accounting/journal_details.jinja @@ -22,7 +22,9 @@

{% trans %}Journal is closed, you can not create operation{% endtrans %}

{% else %}

{% trans %}New operation{% endtrans %}

-

{% trans %}Journal Bilan{% endtrans %}

+

{% trans %}Journal Bilan Nature{% endtrans %}

+

{% trans %}Journal Bilan Person{% endtrans %}

+

{% trans %}Journal Bilan Accounting{% endtrans %}

{% endif %} diff --git a/accounting/urls.py b/accounting/urls.py index 02033b2e..b91620a2 100644 --- a/accounting/urls.py +++ b/accounting/urls.py @@ -26,7 +26,10 @@ urlpatterns = [ url(r'^journal/create$', JournalCreateView.as_view(), name='journal_new'), url(r'^journal/(?P[0-9]+)$', JournalDetailView.as_view(), name='journal_details'), url(r'^journal/(?P[0-9]+)/edit$', JournalEditView.as_view(), name='journal_edit'), - url(r'^journal/(?P[0-9]+)/bilan$', JournalBilanView.as_view(), name='journal_bilan'), + url(r'^journal/(?P[0-9]+)/bilan/nature$', JournalBilanNatureView.as_view(), name='journal_bilan_nature'), + url(r'^journal/(?P[0-9]+)/bilan/person$', JournalBilanPersonView.as_view(), name='journal_bilan_person'), + url(r'^journal/(?P[0-9]+)/bilan/accounting$', JournalBilanAccountingView.as_view(), name='journal_bilan_accounting'), + # Operations url(r'^operation/create/(?P[0-9]+)$', OperationCreateView.as_view(), name='op_new'), url(r'^operation/(?P[0-9]+)$', OperationEditView.as_view(), name='op_edit'), diff --git a/accounting/views.py b/accounting/views.py index 83b3fbcf..f878a663 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -444,34 +444,145 @@ class OperationPDFView(CanViewMixin, DetailView): p.save() return response -class JournalBilanView(CanViewMixin, DetailView): +class JournalBilanNatureView(CanViewMixin, DetailView): """ Calculate a dictionary with operation code and sum of operations """ model = GeneralJournal pk_url_kwarg = "j_id" - template_name='accounting/journal_bilan.jinja' + template_name='accounting/journal_bilan_nature.jinja' def sum_by_code(self, code): from decimal import Decimal + from django.db.models import Sum, DecimalField amount_sum = Decimal(0) - for amount in self.get_object().operations.filter(accounting_type__code=code).values('amount'): - amount_sum += amount['amount'] - return amount_sum + print(self.object.operations.filter( + 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(self): + def bilan_credit(self): bilan = {} - for el in AccountingType.objects.values('code').distinct(): - bilan[el['code']] = self.sum_by_code(el['code']) - print(bilan) + for el in AccountingType.objects.filter(movement_type='CREDIT'): + bilan["%s - %s" % (el.code, el.label)] = self.sum_by_code(el.code) return bilan + def bilan_debit(self): + bilan = {} + for el in AccountingType.objects.filter(movement_type='DEBIT'): + bilan["%s - %s" % (el.code, el.label)] = self.sum_by_code(el.code) + return bilan + + def total_credit(self): + return sum(self.bilan_credit().values()) + + def total_debit(self): + return sum(self.bilan_debit().values()) + def get_context_data(self, **kwargs): """ Add journal to the context """ - kwargs = super(JournalBilanView, self).get_context_data(**kwargs) - kwargs['bilan'] = self.bilan() + kwargs = super(JournalBilanNatureView, self).get_context_data(**kwargs) + kwargs['bilan_credit'] = self.bilan_credit() + kwargs['bilan_debit'] = self.bilan_debit() + kwargs['total_credit'] = self.total_credit() + kwargs['total_debit'] = self.total_debit() return kwargs +class JournalBilanPersonView(CanViewMixin, DetailView): + """ + Calculate a dictionary with operation target and sum of operations + """ + model = GeneralJournal + pk_url_kwarg = "j_id" + template_name='accounting/journal_bilan_person.jinja' + + def sum_by_target(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): + + bilan = {} + for el in Operation.objects.filter(accounting_type__movement_type='CREDIT'): + bilan[el.target] = self.sum_by_target(el.target_id) + return bilan + + def bilan_debit(self): + bilan = {} + for el in Operation.objects.filter(accounting_type__movement_type='DEBIT'): + bilan[el.target] = self.sum_by_target(el.target_id) + return bilan + + def total_credit(self): + return sum(self.bilan_credit().values()) + + def total_debit(self): + return sum(self.bilan_debit().values()) + + def get_context_data(self, **kwargs): + """ Add journal to the context """ + kwargs = super(JournalBilanPersonView, self).get_context_data(**kwargs) + kwargs['bilan_credit'] = self.bilan_credit() + kwargs['bilan_debit'] = self.bilan_debit() + kwargs['total_credit'] = self.total_credit() + kwargs['total_debit'] = self.total_debit() + return kwargs + +class JournalBilanAccountingView(CanViewMixin, DetailView): + """ + Calculate a dictionary with operation type and sum of operations + """ + model = GeneralJournal + pk_url_kwarg = "j_id" + template_name='accounting/journal_bilan_person.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): + + 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): + bilan = {} + for el in Operation.objects.filter(accounting_type__movement_type='DEBIT'): + bilan[el.target] = self.sum_by_code(el.target_id) + return bilan + + def total_credit(self): + return sum(self.bilan_credit().values()) + + def total_debit(self): + return sum(self.bilan_debit().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['total_credit'] = self.total_credit() + kwargs['total_debit'] = self.total_debit() + return kwargs # Company views From 5cd64fb3848dd95b9928ff32c5f0f1f3cf4c706d Mon Sep 17 00:00:00 2001 From: Krophil Date: Thu, 15 Dec 2016 12:21:51 +0100 Subject: [PATCH 04/13] bilan in development --- accounting/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounting/views.py b/accounting/views.py index f878a663..998132d7 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -543,7 +543,7 @@ class JournalBilanAccountingView(CanViewMixin, DetailView): """ model = GeneralJournal pk_url_kwarg = "j_id" - template_name='accounting/journal_bilan_person.jinja' + template_name='accounting/journal_bilan_accounting.jinja' def sum_by_code(self, target_id): from decimal import Decimal From 96c6bf8067c24b5688c8bfc0e37d1144e94ac36a Mon Sep 17 00:00:00 2001 From: Krophil Date: Mon, 19 Dec 2016 03:55:21 +0100 Subject: [PATCH 05/13] bilan added --- .../accounting/journal_bilan_accounting.jinja | 33 ++++++++++++++ accounting/views.py | 43 +++++++++---------- 2 files changed, 53 insertions(+), 23 deletions(-) create mode 100644 accounting/templates/accounting/journal_bilan_accounting.jinja diff --git a/accounting/templates/accounting/journal_bilan_accounting.jinja b/accounting/templates/accounting/journal_bilan_accounting.jinja new file mode 100644 index 00000000..47ca5017 --- /dev/null +++ b/accounting/templates/accounting/journal_bilan_accounting.jinja @@ -0,0 +1,33 @@ +{% extends "core/base.jinja" %} + +{% block title %} +{% trans %}General journal:{% endtrans %} {{ object.name }} +{% endblock %} + + +{% block content %} +

{% trans %}Accounting bilan: {% endtrans %} {{ object.name }}

+ +

{% trans %}Credit{% endtrans %}

+ +
+ + + + + + + + {% for key in bilan.keys() %} + + + + + {% endfor %} + + +
{% trans %}Type of operations{% endtrans %}{% trans %}Sum{% endtrans %}
{{ key }}{{bilan[key]}}
+ +

Total : {{total_credit}}

+ +{% endblock %} \ No newline at end of file diff --git a/accounting/views.py b/accounting/views.py index 998132d7..2f9700f8 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -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 + + if o.number == code : + self.recursive_sum(o.accounting_type.code, bilan) + else: + return bilan + + def bilan(self): 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): - 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 From 1457a7bf74dda0253c237935f232fd35df23c3fe Mon Sep 17 00:00:00 2001 From: Krophil Date: Wed, 21 Dec 2016 00:43:54 +0100 Subject: [PATCH 06/13] Bilan for accounting added --- .../accounting/journal_bilan_accounting.jinja | 4 +- accounting/views.py | 52 +++++++------------ 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/accounting/templates/accounting/journal_bilan_accounting.jinja b/accounting/templates/accounting/journal_bilan_accounting.jinja index 47ca5017..6ceadda6 100644 --- a/accounting/templates/accounting/journal_bilan_accounting.jinja +++ b/accounting/templates/accounting/journal_bilan_accounting.jinja @@ -21,13 +21,13 @@ {% for key in bilan.keys() %} {{ key }} - {{bilan[key]}} + {{ bilan[key] }} {% endfor %} -

Total : {{total_credit}}

+

Total : {{ total_credit }}

{% endblock %} \ No newline at end of file diff --git a/accounting/views.py b/accounting/views.py index 2f9700f8..91434206 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -455,13 +455,8 @@ class JournalBilanNatureView(CanViewMixin, DetailView): def sum_by_code(self, code): from decimal import Decimal from django.db.models import Sum, DecimalField - amount_sum = Decimal(0) - print(self.object.operations.filter( - 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']) + return(list((self.object.operations.filter( + accounting_type__code=code).aggregate(Sum('amount'))).values())[0]) def bilan_credit(self): bilan = {} @@ -501,13 +496,8 @@ class JournalBilanPersonView(CanViewMixin, DetailView): def sum_by_target(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']) + return(list((self.object.operations.filter( + target_id=target_id).aggregate(Sum('amount'))).values())[0]) def bilan_credit(self): @@ -545,33 +535,31 @@ class JournalBilanAccountingView(CanViewMixin, DetailView): pk_url_kwarg = "j_id" template_name='accounting/journal_bilan_accounting.jinja' - def recursive_sum(self, code, bilan): - op = Operation.objects.filter(accounting_type__code__startswith=code) + def recursive_sum(self, max_length): + import collections + from decimal import Decimal + from django.db.models import Sum, DecimalField + bilan = {} + bilan = collections.OrderedDict(bilan) - 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 + for at in AccountingType.objects.order_by('code').all(): + #bilan[at] = self.object.operations.filter(type__startswith=at.code) + sum_by_type = list((self.object.operations.filter( + accounting_type__code__startswith=at.code).aggregate(Sum('amount'))).values())[0] + if sum_by_type != 0: + bilan[at] = sum_by_type + return bilan def bilan(self): - bilan = {} - self.recursive_sum('6', bilan) - print(bilan) + bilan = self.recursive_sum(3) return bilan def total_credit(self): - return sum(self.bilan().values()) + return self.bilan().get('6')#sum(self.bilan().values()) def total_debit(self): - return sum(self.bilan().values()) + return self.bilan().get('6')#sum(self.bilan().values()) def get_context_data(self, **kwargs): """ Add journal to the context """ From 93211d8ada932f888ce8a50cbc65674ac83a69b3 Mon Sep 17 00:00:00 2001 From: Krophil Date: Wed, 21 Dec 2016 02:55:24 +0100 Subject: [PATCH 07/13] operations added in populate --- core/management/commands/populate.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py index 673d3154..db81f0c1 100644 --- a/core/management/commands/populate.py +++ b/core/management/commands/populate.py @@ -295,10 +295,17 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site. ca.save() gj = GeneralJournal(name="A16", start_date=date.today(), club_account=ca) gj.save() - credit = AccountingType(code=74, label="Someone gave us money", movement_type='CREDIT') + credit = AccountingType(code='74', label="Someone gave us money", movement_type='CREDIT') credit.save() - debit = AccountingType(code=607, label="Had to pay a beer", movement_type='DEBIT') + debit = AccountingType(code='607', label="Had to pay a beer", movement_type='DEBIT') debit.save() + t = AccountingType(code='602', label="Gros test de malade", movement_type='DEBIT') + t.save() + Operation(journal=gj, date=date.today(), amount=32.3, remark="...", mode="CASH", done=True, accounting_type=t, target_type="USER", target_id=skia.id).save() + t = AccountingType(code='60', label="...", movement_type='DEBIT') + t.save() + Operation(journal=gj, date=date.today(), amount=32.3, remark="...", mode="CASH", done=True, accounting_type=t, target_type="USER", target_id=skia.id).save() + Operation(journal=gj, date=date.today(), amount=46.42, remark="An answer to life...", mode="CASH", done=True, accounting_type=t, target_type="USER", target_id=skia.id).save() Operation(journal=gj, date=date.today(), amount=666.42, remark="An answer to life...", mode="CASH", done=True, accounting_type=credit, target_type="USER", target_id=skia.id).save() From 6d756423d907b72a0aded7a350025da7c8a9170c Mon Sep 17 00:00:00 2001 From: Krophil Date: Wed, 21 Dec 2016 03:52:33 +0100 Subject: [PATCH 08/13] tabs added --- .../accounting/journal_details.jinja | 4 +- accounting/views.py | 42 ++++++++++++++++--- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/accounting/templates/accounting/journal_details.jinja b/accounting/templates/accounting/journal_details.jinja index 7fa34111..425ae36b 100644 --- a/accounting/templates/accounting/journal_details.jinja +++ b/accounting/templates/accounting/journal_details.jinja @@ -22,9 +22,7 @@

{% trans %}Journal is closed, you can not create operation{% endtrans %}

{% else %}

{% trans %}New operation{% endtrans %}

-

{% trans %}Journal Bilan Nature{% endtrans %}

-

{% trans %}Journal Bilan Person{% endtrans %}

-

{% trans %}Journal Bilan Accounting{% endtrans %}

+
{% endif %} diff --git a/accounting/views.py b/accounting/views.py index 91434206..431f4536 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -16,7 +16,7 @@ from django.conf import settings from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultipleField -from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin +from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin from core.views.forms import SelectFile, SelectDate from accounting.models import BankAccount, ClubAccount, GeneralJournal, Operation, AccountingType, Company, SimplifiedAccountingType, Label from counter.models import Counter, Selling, Product @@ -165,6 +165,34 @@ class ClubAccountDeleteView(CanEditPropMixin, DeleteView): # TODO change Delete # Journal views +class JournalTabsMixin(TabedViewMixin): + def get_tabs_title(self): + return _("Journal") + + def get_list_of_tabs(self): + tab_list = [] + tab_list.append({ + 'url': reverse('accounting:journal_details', kwargs={'j_id': self.object.id}), + 'slug': 'journal', + 'name': _("Journal"), + }) + tab_list.append({ + 'url': reverse('accounting:journal_bilan_nature', kwargs={'j_id': self.object.id}), + 'slug': 'bilan_nature', + 'name': _("Bilan nature"), + }) + tab_list.append({ + 'url': reverse('accounting:journal_bilan_person', kwargs={'j_id': self.object.id}), + 'slug': 'bilan_person', + 'name': _("Bilan person"), + }) + tab_list.append({ + 'url': reverse('accounting:journal_bilan_accounting', kwargs={'j_id': self.object.id}), + 'slug': 'bilan_accounting', + 'name': _("Bilan accounting"), + }) + return tab_list + class JournalCreateView(CanCreateMixin, CreateView): """ Create a general journal @@ -182,13 +210,14 @@ class JournalCreateView(CanCreateMixin, CreateView): ret['club_account'] = obj.id return ret -class JournalDetailView(CanViewMixin, DetailView): +class JournalDetailView(JournalTabsMixin, CanViewMixin, DetailView): """ A detail view, listing every operation """ model = GeneralJournal pk_url_kwarg = "j_id" template_name = 'accounting/journal_details.jinja' + current_tab = 'journal' class JournalEditView(CanEditMixin, UpdateView): """ @@ -444,13 +473,14 @@ class OperationPDFView(CanViewMixin, DetailView): p.save() return response -class JournalBilanNatureView(CanViewMixin, DetailView): +class JournalBilanNatureView(JournalTabsMixin, CanViewMixin, DetailView): """ Calculate a dictionary with operation code and sum of operations """ model = GeneralJournal pk_url_kwarg = "j_id" template_name='accounting/journal_bilan_nature.jinja' + current_tab='bilan_nature' def sum_by_code(self, code): from decimal import Decimal @@ -485,13 +515,14 @@ class JournalBilanNatureView(CanViewMixin, DetailView): kwargs['total_debit'] = self.total_debit() return kwargs -class JournalBilanPersonView(CanViewMixin, DetailView): +class JournalBilanPersonView(JournalTabsMixin, CanViewMixin, DetailView): """ Calculate a dictionary with operation target and sum of operations """ model = GeneralJournal pk_url_kwarg = "j_id" template_name='accounting/journal_bilan_person.jinja' + current_tab='bilan_person' def sum_by_target(self, target_id): from decimal import Decimal @@ -527,13 +558,14 @@ class JournalBilanPersonView(CanViewMixin, DetailView): kwargs['total_debit'] = self.total_debit() return kwargs -class JournalBilanAccountingView(CanViewMixin, DetailView): +class JournalBilanAccountingView(JournalTabsMixin, CanViewMixin, DetailView): """ Calculate a dictionary with operation type and sum of operations """ model = GeneralJournal pk_url_kwarg = "j_id" template_name='accounting/journal_bilan_accounting.jinja' + current_tab = "bilan_accounting" def recursive_sum(self, max_length): import collections From bdcc0bf6e9a3a356cd92cc1c68f56a94ca1807bc Mon Sep 17 00:00:00 2001 From: Skia Date: Wed, 21 Dec 2016 04:58:52 +0100 Subject: [PATCH 09/13] Remake the statement by nature --- .../accounting/journal_bilan_accounting.jinja | 35 +++-- .../accounting/journal_bilan_nature.jinja | 91 +++++------ accounting/views.py | 141 ++++++++---------- locale/fr/LC_MESSAGES/django.po | 2 +- 4 files changed, 126 insertions(+), 143 deletions(-) diff --git a/accounting/templates/accounting/journal_bilan_accounting.jinja b/accounting/templates/accounting/journal_bilan_accounting.jinja index 6ceadda6..b9faf5d0 100644 --- a/accounting/templates/accounting/journal_bilan_accounting.jinja +++ b/accounting/templates/accounting/journal_bilan_accounting.jinja @@ -6,28 +6,27 @@ {% block content %} -

{% trans %}Accounting bilan: {% endtrans %} {{ object.name }}

+

{% trans %}Accounting bilan: {% endtrans %} {{ object.name }}

-

{% trans %}Credit{% endtrans %}

- -
- +
+ - + - - - {% for key in bilan.keys() %} - - - - - {% endfor %} - + + + {% for k,v in bilan.items() %} + + + + + {% endfor %} + -
{% trans %}Type of operations{% endtrans %}{% trans %}Operation type{% endtrans %} {% trans %}Sum{% endtrans %}
{{ key }}{{ bilan[key] }}
{{ k }}{{ v }}
+ -

Total : {{ total_credit }}

+

{% trans %}Amount: {% endtrans %}{{ object.amount }} €

+

{% trans %}Effective amount: {% endtrans %}{{ object.effective_amount }} €

-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/accounting/templates/accounting/journal_bilan_nature.jinja b/accounting/templates/accounting/journal_bilan_nature.jinja index d8de0864..2e82b5fd 100644 --- a/accounting/templates/accounting/journal_bilan_nature.jinja +++ b/accounting/templates/accounting/journal_bilan_nature.jinja @@ -4,52 +4,53 @@ {% trans %}General journal:{% endtrans %} {{ object.name }} {% endblock %} +{% macro display_tables(dict) %} +

{% trans %}Credit{% endtrans %}

+ + + + + + + + + {% for k,v in dict['CREDIT'].items() %} + + + + + {% endfor %} + +
{% trans %}Nature of operation{% endtrans %}{% trans %}Sum{% endtrans %}
{{ k }}{{ v }}
+{% trans %}Total: {% endtrans %}{{ dict['CREDIT_sum'] }} + +

{% trans %}Debit{% endtrans %}

+ + + + + + + + + {% for k,v in dict['DEBIT'].items() %} + + + + + {% endfor %} + +
{% trans %}Nature of operation{% endtrans %}{% trans %}Sum{% endtrans %}
{{ k }}{{ v }}
+{% trans %}Total: {% endtrans %}{{ dict['DEBIT_sum'] }} +{% endmacro %} {% block content %} -

{% trans %}Nature bilan: {% endtrans %} {{ object.name }}

+

{% trans %}Statement by nature: {% endtrans %} {{ object.name }}

-

{% trans %}Credit{% endtrans %}

+{% for k,v in statement.items() %} +

{{ k }}

+{{ display_tables(v) }} +
+{% endfor %} - - - - - - - - - {% for key in bilan_credit.keys() %} - - - - - {% endfor %} - - -
{% trans %}Nature of operation{% endtrans %}{% trans %}Sum{% endtrans %}
{{key}}{{bilan_credit[key]}}
- -

Total : {{total_credit}}

- -

{% trans %}Debit{% endtrans %}

- - - - - - - - - - {% for key in bilan_debit.keys() %} - - - - - {% endfor %} - - -
{% trans %}Nature of operation{% endtrans %}{% trans %}Sum{% endtrans %}
{{key}}{{bilan_debit[key]}}
- -

Total : {{total_debit}}

- -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/accounting/views.py b/accounting/views.py index 431f4536..5b691ca3 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -7,12 +7,14 @@ from django.forms.models import modelform_factory from django.core.exceptions import PermissionDenied from django.forms import HiddenInput from django.db import transaction +from django.db.models import Sum from django.conf import settings from django import forms from django.http import HttpResponseRedirect, HttpResponse from django.utils.translation import ugettext as _ from django.conf import settings +import collections from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultipleField @@ -363,8 +365,6 @@ class OperationPDFView(CanViewMixin, DetailView): pdfmetrics.registerFont(TTFont('DejaVu', 'DejaVuSerif.ttf')) - - self.object = self.get_object() amount = self.object.amount remark = self.object.remark @@ -384,7 +384,6 @@ class OperationPDFView(CanViewMixin, DetailView): else: target = self.object.target.get_display_name() - response = HttpResponse(content_type='application/pdf') response['Content-Disposition'] = 'attachment; filename="op-%d(%s_on_%s).pdf"' %(num, ti, club_name) p = canvas.Canvas(response) @@ -396,11 +395,11 @@ class OperationPDFView(CanViewMixin, DetailView): im = ImageReader("core/static/core/img/logo.jpg") iw, ih = im.getSize() p.drawImage(im, 40, height - 50, width=iw/2, height=ih/2) - + labelStr = [["%s %s - %s %s" % (_("Journal"), ti, _("Operation"), num)]] label = Table(labelStr, colWidths=[150], rowHeights=[20]) - + label.setStyle(TableStyle([ ('ALIGN',(0,0),(-1,-1),'CENTER'), ('BOX', (0,0), (-1,-1), 0.25, colors.black), @@ -414,11 +413,11 @@ class OperationPDFView(CanViewMixin, DetailView): p.drawString(90, height - 190, _("Date: %(date)s") % {"date": date}) data = [] - + data += [["%s" % (_("Credit").upper() if nature == 'CREDIT' else _("Debit").upper())]] data += [[_("Amount: %(amount).2f €") % {"amount": amount}]] - + payment_mode = "" for m in settings.SITH_ACCOUNTING_PAYMENT_METHOD: if m[0] == mode: @@ -428,11 +427,11 @@ class OperationPDFView(CanViewMixin, DetailView): payment_mode += " %s\n" %(m[1]) data += [[payment_mode]] - + data += [["%s : %s" % (_("Debtor") if nature == 'CREDIT' else _("Creditor"), target), ""]] data += [["%s \n%s" % (_("Comment:"), remark)]] - + t = Table(data, colWidths=[(width-90*2)/2]*2, rowHeights=[20, 20, 70, 20, 80]) t.setStyle(TableStyle([ ('ALIGN',(0,0),(-1,-1),'CENTER'), @@ -464,8 +463,6 @@ class OperationPDFView(CanViewMixin, DetailView): t.drawOn(p, 90, 350) - - p.drawCentredString(10.5 * cm, 2 * cm, club_name) p.drawCentredString(10.5 * cm, 1 * cm, club_address) @@ -475,44 +472,50 @@ class OperationPDFView(CanViewMixin, DetailView): class JournalBilanNatureView(JournalTabsMixin, CanViewMixin, DetailView): """ - Calculate a dictionary with operation code and sum of operations + Display a statement sorted by labels """ model = GeneralJournal pk_url_kwarg = "j_id" template_name='accounting/journal_bilan_nature.jinja' current_tab='bilan_nature' - def sum_by_code(self, code): - from decimal import Decimal - from django.db.models import Sum, DecimalField - return(list((self.object.operations.filter( - accounting_type__code=code).aggregate(Sum('amount'))).values())[0]) + def statement(self, queryset, movement_type): + ret = collections.OrderedDict() + statement = collections.OrderedDict() + total_sum = 0 + for at in AccountingType.objects.order_by('label').all(): + sum = queryset.filter(accounting_type__movement_type=movement_type, + accounting_type__code__startswith=at.code).aggregate(amount_sum=Sum('amount'))['amount_sum'] + if sum: + total_sum += sum + statement[at.label] = sum + ret[movement_type] = statement + ret[movement_type+"_sum"] = total_sum + return ret - def bilan_credit(self): - bilan = {} - for el in AccountingType.objects.filter(movement_type='CREDIT'): - bilan["%s - %s" % (el.code, el.label)] = self.sum_by_code(el.code) - return bilan - - def bilan_debit(self): - bilan = {} - for el in AccountingType.objects.filter(movement_type='DEBIT'): - bilan["%s - %s" % (el.code, el.label)] = self.sum_by_code(el.code) - return bilan - - def total_credit(self): - return sum(self.bilan_credit().values()) - - def total_debit(self): - return sum(self.bilan_debit().values()) + def big_statement(self): + label_list = self.object.operations.order_by('label').values_list('label').distinct() + labels = Label.objects.filter(id__in=label_list).all() + statement = collections.OrderedDict() + gen_statement = collections.OrderedDict() + no_label_statement = collections.OrderedDict() + gen_statement.update(self.statement(self.object.operations.all(), "CREDIT")) + gen_statement.update(self.statement(self.object.operations.all(), "DEBIT")) + statement[_("General statement")] = gen_statement + no_label_statement.update(self.statement(self.object.operations.filter(label=None).all(), "CREDIT")) + no_label_statement.update(self.statement(self.object.operations.filter(label=None).all(), "DEBIT")) + statement[_("No label operations")] = no_label_statement + for l in labels: + l_stmt = collections.OrderedDict() + l_stmt.update(self.statement(self.object.operations.filter(label=l).all(), "CREDIT")) + l_stmt.update(self.statement(self.object.operations.filter(label=l).all(), "DEBIT")) + statement[l] = l_stmt + return statement def get_context_data(self, **kwargs): - """ Add journal to the context """ + """ Add infos to the context """ kwargs = super(JournalBilanNatureView, self).get_context_data(**kwargs) - kwargs['bilan_credit'] = self.bilan_credit() - kwargs['bilan_debit'] = self.bilan_debit() - kwargs['total_credit'] = self.total_credit() - kwargs['total_debit'] = self.total_debit() + kwargs['statement'] = self.big_statement() return kwargs class JournalBilanPersonView(JournalTabsMixin, CanViewMixin, DetailView): @@ -530,30 +533,29 @@ class JournalBilanPersonView(JournalTabsMixin, CanViewMixin, DetailView): return(list((self.object.operations.filter( target_id=target_id).aggregate(Sum('amount'))).values())[0]) - def bilan_credit(self): - - bilan = {} + def credit_statement(self): + statement = {} for el in Operation.objects.filter(accounting_type__movement_type='CREDIT'): - bilan[el.target] = self.sum_by_target(el.target_id) - return bilan + statement[el.target] = self.sum_by_target(el.target_id) + return statement - def bilan_debit(self): - bilan = {} + def debit_statement(self): + statement = {} for el in Operation.objects.filter(accounting_type__movement_type='DEBIT'): - bilan[el.target] = self.sum_by_target(el.target_id) - return bilan + statement[el.target] = self.sum_by_target(el.target_id) + return statement def total_credit(self): - return sum(self.bilan_credit().values()) + return sum(self.credit_statement().values()) def total_debit(self): - return sum(self.bilan_debit().values()) + return sum(self.debit_statement().values()) def get_context_data(self, **kwargs): """ Add journal to the context """ kwargs = super(JournalBilanPersonView, self).get_context_data(**kwargs) - kwargs['bilan_credit'] = self.bilan_credit() - kwargs['bilan_debit'] = self.bilan_debit() + kwargs['credit_statement'] = self.credit_statement() + kwargs['debit_statement'] = self.debit_statement() kwargs['total_credit'] = self.total_credit() kwargs['total_debit'] = self.total_debit() return kwargs @@ -567,38 +569,19 @@ class JournalBilanAccountingView(JournalTabsMixin, CanViewMixin, DetailView): template_name='accounting/journal_bilan_accounting.jinja' current_tab = "bilan_accounting" - def recursive_sum(self, max_length): - import collections - from decimal import Decimal - from django.db.models import Sum, DecimalField - bilan = {} - bilan = collections.OrderedDict(bilan) - + def statement(self): + statement = collections.OrderedDict() for at in AccountingType.objects.order_by('code').all(): - #bilan[at] = self.object.operations.filter(type__startswith=at.code) - sum_by_type = list((self.object.operations.filter( - accounting_type__code__startswith=at.code).aggregate(Sum('amount'))).values())[0] + sum_by_type = self.object.operations.filter( + accounting_type__code__startswith=at.code).aggregate(amount_sum=Sum('amount'))['amount_sum'] if sum_by_type != 0: - bilan[at] = sum_by_type - return bilan - - - def bilan(self): - bilan = self.recursive_sum(3) - return bilan - - def total_credit(self): - return self.bilan().get('6')#sum(self.bilan().values()) - - def total_debit(self): - return self.bilan().get('6')#sum(self.bilan().values()) + statement[at] = sum_by_type + return statement def get_context_data(self, **kwargs): """ Add journal to the context """ kwargs = super(JournalBilanAccountingView, self).get_context_data(**kwargs) - kwargs['bilan'] = self.bilan() - kwargs['total_credit'] = self.total_credit() - kwargs['total_debit'] = self.total_debit() + kwargs['statement'] = self.statement() return kwargs # Company views @@ -634,7 +617,7 @@ class LabelListView(CanViewMixin, DetailView): pk_url_kwarg = "clubaccount_id" template_name = 'accounting/label_list.jinja' -class LabelCreateView(CanEditMixin, CreateView): # FIXME we need to check the rights before creating the object +class LabelCreateView(CanCreateMixin, CreateView): # FIXME we need to check the rights before creating the object model = Label form_class = modelform_factory(Label, fields=['name', 'club_account'], widgets={ 'club_account': HiddenInput, diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index fcdf8fd4..1888bc6f 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -161,7 +161,7 @@ msgstr "type comptable" #: accounting/models.py:205 accounting/models.py:299 accounting/models.py:325 #: accounting/models.py:348 counter/models.py:282 msgid "label" -msgstr "intitulé" +msgstr "étiquette" #: accounting/models.py:206 msgid "target type" From e6e4929eff71f143ba39e8fe525fa2e305b1d030 Mon Sep 17 00:00:00 2001 From: Skia Date: Wed, 21 Dec 2016 05:18:02 +0100 Subject: [PATCH 10/13] Rename bilan to statement --- ...nja => journal_statement_accounting.jinja} | 4 +- ...e.jinja => journal_statement_nature.jinja} | 8 ++-- ...n.jinja => journal_statement_person.jinja} | 18 ++++---- accounting/urls.py | 6 +-- accounting/views.py | 42 +++++++++---------- 5 files changed, 39 insertions(+), 39 deletions(-) rename accounting/templates/accounting/{journal_bilan_accounting.jinja => journal_statement_accounting.jinja} (84%) rename accounting/templates/accounting/{journal_bilan_nature.jinja => journal_statement_nature.jinja} (86%) rename accounting/templates/accounting/{journal_bilan_person.jinja => journal_statement_person.jinja} (78%) diff --git a/accounting/templates/accounting/journal_bilan_accounting.jinja b/accounting/templates/accounting/journal_statement_accounting.jinja similarity index 84% rename from accounting/templates/accounting/journal_bilan_accounting.jinja rename to accounting/templates/accounting/journal_statement_accounting.jinja index b9faf5d0..8e6cd8fc 100644 --- a/accounting/templates/accounting/journal_bilan_accounting.jinja +++ b/accounting/templates/accounting/journal_statement_accounting.jinja @@ -6,7 +6,7 @@ {% block content %} -

{% trans %}Accounting bilan: {% endtrans %} {{ object.name }}

+

{% trans %}Accounting statement: {% endtrans %} {{ object.name }}

@@ -16,7 +16,7 @@ - {% for k,v in bilan.items() %} + {% for k,v in statement.items() %} diff --git a/accounting/templates/accounting/journal_bilan_nature.jinja b/accounting/templates/accounting/journal_statement_nature.jinja similarity index 86% rename from accounting/templates/accounting/journal_bilan_nature.jinja rename to accounting/templates/accounting/journal_statement_nature.jinja index 2e82b5fd..fb320dad 100644 --- a/accounting/templates/accounting/journal_bilan_nature.jinja +++ b/accounting/templates/accounting/journal_statement_nature.jinja @@ -5,7 +5,7 @@ {% endblock %} {% macro display_tables(dict) %} -

{% trans %}Credit{% endtrans %}

+
{% trans %}Credit{% endtrans %}
{{ k }} {{ v }}
@@ -24,7 +24,7 @@
{% trans %}Total: {% endtrans %}{{ dict['CREDIT_sum'] }} -

{% trans %}Debit{% endtrans %}

+
{% trans %}Debit{% endtrans %}
@@ -45,10 +45,10 @@ {% endmacro %} {% block content %} -

{% trans %}Statement by nature: {% endtrans %} {{ object.name }}

+

{% trans %}Statement by nature: {% endtrans %} {{ object.name }}

{% for k,v in statement.items() %} -

{{ k }}

+

{{ k }}

{{ display_tables(v) }}
{% endfor %} diff --git a/accounting/templates/accounting/journal_bilan_person.jinja b/accounting/templates/accounting/journal_statement_person.jinja similarity index 78% rename from accounting/templates/accounting/journal_bilan_person.jinja rename to accounting/templates/accounting/journal_statement_person.jinja index 8b913123..89b54cd8 100644 --- a/accounting/templates/accounting/journal_bilan_person.jinja +++ b/accounting/templates/accounting/journal_statement_person.jinja @@ -6,9 +6,9 @@ {% block content %} -

{% trans %}Person bilan: {% endtrans %} {{ object.name }}

+

{% trans %}Statement by person: {% endtrans %} {{ object.name }}

-

{% trans %}Credit{% endtrans %}

+

{% trans %}Credit{% endtrans %}

@@ -18,14 +18,14 @@ - {% for key in bilan_credit.keys() %} + {% for key in credit_statement.keys() %} {% if key.target_type == "OTHER" %} {% else %} {% endif %} - + {% endfor %} @@ -34,8 +34,8 @@

Total : {{total_credit}}

-

{% trans %}Debit{% endtrans %}

- +

{% trans %}Debit{% endtrans %}

+
{{ o.target_label }}{{ key.get_display_name() }}{{bilan_credit[key]}}{{credit_statement[key]}}
@@ -44,14 +44,14 @@ - {% for key in bilan_debit.keys() %} + {% for key in debit_statement.keys() %} {% if key.target_type == "OTHER" %} {% else %} {% endif %} - + {% endfor %} @@ -60,4 +60,4 @@

Total : {{total_debit}}

-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/accounting/urls.py b/accounting/urls.py index b91620a2..3255cb9d 100644 --- a/accounting/urls.py +++ b/accounting/urls.py @@ -26,9 +26,9 @@ urlpatterns = [ url(r'^journal/create$', JournalCreateView.as_view(), name='journal_new'), url(r'^journal/(?P[0-9]+)$', JournalDetailView.as_view(), name='journal_details'), url(r'^journal/(?P[0-9]+)/edit$', JournalEditView.as_view(), name='journal_edit'), - url(r'^journal/(?P[0-9]+)/bilan/nature$', JournalBilanNatureView.as_view(), name='journal_bilan_nature'), - url(r'^journal/(?P[0-9]+)/bilan/person$', JournalBilanPersonView.as_view(), name='journal_bilan_person'), - url(r'^journal/(?P[0-9]+)/bilan/accounting$', JournalBilanAccountingView.as_view(), name='journal_bilan_accounting'), + url(r'^journal/(?P[0-9]+)/statement/nature$', JournalNatureStatementView.as_view(), name='journal_nature_statement'), + url(r'^journal/(?P[0-9]+)/statement/person$', JournalPersonStatementView.as_view(), name='journal_person_statement'), + url(r'^journal/(?P[0-9]+)/statement/accounting$', JournalAccountingStatementView.as_view(), name='journal_accounting_statement'), # Operations url(r'^operation/create/(?P[0-9]+)$', OperationCreateView.as_view(), name='op_new'), diff --git a/accounting/views.py b/accounting/views.py index 5b691ca3..e9628320 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -179,19 +179,19 @@ class JournalTabsMixin(TabedViewMixin): 'name': _("Journal"), }) tab_list.append({ - 'url': reverse('accounting:journal_bilan_nature', kwargs={'j_id': self.object.id}), - 'slug': 'bilan_nature', - 'name': _("Bilan nature"), + 'url': reverse('accounting:journal_nature_statement', kwargs={'j_id': self.object.id}), + 'slug': 'nature_statement', + 'name': _("Statement by nature"), }) tab_list.append({ - 'url': reverse('accounting:journal_bilan_person', kwargs={'j_id': self.object.id}), - 'slug': 'bilan_person', - 'name': _("Bilan person"), + 'url': reverse('accounting:journal_person_statement', kwargs={'j_id': self.object.id}), + 'slug': 'person_statement', + 'name': _("Statement by person"), }) tab_list.append({ - 'url': reverse('accounting:journal_bilan_accounting', kwargs={'j_id': self.object.id}), - 'slug': 'bilan_accounting', - 'name': _("Bilan accounting"), + 'url': reverse('accounting:journal_accounting_statement', kwargs={'j_id': self.object.id}), + 'slug': 'accounting_statement', + 'name': _("Accounting statement"), }) return tab_list @@ -470,14 +470,14 @@ class OperationPDFView(CanViewMixin, DetailView): p.save() return response -class JournalBilanNatureView(JournalTabsMixin, CanViewMixin, DetailView): +class JournalNatureStatementView(JournalTabsMixin, CanViewMixin, DetailView): """ Display a statement sorted by labels """ model = GeneralJournal pk_url_kwarg = "j_id" - template_name='accounting/journal_bilan_nature.jinja' - current_tab='bilan_nature' + template_name='accounting/journal_statement_nature.jinja' + current_tab='nature_statement' def statement(self, queryset, movement_type): ret = collections.OrderedDict() @@ -514,18 +514,18 @@ class JournalBilanNatureView(JournalTabsMixin, CanViewMixin, DetailView): def get_context_data(self, **kwargs): """ Add infos to the context """ - kwargs = super(JournalBilanNatureView, self).get_context_data(**kwargs) + kwargs = super(JournalNatureStatementView, self).get_context_data(**kwargs) kwargs['statement'] = self.big_statement() return kwargs -class JournalBilanPersonView(JournalTabsMixin, CanViewMixin, DetailView): +class JournalPersonStatementView(JournalTabsMixin, CanViewMixin, DetailView): """ Calculate a dictionary with operation target and sum of operations """ model = GeneralJournal pk_url_kwarg = "j_id" - template_name='accounting/journal_bilan_person.jinja' - current_tab='bilan_person' + template_name='accounting/journal_statement_person.jinja' + current_tab='person_statement' def sum_by_target(self, target_id): from decimal import Decimal @@ -553,21 +553,21 @@ class JournalBilanPersonView(JournalTabsMixin, CanViewMixin, DetailView): def get_context_data(self, **kwargs): """ Add journal to the context """ - kwargs = super(JournalBilanPersonView, self).get_context_data(**kwargs) + kwargs = super(JournalPersonStatementView, self).get_context_data(**kwargs) kwargs['credit_statement'] = self.credit_statement() kwargs['debit_statement'] = self.debit_statement() kwargs['total_credit'] = self.total_credit() kwargs['total_debit'] = self.total_debit() return kwargs -class JournalBilanAccountingView(JournalTabsMixin, CanViewMixin, DetailView): +class JournalAccountingStatementView(JournalTabsMixin, CanViewMixin, DetailView): """ Calculate a dictionary with operation type and sum of operations """ model = GeneralJournal pk_url_kwarg = "j_id" - template_name='accounting/journal_bilan_accounting.jinja' - current_tab = "bilan_accounting" + template_name='accounting/journal_statement_accounting.jinja' + current_tab = "accounting_statement" def statement(self): statement = collections.OrderedDict() @@ -580,7 +580,7 @@ class JournalBilanAccountingView(JournalTabsMixin, CanViewMixin, DetailView): def get_context_data(self, **kwargs): """ Add journal to the context """ - kwargs = super(JournalBilanAccountingView, self).get_context_data(**kwargs) + kwargs = super(JournalAccountingStatementView, self).get_context_data(**kwargs) kwargs['statement'] = self.statement() return kwargs From 33ee449fb55f3ed8da1ab408b0faf458fa1d201b Mon Sep 17 00:00:00 2001 From: Skia Date: Wed, 21 Dec 2016 05:23:01 +0100 Subject: [PATCH 11/13] Make translations --- locale/fr/LC_MESSAGES/django.po | 160 ++++++++++++++++++++++---------- 1 file changed, 111 insertions(+), 49 deletions(-) diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 1888bc6f..065ffb43 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2016-12-21 02:37+0100\n" +"POT-Creation-Date: 2016-12-21 05:22+0100\n" "PO-Revision-Date: 2016-07-18\n" "Last-Translator: Skia \n" "Language-Team: AE info \n" @@ -244,11 +244,17 @@ msgstr "Un code comptable ne contient que des numéros" msgid "movement type" msgstr "type de mouvement" -#: accounting/models.py:300 accounting/views.py:389 +#: accounting/models.py:300 +#: accounting/templates/accounting/journal_statement_nature.jinja:8 +#: accounting/templates/accounting/journal_statement_person.jinja:11 +#: accounting/views.py:417 msgid "Credit" msgstr "Crédit" -#: accounting/models.py:300 accounting/views.py:389 +#: accounting/models.py:300 +#: accounting/templates/accounting/journal_statement_nature.jinja:27 +#: accounting/templates/accounting/journal_statement_person.jinja:37 +#: accounting/views.py:417 msgid "Debit" msgstr "Débit" @@ -340,7 +346,7 @@ msgstr "Nouveau compte club" #: accounting/templates/accounting/bank_account_details.jinja:26 #: accounting/templates/accounting/bank_account_list.jinja:21 #: accounting/templates/accounting/club_account_details.jinja:55 -#: accounting/templates/accounting/journal_details.jinja:72 club/views.py:54 +#: accounting/templates/accounting/journal_details.jinja:73 club/views.py:54 #: core/templates/core/file.jinja:38 core/templates/core/page.jinja:31 #: core/templates/core/user_tools.jinja:38 core/views/user.py:152 #: counter/templates/counter/cash_summary_list.jinja:53 @@ -413,7 +419,7 @@ msgid "End" msgstr "Fin" #: accounting/templates/accounting/club_account_details.jinja:31 -#: accounting/templates/accounting/journal_details.jinja:32 +#: accounting/templates/accounting/journal_details.jinja:33 #: core/templates/core/user_account_detail.jinja:53 #: core/templates/core/user_account_detail.jinja:80 #: counter/templates/counter/last_ops.jinja:17 @@ -429,17 +435,17 @@ msgid "Closed" msgstr "Fermé" #: accounting/templates/accounting/club_account_details.jinja:34 -#: accounting/templates/accounting/journal_details.jinja:40 +#: accounting/templates/accounting/journal_details.jinja:41 msgid "Actions" msgstr "Actions" #: accounting/templates/accounting/club_account_details.jinja:50 -#: accounting/templates/accounting/journal_details.jinja:60 +#: accounting/templates/accounting/journal_details.jinja:61 msgid "Yes" msgstr "Oui" #: accounting/templates/accounting/club_account_details.jinja:52 -#: accounting/templates/accounting/journal_details.jinja:62 +#: accounting/templates/accounting/journal_details.jinja:63 msgid "No" msgstr "Non" @@ -464,10 +470,14 @@ msgstr "Entreprises" #: accounting/templates/accounting/journal_details.jinja:4 #: accounting/templates/accounting/journal_details.jinja:15 +#: accounting/templates/accounting/journal_statement_accounting.jinja:4 +#: accounting/templates/accounting/journal_statement_nature.jinja:4 +#: accounting/templates/accounting/journal_statement_person.jinja:4 msgid "General journal:" msgstr "Classeur : " #: accounting/templates/accounting/journal_details.jinja:19 +#: accounting/templates/accounting/journal_statement_accounting.jinja:29 #: core/templates/core/user_account.jinja:38 #: core/templates/core/user_account_detail.jinja:10 #: counter/templates/counter/counter_click.jinja:32 @@ -475,6 +485,7 @@ msgid "Amount: " msgstr "Montant : " #: accounting/templates/accounting/journal_details.jinja:20 +#: accounting/templates/accounting/journal_statement_accounting.jinja:30 msgid "Effective amount: " msgstr "Montant effectif: " @@ -486,12 +497,12 @@ msgstr "Le classeur est fermé, vous ne pouvez pas créer d'opération" msgid "New operation" msgstr "Nouvelle opération" -#: accounting/templates/accounting/journal_details.jinja:29 +#: accounting/templates/accounting/journal_details.jinja:30 #: counter/templates/counter/stats.jinja:14 msgid "Nb" msgstr "No" -#: accounting/templates/accounting/journal_details.jinja:30 +#: accounting/templates/accounting/journal_details.jinja:31 #: club/templates/club/club_sellings.jinja:19 #: core/templates/core/user_account_detail.jinja:17 #: core/templates/core/user_account_detail.jinja:50 @@ -502,50 +513,94 @@ msgstr "No" msgid "Date" msgstr "Date" -#: accounting/templates/accounting/journal_details.jinja:31 +#: accounting/templates/accounting/journal_details.jinja:32 #: club/templates/club/club_sellings.jinja:23 #: core/templates/core/user_account_detail.jinja:20 #: counter/templates/counter/last_ops.jinja:42 msgid "Label" msgstr "Étiquette" -#: accounting/templates/accounting/journal_details.jinja:33 +#: accounting/templates/accounting/journal_details.jinja:34 msgid "Payment mode" msgstr "Méthode de paiement" -#: accounting/templates/accounting/journal_details.jinja:34 +#: accounting/templates/accounting/journal_details.jinja:35 msgid "Target" msgstr "Cible" -#: accounting/templates/accounting/journal_details.jinja:35 +#: accounting/templates/accounting/journal_details.jinja:36 msgid "Code" msgstr "Code" -#: accounting/templates/accounting/journal_details.jinja:36 +#: accounting/templates/accounting/journal_details.jinja:37 msgid "Nature" msgstr "Nature" -#: accounting/templates/accounting/journal_details.jinja:37 +#: accounting/templates/accounting/journal_details.jinja:38 msgid "Done" msgstr "Effectué" -#: accounting/templates/accounting/journal_details.jinja:38 +#: accounting/templates/accounting/journal_details.jinja:39 #: counter/templates/counter/cash_summary_list.jinja:37 counter/views.py:710 msgid "Comment" msgstr "Commentaire" -#: accounting/templates/accounting/journal_details.jinja:39 +#: accounting/templates/accounting/journal_details.jinja:40 msgid "File" msgstr "Fichier" -#: accounting/templates/accounting/journal_details.jinja:41 +#: accounting/templates/accounting/journal_details.jinja:42 msgid "PDF" msgstr "PDF" -#: accounting/templates/accounting/journal_details.jinja:75 +#: accounting/templates/accounting/journal_details.jinja:76 msgid "Generate" msgstr "Générer" +#: accounting/templates/accounting/journal_statement_accounting.jinja:9 +msgid "Accounting statement: " +msgstr "Bilan comptable : " + +#: accounting/templates/accounting/journal_statement_accounting.jinja:14 +msgid "Operation type" +msgstr "Type d'opération" + +#: accounting/templates/accounting/journal_statement_accounting.jinja:15 +#: accounting/templates/accounting/journal_statement_nature.jinja:13 +#: accounting/templates/accounting/journal_statement_nature.jinja:32 +#: accounting/templates/accounting/journal_statement_person.jinja:17 +#: accounting/templates/accounting/journal_statement_person.jinja:43 +#: counter/templates/counter/invoices_call.jinja:21 +msgid "Sum" +msgstr "Somme" + +#: accounting/templates/accounting/journal_statement_nature.jinja:12 +#: accounting/templates/accounting/journal_statement_nature.jinja:31 +msgid "Nature of operation" +msgstr "Nature de l'opération" + +#: accounting/templates/accounting/journal_statement_nature.jinja:25 +#: accounting/templates/accounting/journal_statement_nature.jinja:44 +#: club/templates/club/club_sellings.jinja:14 +#: counter/templates/counter/counter_click.jinja:70 +#: counter/templates/counter/counter_main.jinja:28 +#: eboutic/templates/eboutic/eboutic_main.jinja:34 +msgid "Total: " +msgstr "Total : " + +#: accounting/templates/accounting/journal_statement_nature.jinja:48 +msgid "Statement by nature: " +msgstr "Bilan par nature : " + +#: accounting/templates/accounting/journal_statement_person.jinja:9 +msgid "Statement by person: " +msgstr "Bilan par personne : " + +#: accounting/templates/accounting/journal_statement_person.jinja:16 +#: accounting/templates/accounting/journal_statement_person.jinja:42 +msgid "Target of the operation" +msgstr "Cible de l'opération" + #: accounting/templates/accounting/label_list.jinja:14 msgid "Back to club account" msgstr "Retour au compte club" @@ -573,7 +628,7 @@ msgstr "Sauver" #: accounting/templates/accounting/refound_account.jinja:4 #: accounting/templates/accounting/refound_account.jinja:8 -#: accounting/views.py:548 +#: accounting/views.py:688 msgid "Refound account" msgstr "Remboursement de compte" @@ -594,55 +649,75 @@ msgstr "Types simplifiés" msgid "New simplified type" msgstr "Nouveau type simplifié" -#: accounting/views.py:365 accounting/views.py:371 -msgid "Operation" -msgstr "Opération" - -#: accounting/views.py:371 +#: accounting/views.py:172 accounting/views.py:179 accounting/views.py:399 msgid "Journal" msgstr "Classeur" -#: accounting/views.py:382 +#: accounting/views.py:184 +msgid "Statement by nature" +msgstr "Bilan par nature" + +#: accounting/views.py:189 +msgid "Statement by person" +msgstr "Bilan par personne" + +#: accounting/views.py:194 +msgid "Accounting statement" +msgstr "Bilan comptable" + +#: accounting/views.py:393 accounting/views.py:399 +msgid "Operation" +msgstr "Opération" + +#: accounting/views.py:410 msgid "Financial proof: " msgstr "Justificatif de libellé : " -#: accounting/views.py:383 +#: accounting/views.py:411 #, python-format msgid "Club: %(club_name)s" msgstr "Club : %(club_name)s" -#: accounting/views.py:384 +#: accounting/views.py:412 #, python-format msgid "Label: %(op_label)s" msgstr "Libellé : %(op_label)s" -#: accounting/views.py:385 +#: accounting/views.py:413 #, python-format msgid "Date: %(date)s" msgstr "Date : %(date)s" -#: accounting/views.py:391 +#: accounting/views.py:419 #, python-format msgid "Amount: %(amount).2f €" msgstr "Montant : %(amount).2f €" -#: accounting/views.py:403 +#: accounting/views.py:431 msgid "Debtor" msgstr "Débiteur" -#: accounting/views.py:403 +#: accounting/views.py:431 msgid "Creditor" msgstr "Créditeur" -#: accounting/views.py:405 +#: accounting/views.py:433 msgid "Comment:" msgstr "Commentaire :" -#: accounting/views.py:424 +#: accounting/views.py:452 msgid "Signature:" msgstr "Signature :" -#: accounting/views.py:510 +#: accounting/views.py:504 +msgid "General statement" +msgstr "Bilan général" + +#: accounting/views.py:507 +msgid "No label operations" +msgstr "Opérations sans étiquette" + +#: accounting/views.py:650 msgid "Refound this account" msgstr "Rembourser ce compte" @@ -790,13 +865,6 @@ msgstr "Quantité : " msgid "units" msgstr "unités" -#: club/templates/club/club_sellings.jinja:14 -#: counter/templates/counter/counter_click.jinja:70 -#: counter/templates/counter/counter_main.jinja:28 -#: eboutic/templates/eboutic/eboutic_main.jinja:34 -msgid "Total: " -msgstr "Total : " - #: club/templates/club/club_sellings.jinja:20 club/views.py:167 #: core/templates/core/user_account_detail.jinja:18 #: core/templates/core/user_account_detail.jinja:51 @@ -2601,10 +2669,6 @@ msgstr "Appels à facture pour %(date)s" msgid "Choose another month: " msgstr "Choisir un autre mois : " -#: counter/templates/counter/invoices_call.jinja:21 -msgid "Sum" -msgstr "Somme" - #: counter/templates/counter/last_ops.jinja:5 #: counter/templates/counter/last_ops.jinja:9 #, python-format @@ -3228,5 +3292,3 @@ msgid "You must either choose an existing user or create a new one properly" msgstr "" "Vous devez soit choisir un utilisateur existant, soit en créer un proprement" -#~ msgid "Welcome to the new AE's website!" -#~ msgstr "Bienvenue sur le nouveau site de l'AE ! " From f6d34baf598802d91b55278aa029e33087607e67 Mon Sep 17 00:00:00 2001 From: Skia Date: Wed, 21 Dec 2016 05:42:33 +0100 Subject: [PATCH 12/13] Refactor statement by person, make it work --- .../accounting/journal_statement_person.jinja | 74 +++++++++---------- accounting/views.py | 35 +++------ 2 files changed, 49 insertions(+), 60 deletions(-) diff --git a/accounting/templates/accounting/journal_statement_person.jinja b/accounting/templates/accounting/journal_statement_person.jinja index 89b54cd8..f163be1d 100644 --- a/accounting/templates/accounting/journal_statement_person.jinja +++ b/accounting/templates/accounting/journal_statement_person.jinja @@ -6,58 +6,58 @@ {% block content %} -

{% trans %}Statement by person: {% endtrans %} {{ object.name }}

+

{% trans %}Statement by person: {% endtrans %} {{ object.name }}

-

{% trans %}Credit{% endtrans %}

+

{% trans %}Credit{% endtrans %}

-
{{ o.target_label }}{{ key.get_display_name() }}{{bilan_debit[key]}}{{debit_statement[key]}}
- +
+ - - - {% for key in credit_statement.keys() %} - - {% if key.target_type == "OTHER" %} - - {% else %} - - {% endif %} - - - {% endfor %} - + + + {% for key in credit_statement.keys() %} + + {% if key.target_type == "OTHER" %} + + {% else %} + + {% endif %} + + + {% endfor %} + -
{% trans %}Target of the operation{% endtrans %} {% trans %}Sum{% endtrans %}
{{ o.target_label }}{{ key.get_display_name() }}{{credit_statement[key]}}
{{ o.target_label }}{{ key.get_display_name() }}{{ credit_statement[key] }}
+ -

Total : {{total_credit}}

+

Total : {{ total_credit }}

-

{% trans %}Debit{% endtrans %}

+

{% trans %}Debit{% endtrans %}

- - +
+ - - - {% for key in debit_statement.keys() %} - - {% if key.target_type == "OTHER" %} - - {% else %} - - {% endif %} - - - {% endfor %} - + + + {% for key in debit_statement.keys() %} + + {% if key.target_type == "OTHER" %} + + {% else %} + + {% endif %} + + + {% endfor %} + -
{% trans %}Target of the operation{% endtrans %} {% trans %}Sum{% endtrans %}
{{ o.target_label }}{{ key.get_display_name() }}{{debit_statement[key]}}
{{ o.target_label }}{{ key.get_display_name() }}{{ debit_statement[key] }}
+ -

Total : {{total_debit}}

+

Total : {{ total_debit }}

{% endblock %} diff --git a/accounting/views.py b/accounting/views.py index e9628320..79aaf525 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -527,37 +527,26 @@ class JournalPersonStatementView(JournalTabsMixin, CanViewMixin, DetailView): template_name='accounting/journal_statement_person.jinja' current_tab='person_statement' - def sum_by_target(self, target_id): - from decimal import Decimal - from django.db.models import Sum, DecimalField - return(list((self.object.operations.filter( - target_id=target_id).aggregate(Sum('amount'))).values())[0]) + def sum_by_target(self, target_id, target_type, movement_type): + return self.object.operations.filter(accounting_type__movement_type=movement_type, + target_id=target_id, target_type=target_type).aggregate(amount_sum=Sum('amount'))['amount_sum'] - def credit_statement(self): + def statement(self, movement_type): statement = {} - for el in Operation.objects.filter(accounting_type__movement_type='CREDIT'): - statement[el.target] = self.sum_by_target(el.target_id) + for op in Operation.objects.filter(accounting_type__movement_type=movement_type): + statement[op.target] = self.sum_by_target(op.target_id, op.target_type, movement_type) return statement - def debit_statement(self): - statement = {} - for el in Operation.objects.filter(accounting_type__movement_type='DEBIT'): - statement[el.target] = self.sum_by_target(el.target_id) - return statement - - def total_credit(self): - return sum(self.credit_statement().values()) - - def total_debit(self): - return sum(self.debit_statement().values()) + def total(self, movement_type): + return sum(self.statement(movement_type).values()) def get_context_data(self, **kwargs): """ Add journal to the context """ kwargs = super(JournalPersonStatementView, self).get_context_data(**kwargs) - kwargs['credit_statement'] = self.credit_statement() - kwargs['debit_statement'] = self.debit_statement() - kwargs['total_credit'] = self.total_credit() - kwargs['total_debit'] = self.total_debit() + kwargs['credit_statement'] = self.statement("CREDIT") + kwargs['debit_statement'] = self.statement("DEBIT") + kwargs['total_credit'] = self.total("CREDIT") + kwargs['total_debit'] = self.total("DEBIT") return kwargs class JournalAccountingStatementView(JournalTabsMixin, CanViewMixin, DetailView): From b07b408ecf676288ac749a1058e842531b7d504b Mon Sep 17 00:00:00 2001 From: Skia Date: Wed, 21 Dec 2016 13:09:40 +0100 Subject: [PATCH 13/13] Fix statements --- .../accounting/journal_statement_nature.jinja | 6 +++--- .../accounting/journal_statement_person.jinja | 8 ++++++-- accounting/views.py | 15 +++++++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/accounting/templates/accounting/journal_statement_nature.jinja b/accounting/templates/accounting/journal_statement_nature.jinja index fb320dad..44fa33e2 100644 --- a/accounting/templates/accounting/journal_statement_nature.jinja +++ b/accounting/templates/accounting/journal_statement_nature.jinja @@ -5,7 +5,7 @@ {% endblock %} {% macro display_tables(dict) %} -
{% trans %}Credit{% endtrans %}
+
{% trans %}Credit{% endtrans %}
@@ -24,7 +24,7 @@
{% trans %}Total: {% endtrans %}{{ dict['CREDIT_sum'] }} -
{% trans %}Debit{% endtrans %}
+
{% trans %}Debit{% endtrans %}
@@ -48,7 +48,7 @@

{% trans %}Statement by nature: {% endtrans %} {{ object.name }}

{% for k,v in statement.items() %} -

{{ k }}

+

{{ k }} : {{ v['CREDIT_sum'] - v['DEBIT_sum'] }}

{{ display_tables(v) }}
{% endfor %} diff --git a/accounting/templates/accounting/journal_statement_person.jinja b/accounting/templates/accounting/journal_statement_person.jinja index f163be1d..3c71f900 100644 --- a/accounting/templates/accounting/journal_statement_person.jinja +++ b/accounting/templates/accounting/journal_statement_person.jinja @@ -22,8 +22,10 @@ {% if key.target_type == "OTHER" %} - {% else %} + {% elif key %} + {% else %} + {% endif %} @@ -48,8 +50,10 @@ {% if key.target_type == "OTHER" %} - {% else %} + {% elif key %} + {% else %} + {% endif %} diff --git a/accounting/views.py b/accounting/views.py index 79aaf525..6984ec24 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -483,12 +483,14 @@ class JournalNatureStatementView(JournalTabsMixin, CanViewMixin, DetailView): ret = collections.OrderedDict() statement = collections.OrderedDict() total_sum = 0 - for at in AccountingType.objects.order_by('label').all(): + for sat in [None] + list(SimplifiedAccountingType.objects.order_by('label').all()): sum = queryset.filter(accounting_type__movement_type=movement_type, - accounting_type__code__startswith=at.code).aggregate(amount_sum=Sum('amount'))['amount_sum'] + simpleaccounting_type=sat).aggregate(amount_sum=Sum('amount'))['amount_sum'] + if sat: sat = sat.label + else: sat = "" if sum: total_sum += sum - statement[at.label] = sum + statement[sat] = sum ret[movement_type] = statement ret[movement_type+"_sum"] = total_sum return ret @@ -532,8 +534,9 @@ class JournalPersonStatementView(JournalTabsMixin, CanViewMixin, DetailView): target_id=target_id, target_type=target_type).aggregate(amount_sum=Sum('amount'))['amount_sum'] def statement(self, movement_type): - statement = {} - for op in Operation.objects.filter(accounting_type__movement_type=movement_type): + statement = collections.OrderedDict() + for op in self.object.operations.filter(accounting_type__movement_type=movement_type).order_by('target_type', + 'target_id').distinct(): statement[op.target] = self.sum_by_target(op.target_id, op.target_type, movement_type) return statement @@ -563,7 +566,7 @@ class JournalAccountingStatementView(JournalTabsMixin, CanViewMixin, DetailView) for at in AccountingType.objects.order_by('code').all(): sum_by_type = self.object.operations.filter( accounting_type__code__startswith=at.code).aggregate(amount_sum=Sum('amount'))['amount_sum'] - if sum_by_type != 0: + if sum_by_type: statement[at] = sum_by_type return statement
{{ o.target_label }}{{ key.get_display_name() }}{{ credit_statement[key] }}
{{ o.target_label }}{{ key.get_display_name() }}{{ debit_statement[key] }}