Skip to content

Commit

Permalink
Merge pull request #898 from ae-utbm/taiste
Browse files Browse the repository at this point in the history
Complete webpack migration, introduction of tom select, better SAS moderation workflow, more ruff and bugfixes
  • Loading branch information
imperosol authored Oct 18, 2024
2 parents 19e21c8 + b9cbba2 commit e6f25fb
Show file tree
Hide file tree
Showing 132 changed files with 3,709 additions and 2,433 deletions.
11 changes: 10 additions & 1 deletion accounting/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@

from django.contrib import admin

from accounting.models import *
from accounting.models import (
AccountingType,
BankAccount,
ClubAccount,
Company,
GeneralJournal,
Label,
Operation,
SimplifiedAccountingType,
)

admin.site.register(BankAccount)
admin.site.register(ClubAccount)
Expand Down
45 changes: 11 additions & 34 deletions accounting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ def get_display_name(self):

def is_owned_by(self, user):
"""Check if that object can be edited by the given user."""
if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True
return False
return user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID)

def can_be_edited_by(self, user):
"""Check if that object can be edited by the given user."""
Expand Down Expand Up @@ -127,9 +125,7 @@ def is_owned_by(self, user):
if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True
m = self.club.get_membership_for(user)
if m is not None and m.role >= settings.SITH_CLUB_ROLES_ID["Treasurer"]:
return True
return False
return m is not None and m.role >= settings.SITH_CLUB_ROLES_ID["Treasurer"]


class ClubAccount(models.Model):
Expand Down Expand Up @@ -161,29 +157,20 @@ def is_owned_by(self, user):
"""Check if that object can be edited by the given user."""
if user.is_anonymous:
return False
if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True
return False
return user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID)

def can_be_edited_by(self, user):
"""Check if that object can be edited by the given user."""
m = self.club.get_membership_for(user)
if m and m.role == settings.SITH_CLUB_ROLES_ID["Treasurer"]:
return True
return False
return m and m.role == settings.SITH_CLUB_ROLES_ID["Treasurer"]

def can_be_viewed_by(self, user):
"""Check if that object can be viewed by the given user."""
m = self.club.get_membership_for(user)
if m and m.role >= settings.SITH_CLUB_ROLES_ID["Treasurer"]:
return True
return False
return m and m.role >= settings.SITH_CLUB_ROLES_ID["Treasurer"]

def has_open_journal(self):
for j in self.journals.all():
if not j.closed:
return True
return False
return self.journals.filter(closed=False).exists()

def get_open_journal(self):
return self.journals.filter(closed=False).first()
Expand Down Expand Up @@ -228,17 +215,13 @@ def is_owned_by(self, user):
return False
if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True
if self.club_account.can_be_edited_by(user):
return True
return False
return self.club_account.can_be_edited_by(user)

def can_be_edited_by(self, user):
"""Check if that object can be edited by the given user."""
if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True
if self.club_account.can_be_edited_by(user):
return True
return False
return self.club_account.can_be_edited_by(user)

def can_be_viewed_by(self, user):
return self.club_account.can_be_viewed_by(user)
Expand Down Expand Up @@ -416,9 +399,7 @@ def is_owned_by(self, user):
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
return m is not None and m.role >= settings.SITH_CLUB_ROLES_ID["Treasurer"]

def can_be_edited_by(self, user):
"""Check if that object can be edited by the given user."""
Expand All @@ -427,9 +408,7 @@ def can_be_edited_by(self, user):
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
return m is not None and m.role == settings.SITH_CLUB_ROLES_ID["Treasurer"]


class AccountingType(models.Model):
Expand Down Expand Up @@ -472,9 +451,7 @@ def is_owned_by(self, user):
"""Check if that object can be edited by the given user."""
if user.is_anonymous:
return False
if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True
return False
return user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID)


