mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 15:51:19 +00:00
Now, I understand how ORM works... or not
This commit is contained in:
parent
bfa09c0bcd
commit
147287f9a9
@ -14,13 +14,16 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Nature of operation{% endtrans %}</td>
|
||||
<td>{% trans %}Amount{% endtrans %}</td>
|
||||
<td>{% trans %}Sum{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tr>
|
||||
<td>bla</td>
|
||||
<td>{{self.get_test()}}</td>
|
||||
<tr>
|
||||
<tbody>
|
||||
{% for key in bilan.keys() %}
|
||||
<tr>
|
||||
<td>{{object.operations.get(accounting_type__code=key).accounting_type.label}}</td>
|
||||
<td>{{bilan[key]}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
@ -22,6 +22,7 @@
|
||||
<p>{% trans %}Journal is closed, you can not create operation{% endtrans %}</p>
|
||||
{% else %}
|
||||
<p><a href="{{ url('accounting:op_new', j_id=object.id) }}">{% trans %}New operation{% endtrans %}</a></p>
|
||||
<p><a href="{{ url('accounting:journal_bilan', j_id=object.id) }}">{% trans %}Journal Bilan{% endtrans %}</a></p>
|
||||
{% endif %}
|
||||
<table>
|
||||
<thead>
|
||||
|
@ -26,6 +26,7 @@ urlpatterns = [
|
||||
url(r'^journal/create$', JournalCreateView.as_view(), name='journal_new'),
|
||||
url(r'^journal/(?P<j_id>[0-9]+)$', JournalDetailView.as_view(), name='journal_details'),
|
||||
url(r'^journal/(?P<j_id>[0-9]+)/edit$', JournalEditView.as_view(), name='journal_edit'),
|
||||
url(r'^journal/(?P<j_id>[0-9]+)/bilan$', JournalBilanView.as_view(), name='journal_bilan'),
|
||||
# Operations
|
||||
url(r'^operation/create/(?P<j_id>[0-9]+)$', OperationCreateView.as_view(), name='op_new'),
|
||||
url(r'^operation/(?P<op_id>[0-9]+)$', OperationEditView.as_view(), name='op_edit'),
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user