Commit 50efc07e authored by Skia's avatar Skia
Browse files

Add basic close journal functions

parent e9544f25
......@@ -70,6 +70,12 @@ class ClubAccount(models.Model):
return True
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):
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']):
return True
if self.journal.closed:
return False
m = self.journal.club_account.club.get_membership_for(user)
if m is not None and m.role >= 7:
return True
......@@ -152,7 +160,7 @@ class Operation(models.Model):
"""
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 False
......
......@@ -11,16 +11,41 @@
<li>{{ k }} - {{ v }}</li>
{% endfor %}
</ul>
<p><a href="{{ url('accounting:journal_new') }}?parent={{ object.id }}">New journal</a></p>
<ul>
{% if not object.has_open_journal() %}
<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() %}
<li>
<a href="{{ url('accounting:journal_details', j_id=j.id) }}">{{ j }}</a> -
<a href="{{ url('accounting:journal_edit', j_id=j.id) }}">Edit</a>
</li>
<tr>
<td>{{ j.name }}</td>
<td>{{ j.start_date }}</td>
{% if j.end_date %}
<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 %}
</ul>
</table>
{% endblock %}
......
......@@ -8,7 +8,11 @@
{{ object.name }}
</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>
{% endif %}
<table>
<tr>
<td>Nb</td>
......@@ -16,7 +20,7 @@
<td>Label</td>
<td>Amount</td>
<td>Payment mode</td>
<!-- <td>Target</td> -->
<!-- TODO: <td>Target</td> -->
<td>Code</td>
<td>Nature</td>
<td>Done</td>
......@@ -38,7 +42,11 @@
<td>No</td>
{% endif %}
<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>
{% endfor %}
</table>
......
......@@ -153,7 +153,7 @@ class JournalEditView(CanEditMixin, UpdateView):
"""
model = GeneralJournal
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'
# Operation views
......@@ -177,7 +177,7 @@ class OperationCreateView(CanCreateMixin, CreateView):
ret['journal'] = obj.id
return ret
class OperationEditView(CanViewMixin, UpdateView):
class OperationEditView(CanEditMixin, UpdateView):
"""
An edit view, working as detail for the moment
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment