mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 22:23:23 +00:00
Refactor statement by person, make it work
This commit is contained in:
parent
33ee449fb5
commit
f6d34baf59
@ -6,58 +6,58 @@
|
|||||||
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h3>{% trans %}Statement by person: {% endtrans %} {{ object.name }}</h3>
|
<h3>{% trans %}Statement by person: {% endtrans %} {{ object.name }}</h3>
|
||||||
|
|
||||||
<h4>{% trans %}Credit{% endtrans %}</h4>
|
<h4>{% trans %}Credit{% endtrans %}</h4>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{% trans %}Target of the operation{% endtrans %}</td>
|
<td>{% trans %}Target of the operation{% endtrans %}</td>
|
||||||
<td>{% trans %}Sum{% endtrans %}</td>
|
<td>{% trans %}Sum{% endtrans %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for key in credit_statement.keys() %}
|
{% for key in credit_statement.keys() %}
|
||||||
<tr>
|
<tr>
|
||||||
{% if key.target_type == "OTHER" %}
|
{% if key.target_type == "OTHER" %}
|
||||||
<td>{{ o.target_label }}</td>
|
<td>{{ o.target_label }}</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td><a href="{{ key.get_absolute_url() }}">{{ key.get_display_name() }}</a></td>
|
<td><a href="{{ key.get_absolute_url() }}">{{ key.get_display_name() }}</a></td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td>{{credit_statement[key]}}</td>
|
<td>{{ credit_statement[key] }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<p>Total : {{total_credit}}</p>
|
<p>Total : {{ total_credit }}</p>
|
||||||
|
|
||||||
<h4>{% trans %}Debit{% endtrans %}</h4>
|
<h4>{% trans %}Debit{% endtrans %}</h4>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{% trans %}Target of the operation{% endtrans %}</td>
|
<td>{% trans %}Target of the operation{% endtrans %}</td>
|
||||||
<td>{% trans %}Sum{% endtrans %}</td>
|
<td>{% trans %}Sum{% endtrans %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for key in debit_statement.keys() %}
|
{% for key in debit_statement.keys() %}
|
||||||
<tr>
|
<tr>
|
||||||
{% if key.target_type == "OTHER" %}
|
{% if key.target_type == "OTHER" %}
|
||||||
<td>{{ o.target_label }}</td>
|
<td>{{ o.target_label }}</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td><a href="{{ key.get_absolute_url() }}">{{ key.get_display_name() }}</a></td>
|
<td><a href="{{ key.get_absolute_url() }}">{{ key.get_display_name() }}</a></td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td>{{debit_statement[key]}}</td>
|
<td>{{ debit_statement[key] }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<p>Total : {{total_debit}}</p>
|
<p>Total : {{ total_debit }}</p>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -527,37 +527,26 @@ class JournalPersonStatementView(JournalTabsMixin, CanViewMixin, DetailView):
|
|||||||
template_name='accounting/journal_statement_person.jinja'
|
template_name='accounting/journal_statement_person.jinja'
|
||||||
current_tab='person_statement'
|
current_tab='person_statement'
|
||||||
|
|
||||||
def sum_by_target(self, target_id):
|
def sum_by_target(self, target_id, target_type, movement_type):
|
||||||
from decimal import Decimal
|
return self.object.operations.filter(accounting_type__movement_type=movement_type,
|
||||||
from django.db.models import Sum, DecimalField
|
target_id=target_id, target_type=target_type).aggregate(amount_sum=Sum('amount'))['amount_sum']
|
||||||
return(list((self.object.operations.filter(
|
|
||||||
target_id=target_id).aggregate(Sum('amount'))).values())[0])
|
|
||||||
|
|
||||||
def credit_statement(self):
|
def statement(self, movement_type):
|
||||||
statement = {}
|
statement = {}
|
||||||
for el in Operation.objects.filter(accounting_type__movement_type='CREDIT'):
|
for op in Operation.objects.filter(accounting_type__movement_type=movement_type):
|
||||||
statement[el.target] = self.sum_by_target(el.target_id)
|
statement[op.target] = self.sum_by_target(op.target_id, op.target_type, movement_type)
|
||||||
return statement
|
return statement
|
||||||
|
|
||||||
def debit_statement(self):
|
def total(self, movement_type):
|
||||||
statement = {}
|
return sum(self.statement(movement_type).values())
|
||||||
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 get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
""" Add journal to the context """
|
""" Add journal to the context """
|
||||||
kwargs = super(JournalPersonStatementView, self).get_context_data(**kwargs)
|
kwargs = super(JournalPersonStatementView, self).get_context_data(**kwargs)
|
||||||
kwargs['credit_statement'] = self.credit_statement()
|
kwargs['credit_statement'] = self.statement("CREDIT")
|
||||||
kwargs['debit_statement'] = self.debit_statement()
|
kwargs['debit_statement'] = self.statement("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
|
||||||
|
|
||||||
class JournalAccountingStatementView(JournalTabsMixin, CanViewMixin, DetailView):
|
class JournalAccountingStatementView(JournalTabsMixin, CanViewMixin, DetailView):
|
||||||
|
Loading…
Reference in New Issue
Block a user