diff --git a/accounting/models.py b/accounting/models.py
index 7338e907..f4ea5c73 100644
--- a/accounting/models.py
+++ b/accounting/models.py
@@ -45,6 +45,32 @@ class Company(models.Model):
class Meta:
verbose_name = _("company")
+ def is_owned_by(self, user):
+ """
+ Method to see if that object can be edited by the given user
+ """
+ if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
+ return True
+ return False
+
+ def can_be_edited_by(self, user):
+ """
+ Method to see if that object can be edited by the given user
+ """
+ for club in user.memberships.filter(end_date=None).all():
+ if club and club.role == settings.SITH_CLUB_ROLES_ID['Treasurer']:
+ return True
+ return False
+
+ def can_be_viewed_by(self, user):
+ """
+ Method to see if that object can be viewed by the given user
+ """
+ for club in user.memberships.filter(end_date=None).all():
+ if club and club.role >= settings.SITH_CLUB_ROLES_ID['Treasurer']:
+ return True
+ return False
+
def get_absolute_url(self):
return reverse('accounting:co_edit', kwargs={'co_id': self.id})
@@ -71,7 +97,7 @@ class BankAccount(models.Model):
if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True
m = self.club.get_membership_for(user)
- if m is not None and m.role >= 7:
+ if m is not None and m.role >= settings.SITH_CLUB_ROLES_ID['Treasurer']:
return True
return False
@@ -103,7 +129,7 @@ class ClubAccount(models.Model):
Method to see if that object can be edited by the given user
"""
m = self.club.get_membership_for(user)
- if m and m.role == 7:
+ if m and m.role == settings.SITH_CLUB_ROLES_ID['Treasurer']:
return True
return False
@@ -112,7 +138,7 @@ class ClubAccount(models.Model):
Method to see if that object can be viewed by the given user
"""
m = self.club.get_membership_for(user)
- if m and m.role >= 7:
+ if m and m.role >= settings.SITH_CLUB_ROLES_ID['Treasurer']:
return True
return False
@@ -161,6 +187,16 @@ class GeneralJournal(models.Model):
return True
return False
+ def can_be_edited_by(self, user):
+ """
+ Method to see if that object can be edited by the given user
+ """
+ if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
+ return True
+ if self.club_account.can_be_edited_by(user):
+ return True
+ return False
+
def can_be_viewed_by(self, user):
return self.club_account.can_be_edited_by(user)
@@ -192,7 +228,7 @@ class Operation(models.Model):
journal = models.ForeignKey(GeneralJournal, related_name="operations", null=False, verbose_name=_("journal"))
amount = CurrencyField(_('amount'))
date = models.DateField(_('date'))
- remark = models.CharField(_('comment'), max_length=128)
+ remark = models.CharField(_('comment'), max_length=128, null=True, blank=True)
mode = models.CharField(_('payment method'), max_length=255, choices=settings.SITH_ACCOUNTING_PAYMENT_METHOD)
cheque_number = models.CharField(_('cheque number'), max_length=32, default="", null=True, blank=True)
invoice = models.ForeignKey(SithFile, related_name='operations', verbose_name=_("invoice"), null=True, blank=True)
@@ -265,7 +301,7 @@ class Operation(models.Model):
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:
+ if m is not None and m.role >= settings.SITH_CLUB_ROLES_ID['Treasurer']:
return True
return False
@@ -273,7 +309,12 @@ class Operation(models.Model):
"""
Method to see if that object can be edited by the given user
"""
- if self.is_owned_by(user):
+ if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
+ 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 == settings.SITH_CLUB_ROLES_ID['Treasurer']:
return True
return False
diff --git a/accounting/templates/accounting/bank_account_details.jinja b/accounting/templates/accounting/bank_account_details.jinja
index 076d2753..cd968322 100644
--- a/accounting/templates/accounting/bank_account_details.jinja
+++ b/accounting/templates/accounting/bank_account_details.jinja
@@ -11,7 +11,7 @@
{% trans %}Bank account: {% endtrans %}{{ object.name }}
- {% if user.is_root and not object.club_accounts.exists() %}
+ {% if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) and not object.club_accounts.exists() %}
{% trans %}Delete{% endtrans %}
{% endif %}
{% trans %}Infos{% endtrans %}
@@ -24,6 +24,9 @@
{% for c in object.club_accounts.all() %}
{{ c }}
- {% trans %}Edit{% endtrans %}
+ {% if c.journals.count() == 0 %}
+ - {% trans %}Delete{% endtrans %}
+ {% endif %}
{% endfor %}
diff --git a/accounting/templates/accounting/club_account_details.jinja b/accounting/templates/accounting/club_account_details.jinja
index 333e3081..08f22c2d 100644
--- a/accounting/templates/accounting/club_account_details.jinja
+++ b/accounting/templates/accounting/club_account_details.jinja
@@ -15,7 +15,9 @@
{% if user.is_root and not object.journals.exists() %}
{% trans %}Delete{% endtrans %}
{% endif %}
+ {% if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) %}
{% trans %}New label{% endtrans %}
+ {% endif %}
{% trans %}Label list{% endtrans %}
{% if not object.has_open_journal() %}
{% trans %}New journal{% endtrans %}
@@ -52,7 +54,11 @@
{% trans %}No{% endtrans %} |
{% endif %}
{% trans %}View{% endtrans %}
- {% trans %}Edit{% endtrans %} |
+ {% trans %}Edit{% endtrans %}
+ {% if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) and j.operations.count() == 0 %}
+ {% trans %}Delete{% endtrans %}
+ {% endif %}
+
{% endfor %}
diff --git a/accounting/templates/accounting/co_list.jinja b/accounting/templates/accounting/co_list.jinja
index 0cfbca70..e40ee2d8 100644
--- a/accounting/templates/accounting/co_list.jinja
+++ b/accounting/templates/accounting/co_list.jinja
@@ -5,7 +5,9 @@
{% endblock %}
{% block content %}
+{% if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) or user.is_root %}
{% trans %}Create new company{% endtrans %}
+{% endif %}
diff --git a/accounting/templates/accounting/journal_details.jinja b/accounting/templates/accounting/journal_details.jinja
index e38dfe7d..6884884d 100644
--- a/accounting/templates/accounting/journal_details.jinja
+++ b/accounting/templates/accounting/journal_details.jinja
@@ -78,9 +78,11 @@
- |
{% endif %}
+ {% if o.journal.club_account.bank_account.name != "AE TI" and journal.club_account.bank_account.name != "TI" or user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) %}
{% if not o.journal.closed %}
{% trans %}Edit{% endtrans %}
{% endif %}
+ {% endif %}
|
{% trans %}Generate{% endtrans %} |
diff --git a/accounting/templates/accounting/label_list.jinja b/accounting/templates/accounting/label_list.jinja
index 9d35701b..9841fba6 100644
--- a/accounting/templates/accounting/label_list.jinja
+++ b/accounting/templates/accounting/label_list.jinja
@@ -12,13 +12,18 @@
{% trans %}Back to club account{% endtrans %}
+ {% if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) %}
{% trans %}New label{% endtrans %}
+ {% endif %}
{% if object.labels.all() %}
{% trans %}Label list{% endtrans %}
diff --git a/accounting/urls.py b/accounting/urls.py
index 3255cb9d..2a3727fa 100644
--- a/accounting/urls.py
+++ b/accounting/urls.py
@@ -26,6 +26,7 @@ urlpatterns = [
url(r'^journal/create$', JournalCreateView.as_view(), name='journal_new'),
url(r'^journal/(?P[0-9]+)$', JournalDetailView.as_view(), name='journal_details'),
url(r'^journal/(?P[0-9]+)/edit$', JournalEditView.as_view(), name='journal_edit'),
+ url(r'^journal/(?P[0-9]+)/delete$', JournalDeleteView.as_view(), name='journal_delete'),
url(r'^journal/(?P[0-9]+)/statement/nature$', JournalNatureStatementView.as_view(), name='journal_nature_statement'),
url(r'^journal/(?P[0-9]+)/statement/person$', JournalPersonStatementView.as_view(), name='journal_person_statement'),
url(r'^journal/(?P[0-9]+)/statement/accounting$', JournalAccountingStatementView.as_view(), name='journal_accounting_statement'),
diff --git a/accounting/views.py b/accounting/views.py
index c50b1f6b..51808632 100644
--- a/accounting/views.py
+++ b/accounting/views.py
@@ -230,6 +230,21 @@ class JournalEditView(CanEditMixin, UpdateView):
fields = ['name', 'start_date', 'end_date', 'club_account', 'closed']
template_name = 'core/edit.jinja'
+class JournalDeleteView(CanEditPropMixin, DeleteView):
+ """
+ Delete a club account (for the admins)
+ """
+ model = GeneralJournal
+ pk_url_kwarg = "j_id"
+ template_name = 'core/delete_confirm.jinja'
+ success_url = reverse_lazy('accounting:club_details')
+
+ def dispatch(self, request, *args, **kwargs):
+ self.object = self.get_object()
+ if self.object.operations.count() == 0:
+ return super(JournalDeleteView, self).dispatch(request, *args, **kwargs)
+ else:
+ raise PermissionDenied
# Operation views
diff --git a/core/views/__init__.py b/core/views/__init__.py
index eaa08760..c0a613bc 100644
--- a/core/views/__init__.py
+++ b/core/views/__init__.py
@@ -4,6 +4,7 @@ from django.shortcuts import render
from django.http import HttpResponseForbidden, HttpResponseNotFound
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist, ImproperlyConfigured
from django.views.generic.base import View
+from django.db.models import Count
from core.models import Group
from core.views.forms import LoginForm
@@ -66,7 +67,7 @@ class CanEditPropMixin(View):
except: pass
# If we get here, it's a ListView
l_id = [o.id for o in self.get_queryset() if can_edit_prop(o, request.user)]
- if not l_id:
+ if not l_id and self.get_queryset().count() != 0:
raise PermissionDenied
self._get_queryset = self.get_queryset
def get_qs(self2):
@@ -88,7 +89,7 @@ class CanEditMixin(View):
except: pass
# If we get here, it's a ListView
l_id = [o.id for o in self.get_queryset() if can_edit(o, request.user)]
- if not l_id:
+ if not l_id and self.get_queryset().count() != 0:
raise PermissionDenied
self._get_queryset = self.get_queryset
def get_qs(self2):
@@ -110,7 +111,7 @@ class CanViewMixin(View):
except: pass
# If we get here, it's a ListView
l_id = [o.id for o in self.get_queryset() if can_view(o, request.user)]
- if not l_id:
+ if not l_id and self.get_queryset().count() != 0:
raise PermissionDenied
self._get_queryset = self.get_queryset
def get_qs(self2):
diff --git a/sith/settings.py b/sith/settings.py
index 86fc473b..042e3114 100644
--- a/sith/settings.py
+++ b/sith/settings.py
@@ -426,17 +426,22 @@ SITH_SUBSCRIPTIONS = {
# To be completed....
}
-SITH_CLUB_ROLES = {
- 10: _('President'),
- 9: _('Vice-President'),
- 7: _('Treasurer'),
- 5: _('Communication supervisor'),
- 4: _('Secretary'),
- 3: _('IT supervisor'),
- 2: _('Board member'),
- 1: _('Active member'),
- 0: _('Curious'),
- }
+SITH_CLUB_ROLES = {}
+
+SITH_CLUB_ROLES_ID = {
+ 'President': 10,
+ 'Vice-President': 9,
+ 'Treasurer': 7,
+ 'Communication supervisor': 5,
+ 'Secretary': 4,
+ 'IT supervisor': 3,
+ 'Board member': 2,
+ 'Active member': 1,
+ 'Curious': 0,
+}
+
+for role in SITH_CLUB_ROLES_ID:
+ SITH_CLUB_ROLES[SITH_CLUB_ROLES_ID[role]] = _(role)
# This corresponds to the maximum role a user can freely subscribe to
# In this case, SITH_MAXIMUM_FREE_ROLE=1 means that a user can set himself as "Membre actif" or "Curieux", but not higher