class SimplifiedAccountingType(models.Model):
Expand Down
6 changes: 3 additions & 3 deletions accounting/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def setUp(self):
code="443", label="Ce code n'existe pas", movement_type="CREDIT"
)
at.save()
l = Label.objects.create(club_account=self.journal.club_account, name="bob")
label = Label.objects.create(club_account=self.journal.club_account, name="bob")
self.client.force_login(User.objects.get(username="comptable"))
self.op1 = Operation(
journal=self.journal,
Expand All @@ -111,7 +111,7 @@ def setUp(self):
remark="Test bilan",
mode="CASH",
done=True,
label=l,
label=label,
accounting_type=at,
target_type="USER",
target_id=self.skia.id,
Expand All @@ -124,7 +124,7 @@ def setUp(self):
remark="Test bilan",
mode="CASH",
done=True,
label=l,
label=label,
accounting_type=at,
target_type="USER",
target_id=self.skia.id,
Expand Down
36 changes: 35 additions & 1 deletion accounting/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,41 @@

from django.urls import path

from accounting.views import *
from accounting.views import (
AccountingTypeCreateView,
AccountingTypeEditView,
AccountingTypeListView,
BankAccountCreateView,
BankAccountDeleteView,
BankAccountDetailView,
BankAccountEditView,
BankAccountListView,
ClubAccountCreateView,
ClubAccountDeleteView,
ClubAccountDetailView,
ClubAccountEditView,
CompanyCreateView,
CompanyEditView,
CompanyListView,
JournalAccountingStatementView,
JournalCreateView,
JournalDeleteView,
JournalDetailView,
JournalEditView,
JournalNatureStatementView,
JournalPersonStatementView,
LabelCreateView,
LabelDeleteView,
LabelEditView,
LabelListView,
OperationCreateView,
OperationEditView,
OperationPDFView,
RefoundAccountView,
SimplifiedAccountingTypeCreateView,
SimplifiedAccountingTypeEditView,
SimplifiedAccountingTypeListView,
)

urlpatterns = [
# Accounting types
Expand Down
35 changes: 15 additions & 20 deletions accounting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class ClubAccountCreateView(CanCreateMixin, CreateView):

def get_initial(self):
ret = super().get_initial()
if "parent" in self.request.GET.keys():
if "parent" in self.request.GET:
obj = BankAccount.objects.filter(id=int(self.request.GET["parent"])).first()
if obj is not None:
ret["bank_account"] = obj.id
Expand Down Expand Up @@ -264,7 +264,7 @@ class JournalCreateView(CanCreateMixin, CreateView):

def get_initial(self):
ret = super().get_initial()
if "parent" in self.request.GET.keys():
if "parent" in self.request.GET:
obj = ClubAccount.objects.filter(id=int(self.request.GET["parent"])).first()
if obj is not None:
ret["club_account"] = obj.id
Expand Down Expand Up @@ -362,7 +362,7 @@ def __init__(self, *args, **kwargs):

def clean(self):
self.cleaned_data = super().clean()
if "target_type" in self.cleaned_data.keys():
if "target_type" in self.cleaned_data:
if (
self.cleaned_data.get("user") is None
and self.cleaned_data.get("club") is None
Expand Down Expand Up @@ -633,19 +633,17 @@ def statement(self, queryset, movement_type):
ret = collections.OrderedDict()
statement = collections.OrderedDict()
total_sum = 0
for sat in [None] + list(
SimplifiedAccountingType.objects.order_by("label").all()
):
for sat in [
None,
*list(SimplifiedAccountingType.objects.order_by("label")),
]:
amount = queryset.filter(
accounting_type__movement_type=movement_type, simpleaccounting_type=sat
).aggregate(amount_sum=Sum("amount"))["amount_sum"]
if sat:
sat = sat.label
else:
sat = ""
label = sat.label if sat is not None else ""
if amount:
total_sum += amount
statement[sat] = amount
statement[label] = amount
ret[movement_type] = statement
ret[movement_type + "_sum"] = total_sum
return ret
Expand All @@ -668,15 +666,12 @@ def big_statement(self):
self.statement(self.object.operations.filter(label=None).all(), "DEBIT")
)
statement[_("No label operations")] = no_label_statement
for l in labels:
for label in labels:
l_stmt = collections.OrderedDict()
l_stmt.update(
self.statement(self.object.operations.filter(label=l).all(), "CREDIT")
)
l_stmt.update(
self.statement(self.object.operations.filter(label=l).all(), "DEBIT")
)
statement[l] = l_stmt
journals = self.object.operations.filter(label=label).all()
l_stmt.update(self.statement(journals, "CREDIT"))
l_stmt.update(self.statement(journals, "DEBIT"))
statement[label] = l_stmt
return statement

def get_context_data(self, **kwargs):
Expand Down Expand Up @@ -798,7 +793,7 @@ class LabelCreateView(

def get_initial(self):
ret = super().get_initial()
if "parent" in self.request.GET.keys():
if "parent" in self.request.GET:
obj = ClubAccount.objects.filter(id=int(self.request.GET["parent"])).first()
if obj is not None:
ret["club_account"] = obj.id
Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"files": {
"ignoreUnknown": false,
"ignore": ["core/static/vendored", "*.min.*", "staticfiles/generated"]
"ignore": ["*.min.*", "staticfiles/generated"]
},
"formatter": {
"enabled": true,
Expand Down
6 changes: 3 additions & 3 deletions club/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def clean_subscription_users(self):
"""Convert given users into real users and check their validity."""
cleaned_data = super().clean()
users = []
for user in cleaned_data["subscription_users"]:
user = User.objects.filter(id=user).first()
for user_id in cleaned_data["subscription_users"]:
user = User.objects.filter(id=user_id).first()
if not user:
raise forms.ValidationError(
_("One of the selected users doesn't exist"), code="invalid"
Expand All @@ -128,7 +128,7 @@ def clean_subscription_users(self):
def clean(self):
cleaned_data = super().clean()

if not "action" in cleaned_data:
if "action" not in cleaned_data:
# If there is no action provided, we can stop here
raise forms.ValidationError(_("An action is required"), code="invalid")

Expand Down
4 changes: 1 addition & 3 deletions club/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,7 @@ def can_be_edited_by(self, user: User) -> bool:
if user.is_root or user.is_board_member:
return True
membership = self.club.get_membership_for(user)
if membership is not None and membership.role >= self.role:
return True
return False
return membership is not None and membership.role >= self.role

def delete(self, *args, **kwargs):
super().delete(*args, **kwargs)
Expand Down
Loading

0 comments on commit e6f25fb

Please sign in to comment.