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