Skip to content

Commit

Permalink
Merge pull request #714 from ae-utbm/taiste
Browse files Browse the repository at this point in the history
More ruff rules, mistune update and more bot-blocking features
  • Loading branch information
imperosol authored Jul 11, 2024
2 parents 44c8558 + c9e398b commit b852176
Show file tree
Hide file tree
Showing 276 changed files with 2,449 additions and 2,549 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.10
rev: v0.5.1
hooks:
- id: ruff # just check the code, and print the errors
- id: ruff # actually fix the fixable errors, but print nothing
Expand Down
1 change: 0 additions & 1 deletion accounting/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# [email protected] / [email protected]
Expand Down
1 change: 0 additions & 1 deletion accounting/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# [email protected] / [email protected]
Expand Down
1 change: 0 additions & 1 deletion accounting/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import django.core.validators
Expand Down
3 changes: 1 addition & 2 deletions accounting/migrations/0002_auto_20160824_2152.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import django.db.models.deletion
Expand Down Expand Up @@ -101,6 +100,6 @@ class Migration(migrations.Migration):
),
),
migrations.AlterUniqueTogether(
name="operation", unique_together=set([("number", "journal")])
name="operation", unique_together={("number", "journal")}
),
]
1 change: 0 additions & 1 deletion accounting/migrations/0003_auto_20160824_2203.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import phonenumber_field.modelfields
Expand Down
3 changes: 1 addition & 2 deletions accounting/migrations/0004_auto_20161005_1505.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import django.db.models.deletion
Expand Down Expand Up @@ -46,6 +45,6 @@ class Migration(migrations.Migration):
),
),
migrations.AlterUniqueTogether(
name="label", unique_together=set([("name", "club_account")])
name="label", unique_together={("name", "club_account")}
),
]
1 change: 0 additions & 1 deletion accounting/migrations/0005_auto_20170324_0917.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
Expand Down
123 changes: 57 additions & 66 deletions accounting/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# [email protected] / [email protected]
Expand Down Expand Up @@ -37,11 +36,11 @@ class CurrencyField(models.DecimalField):
def __init__(self, *args, **kwargs):
kwargs["max_digits"] = 12
kwargs["decimal_places"] = 2
super(CurrencyField, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def to_python(self, value):
try:
return super(CurrencyField, self).to_python(value).quantize(Decimal("0.01"))
return super().to_python(value).quantize(Decimal("0.01"))
except AttributeError:
return None

Expand All @@ -62,6 +61,15 @@ class Company(models.Model):
class Meta:
verbose_name = _("company")

def __str__(self):
return self.name

def get_absolute_url(self):
return reverse("accounting:co_edit", kwargs={"co_id": self.id})

def get_display_name(self):
return self.name

def is_owned_by(self, user):
"""
Method to see if that object can be edited by the given user
Expand All @@ -88,15 +96,6 @@ def can_be_viewed_by(self, user):
return True
return False

def get_absolute_url(self):
return reverse("accounting:co_edit", kwargs={"co_id": self.id})

def get_display_name(self):
return self.name

def __str__(self):
return self.name


class BankAccount(models.Model):
name = models.CharField(_("name"), max_length=30)
Expand All @@ -113,6 +112,12 @@ class Meta:
verbose_name = _("Bank account")
ordering = ["club", "name"]

def __str__(self):
return self.name

def get_absolute_url(self):
return reverse("accounting:bank_details", kwargs={"b_account_id": self.id})

def is_owned_by(self, user):
"""
Method to see if that object can be edited by the given user
Expand All @@ -126,12 +131,6 @@ def is_owned_by(self, user):
return True
return False

def get_absolute_url(self):
return reverse("accounting:bank_details", kwargs={"b_account_id": self.id})

def __str__(self):
return self.name


class ClubAccount(models.Model):
name = models.CharField(_("name"), max_length=30)
Expand All @@ -152,6 +151,12 @@ class Meta:
verbose_name = _("Club account")
ordering = ["bank_account", "name"]

def __str__(self):
return self.name

def get_absolute_url(self):
return reverse("accounting:club_details", kwargs={"c_account_id": self.id})

def is_owned_by(self, user):
"""
Method to see if that object can be edited by the given user
Expand Down Expand Up @@ -189,12 +194,6 @@ def has_open_journal(self):
def get_open_journal(self):
return self.journals.filter(closed=False).first()

def get_absolute_url(self):
return reverse("accounting:club_details", kwargs={"c_account_id": self.id})

def __str__(self):
return self.name

def get_display_name(self):
return _("%(club_account)s on %(bank_account)s") % {
"club_account": self.name,
Expand Down Expand Up @@ -225,6 +224,12 @@ class Meta:
verbose_name = _("General journal")
ordering = ["-start_date"]

def __str__(self):
return self.name

def get_absolute_url(self):
return reverse("accounting:journal_details", kwargs={"j_id": self.id})

def is_owned_by(self, user):
"""
Method to see if that object can be edited by the given user
Expand All @@ -250,12 +255,6 @@ def can_be_edited_by(self, user):
def can_be_viewed_by(self, user):
return self.club_account.can_be_viewed_by(user)

def get_absolute_url(self):
return reverse("accounting:journal_details", kwargs={"j_id": self.id})

def __str__(self):
return self.name

def update_amounts(self):
self.amount = 0
self.effective_amount = 0
Expand Down Expand Up @@ -357,14 +356,26 @@ class Meta:
unique_together = ("number", "journal")
ordering = ["-number"]

def __str__(self):
return f"{self.amount} € | {self.date} | {self.accounting_type} | {self.done}"

def save(self, *args, **kwargs):
if self.number is None:
self.number = self.journal.operations.count() + 1
super().save(*args, **kwargs)
self.journal.update_amounts()

def get_absolute_url(self):
return reverse("accounting:journal_details", kwargs={"j_id": self.journal.id})

def __getattribute__(self, attr):
if attr == "target":
return self.get_target()
else:
return object.__getattribute__(self, attr)

def clean(self):
super(Operation, self).clean()
super().clean()
if self.date is None:
raise ValidationError(_("The date must be set."))
elif self.date < self.journal.start_date:
Expand Down Expand Up @@ -410,12 +421,6 @@ def get_target(self):
tar = Company.objects.filter(id=self.target_id).first()
return tar

def save(self):
if self.number is None:
self.number = self.journal.operations.count() + 1
super(Operation, self).save()
self.journal.update_amounts()

def is_owned_by(self, user):
"""
Method to see if that object can be edited by the given user
Expand Down Expand Up @@ -444,17 +449,6 @@ def can_be_edited_by(self, user):
return True
return False

def get_absolute_url(self):
return reverse("accounting:journal_details", kwargs={"j_id": self.journal.id})

def __str__(self):
return "%d € | %s | %s | %s" % (
self.amount,
self.date,
self.accounting_type,
self.done,
)


class AccountingType(models.Model):
"""
Expand Down Expand Up @@ -487,6 +481,12 @@ class Meta:
verbose_name = _("accounting type")
ordering = ["movement_type", "code"]

def __str__(self):
return self.code + " - " + self.get_movement_type_display() + " - " + self.label

def get_absolute_url(self):
return reverse("accounting:type_list")

def is_owned_by(self, user):
"""
Method to see if that object can be edited by the given user
Expand All @@ -497,12 +497,6 @@ def is_owned_by(self, user):
return True
return False

def get_absolute_url(self):
return reverse("accounting:type_list")

def __str__(self):
return self.code + " - " + self.get_movement_type_display() + " - " + self.label


class SimplifiedAccountingType(models.Model):
"""
Expand All @@ -521,25 +515,22 @@ class Meta:
verbose_name = _("simplified type")
ordering = ["accounting_type__movement_type", "accounting_type__code"]

def __str__(self):
return (
f"{self.get_movement_type_display()} "
f"- {self.accounting_type.code} - {self.label}"
)

def get_absolute_url(self):
return reverse("accounting:simple_type_list")

@property
def movement_type(self):
return self.accounting_type.movement_type

def get_movement_type_display(self):
return self.accounting_type.get_movement_type_display()

def get_absolute_url(self):
return reverse("accounting:simple_type_list")

def __str__(self):
return (
self.get_movement_type_display()
+ " - "
+ self.accounting_type.code
+ " - "
+ self.label
)


class Label(models.Model):
"""Label allow a club to sort its operations"""
Expand Down
1 change: 0 additions & 1 deletion accounting/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# [email protected] / [email protected]
Expand Down
1 change: 0 additions & 1 deletion accounting/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# [email protected] / [email protected]
Expand Down
Loading

0 comments on commit b852176

Please sign in to comment.