Add basic close journal functions

This commit is contained in:
Skia 2016-06-24 21:55:52 +02:00
parent e9544f2581
commit 50efc07eaa
4 changed files with 54 additions and 13 deletions

View File

@ -70,6 +70,12 @@ class ClubAccount(models.Model):
return True return True
return False return False
def has_open_journal(self):
for j in self.journals.all():
if not j.closed:
return True
return False
def get_absolute_url(self): def get_absolute_url(self):
return reverse('accounting:club_details', kwargs={'c_account_id': self.id}) return reverse('accounting:club_details', kwargs={'c_account_id': self.id})
@ -143,6 +149,8 @@ class Operation(models.Model):
""" """
if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']):
return True return True
if self.journal.closed:
return False
m = self.journal.club_account.club.get_membership_for(user) m = self.journal.club_account.club.get_membership_for(user)
if m is not None and m.role >= 7: if m is not None and m.role >= 7:
return True return True
@ -152,7 +160,7 @@ class Operation(models.Model):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
""" """
if self.journal.can_be_edited_by(user): if self.is_owned_by(user):
return True return True
return False return False

View File

@ -11,16 +11,41 @@
<li>{{ k }} - {{ v }}</li> <li>{{ k }} - {{ v }}</li>
{% endfor %} {% endfor %}
</ul> </ul>
<p><a href="{{ url('accounting:journal_new') }}?parent={{ object.id }}">New journal</a></p> {% if not object.has_open_journal() %}
<ul> <p><a href="{{ url('accounting:journal_new') }}?parent={{ object.id }}">New journal</a></p>
{% else %}
<p>You can not create new journal while you still have one opened</p>
{% endif %}
<table>
<tr>
<td>Name</td>
<td>Start</td>
<td>End</td>
<td>Amount</td>
<td>Effective amount</td>
<td>Closed</td>
</tr>
{% for j in object.journals.all() %} {% for j in object.journals.all() %}
<li> <tr>
<a href="{{ url('accounting:journal_details', j_id=j.id) }}">{{ j }}</a> - <td>{{ j.name }}</td>
<a href="{{ url('accounting:journal_edit', j_id=j.id) }}">Edit</a> <td>{{ j.start_date }}</td>
{% if j.end_date %}
</li> <td>{{ j.end_date }}</td>
{% else %}
<td> - </td>
{% endif %}
<td>{{ j.amount }} €</td>
<td>{{ j.effective_amount }} €</td>
{% if j.closed %}
<td>Yes</td>
{% else %}
<td>No</td>
{% endif %}
<td> <a href="{{ url('accounting:journal_details', j_id=j.id) }}">View</a>
<a href="{{ url('accounting:journal_edit', j_id=j.id) }}">Edit</a> </td>
</tr>
{% endfor %} {% endfor %}
</ul> </table>
{% endblock %} {% endblock %}

View File

@ -8,7 +8,11 @@
{{ object.name }} {{ object.name }}
</p> </p>
<p><strong>Amount: </strong>{{ object.amount }} € - <strong>Effective amount: </strong>{{ object.effective_amount }} €</p> <p><strong>Amount: </strong>{{ object.amount }} € - <strong>Effective amount: </strong>{{ object.effective_amount }} €</p>
{% if object.closed %}
<p>Journal is closed, you can not create operation</p>
{% else %}
<p><a href="{{ url('accounting:op_new') }}?parent={{ object.id }}">New operation</a></p> <p><a href="{{ url('accounting:op_new') }}?parent={{ object.id }}">New operation</a></p>
{% endif %}
<table> <table>
<tr> <tr>
<td>Nb</td> <td>Nb</td>
@ -16,7 +20,7 @@
<td>Label</td> <td>Label</td>
<td>Amount</td> <td>Amount</td>
<td>Payment mode</td> <td>Payment mode</td>
<!-- <td>Target</td> --> <!-- TODO: <td>Target</td> -->
<td>Code</td> <td>Code</td>
<td>Nature</td> <td>Nature</td>
<td>Done</td> <td>Done</td>
@ -38,7 +42,11 @@
<td>No</td> <td>No</td>
{% endif %} {% endif %}
<td>{{ o.remark }}</td> <td>{{ o.remark }}</td>
<td><a href="{{ url('accounting:op_edit', op_id=o.id) }}">Edit</a></td> <td>
{% if not o.journal.closed %}
<a href="{{ url('accounting:op_edit', op_id=o.id) }}">Edit</a>
{% endif %}
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

View File

@ -153,7 +153,7 @@ class JournalEditView(CanEditMixin, UpdateView):
""" """
model = GeneralJournal model = GeneralJournal
pk_url_kwarg = "j_id" pk_url_kwarg = "j_id"
fields = ['name', 'start_date', 'club_account'] fields = ['name', 'start_date', 'end_date', 'club_account', 'closed']
template_name = 'core/edit.jinja' template_name = 'core/edit.jinja'
# Operation views # Operation views
@ -177,7 +177,7 @@ class OperationCreateView(CanCreateMixin, CreateView):
ret['journal'] = obj.id ret['journal'] = obj.id
return ret return ret
class OperationEditView(CanViewMixin, UpdateView): class OperationEditView(CanEditMixin, UpdateView):
""" """
An edit view, working as detail for the moment An edit view, working as detail for the moment
""" """