From 843a9b0c780614368afdf872d634b699e7f537dc Mon Sep 17 00:00:00 2001 From: Trullemans Gregory Date: Fri, 21 Feb 2020 08:50:12 +0100 Subject: [PATCH] [WIP] Improve code lisibility. --- src/comptaClub/settings.py | 8 +- src/comptabilite/compta_tools.py | 119 ++++++----- .../management/commands/importcsv.py | 4 +- src/comptabilite/models.py | 4 +- src/comptabilite/urls.py | 14 +- src/comptabilite/views.py | 191 +++++++++--------- src/templates/compta.html | 2 +- src/templates/event_transaction_listing.html | 2 +- src/templates/transaction_listing.html | 6 +- src/templates/year_listing.html | 12 +- .../year_transaction_export_ooo.html | 10 +- .../year_transaction_export_spf.html | 10 +- .../year_transaction_export_sxs.html | 38 ++-- src/templates/year_transaction_listing.html | 8 +- src/tests/test_comptabilite_forms.py | 1 - src/tests/test_comptabilite_models.py | 9 +- src/tests/test_comptabilite_utils.py | 4 +- 17 files changed, 231 insertions(+), 211 deletions(-) diff --git a/src/comptaClub/settings.py b/src/comptaClub/settings.py index 11e0210..a44ce23 100644 --- a/src/comptaClub/settings.py +++ b/src/comptaClub/settings.py @@ -46,7 +46,7 @@ ROOT_URLCONF = "comptaClub.urls" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [os.path.join(BASE_DIR, "templates"), ], + "DIRS": [os.path.join(BASE_DIR, "templates"),], "APP_DIRS": True, "OPTIONS": { "context_processors": [ @@ -81,9 +81,9 @@ AUTH_PASSWORD_VALIDATORS = [ { "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", }, - {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", }, - {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", }, - {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", }, + {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",}, + {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",}, + {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",}, ] diff --git a/src/comptabilite/compta_tools.py b/src/comptabilite/compta_tools.py index 7ce52ff..8bd62d6 100644 --- a/src/comptabilite/compta_tools.py +++ b/src/comptabilite/compta_tools.py @@ -13,7 +13,7 @@ from .models import ( from .utils import zero_or_value -def get_transaction_and_sum_for_year_and_type(year, transaction_type_id): +def get_transactions_and_sums_for_year_and_type(accounting_year, transaction_type_id): """ Récupère les transactions associées à une date et un type et additionne les valeurs obtenues. @@ -25,7 +25,7 @@ def get_transaction_and_sum_for_year_and_type(year, transaction_type_id): dict """ transaction_list = ( - Transaction.objects.filter(registrationDate__year=year) + Transaction.objects.filter(registrationDate__year=accounting_year) .filter(transaction_type__transaction_type=transaction_type_id) .order_by("registrationDate") ) @@ -46,7 +46,7 @@ def get_transaction_and_sum_for_year_and_type(year, transaction_type_id): } -def get_totalamount_sum_value(year, transaction_type): +def get_transactions_totalamount_sum_value(accounting_year, transaction_type): """ Récupère les transactions associées à une date et un type et additionne le montant total des records obtenus. @@ -58,45 +58,47 @@ def get_totalamount_sum_value(year, transaction_type): Returns: (int): somme totale """ - return zero_or_value(list( + return zero_or_value( + list( Transaction.objects.filter( - registrationDate__year=year, + registrationDate__year=accounting_year, transaction_type=transaction_type, is_simulated=False, is_done=True, ) .aggregate(Sum("totalAmount")) .values() - )[0]) + )[0] + ) -def get_transaction_and_sum_sxs(year, transaction_type_id): +def get_transactiontypes_and_total_amount_transactions(accounting_year, transactiontype_id): """ Récupère tous les types de transactions qui existent pour, pour chacun d'eux récupère toutes les transactions qui sont `effectuées` et non `simulées` et va additionner les montants totaux par type de transaction. Args: - year (int): année + accounting_year (int): année transaction_type_id (int): type de transaction Returns: - (int): somme totale + (dict): ensemble des types de transaction et somme totale """ i = 0 - total_transaction = 0 - transactions_list = [] - transaction_type_list = TransactionType.objects.filter( - transaction_type=transaction_type_id, parent=None + total_transactions_value = 0 + transactiontypes_info_list = [] + transactiontypes_list = TransactionType.objects.filter( + transaction_type=transactiontype_id, parent=None ).order_by("order") - for transaction_type in transaction_type_list: + for transaction_type in transactiontypes_list: j = 0 - sum_value = get_totalamount_sum_value(year, transaction_type) - total_transaction += sum_value - transactions_list.append( + sum_value = get_transactions_totalamount_sum_value(accounting_year, transaction_type) + total_transactions_value += sum_value + transactiontypes_info_list.append( { "label": transaction_type.label, "category": transaction_type.category, @@ -106,14 +108,14 @@ def get_transaction_and_sum_sxs(year, transaction_type_id): } ) - transaction_subtype = TransactionType.objects.filter( + transactiontype_subtype = TransactionType.objects.filter( parent=transaction_type ).order_by("order") - for subtype in transaction_subtype: - subtype_sum_value = get_totalamount_sum_value(year, subtype) + for subtype in transactiontype_subtype: + subtype_sum_value = get_transactions_totalamount_sum_value(accounting_year, subtype) - transactions_list.append( + transactiontypes_info_list.append( { "label": subtype.label, "category": subtype.category, @@ -123,26 +125,27 @@ def get_transaction_and_sum_sxs(year, transaction_type_id): } ) - transactions_list[i]["total_transactions_value"] += subtype_sum_value + transactiontypes_info_list[i]["total_transactions_value"] += subtype_sum_value j += 1 i += j + 1 - return {"sum": transactions_list, "total": total_transaction} + return {"transactiontypes_info_list": transactiontypes_info_list, "total": total_transactions_value} -def get_transaction_and_sum_for_spf_export(year, transaction_type_id): +def get_transactiontype_and_sum_for_spf_export(accounting_year, transaction_type_id): """ - Récupère tous les types de transactions sans parents pour une année et un type donnés. Ensuite, pour chacun d'eux elle va sélectionner toutes les - transactions qui sont `effectuées` et `non simulées` appartenant à ce type de transactions et - va ensuite additionner les montants totaux du type de transaction. + Récupère tous les types de transactions sans parents pour une année et un type donnés. Ensuite, + pour chacun d'eux elle va sélectionner toutes les transactions qui sont `effectuées` et `non + simulées` appartenant à ce type de transactions et va ensuite additionner les montants totaux + du type de transaction. Args: year (int): année transaction_type_id (int): type de transaction Returns: - (int): somme totale + (dict): ensemble des types de transaction et somme totale """ transaction_type_info = [] @@ -152,19 +155,21 @@ def get_transaction_and_sum_for_spf_export(year, transaction_type_id): for transaction_type in transaction_type_list: # Somme du père - sum_value = get_totalamount_sum_value(year, transaction_type) + sum_value = get_transactions_totalamount_sum_value(accounting_year, transaction_type) # Selection des fils - sum_value += zero_or_value(list( - Transaction.objects.filter( - registrationDate__year=year, - transaction_type__parent=transaction_type, - is_simulated=False, - is_done=True, - ) - .aggregate(Sum("totalAmount")) - .values() - )[0]) + sum_value += zero_or_value( + list( + Transaction.objects.filter( + registrationDate__year=accounting_year, + transaction_type__parent=transaction_type, + is_simulated=False, + is_done=True, + ) + .aggregate(Sum("totalAmount")) + .values() + )[0] + ) transaction_type_info.append( [ @@ -176,20 +181,22 @@ def get_transaction_and_sum_for_spf_export(year, transaction_type_id): sum_total_transaction = 0 for transaction_type in transaction_type_info: - # if transaction[1] is not None: sum_total_transaction += transaction_type[1] - return {"sum": transaction_type_info, "sum_total_transaction": sum_total_transaction} + return { + "sum": transaction_type_info, + "sum_total_transaction": sum_total_transaction, + } -def get_right_engagement_and_sump_spf(year, category): +def get_right_engagement_and_sump_spf(accounting_year, category): """ Récupère tous les types de droits et d'engagements et l'ensemble lignes correspondantes et additionne les montants. Args: year (int): année - category (int): ??? + category (int): choix de la catégorie (i.e. "droits" ou "engagements") Returns: (int): somme totale @@ -202,39 +209,45 @@ def get_right_engagement_and_sump_spf(year, category): for right_engagement in right_engagement_list: tmp = list( - RightEngagement.objects.filter(registrationDate__year=year, r_e_type=right_engagement) + RightEngagement.objects.filter( + registrationDate__year=accounting_year, r_e_type=right_engagement + ) .aggregate(Sum("amount")) .values() )[0] - right_engagement_info.append([right_engagement.label, tmp if tmp is not None else Decimal(0.00)]) + right_engagement_info.append( + [right_engagement.label, tmp if tmp is not None else Decimal(0.00)] + ) return right_engagement_info -def get_asset_liability_and_sump_spf(year, category): +def get_asset_liability_and_sump_spf(accounting_year, category): """ Récupère tous les types de droits et dettes. Pour chacun de ces types, va chercher - l'ensemble lignes correspondantes et sommes les montants. + l'ensemble lignes correspondantes et additionne les montants. Args: year (int): année - category (int): ??? + category (int): choix de la catégorie (i.e. "droits" ou "engagements") Returns: (int): somme totale """ - asset_info = [] + asset_liability_info = [] asset_liability_list = PatrimonyType.objects.filter(category=category).order_by( "order" ) - for line in asset_liability_list: + for item in asset_liability_list: tmp = list( - Patrimony.objects.filter(registrationDate__year=year, patrimony_type=line) + Patrimony.objects.filter(registrationDate__year=accounting_year, patrimony_type=item) .aggregate(Sum("totalAmount")) .values() )[0] - asset_info.append([line.label, tmp if tmp is not None else Decimal(0.00)]) + asset_liability_info.append( + [item.label, tmp if tmp is not None else Decimal(0.00)] + ) - return asset_info + return asset_liability_info diff --git a/src/comptabilite/management/commands/importcsv.py b/src/comptabilite/management/commands/importcsv.py index 3536913..d11d050 100644 --- a/src/comptabilite/management/commands/importcsv.py +++ b/src/comptabilite/management/commands/importcsv.py @@ -53,7 +53,9 @@ class Command(BaseCommand): # records_added += 1 if options["bank"] == "crelan" or options["bank"] == "keytrade": - records_added, error_list = import_csv_transaction(options["file"], options["bank"]) + records_added, error_list = import_csv_transaction( + options["file"], options["bank"] + ) print("%s transactions ont été importées" % records_added) for error in error_list: print(error) diff --git a/src/comptabilite/models.py b/src/comptabilite/models.py index e237585..ad18333 100644 --- a/src/comptabilite/models.py +++ b/src/comptabilite/models.py @@ -305,7 +305,7 @@ class RightEngagementType(models.Model): "label", ] - RIGHT_ENGAGEMENT_TYPE_CHOICE = ( + CATEGORY_CHOICE = ( (0, "Droit"), (1, "Engagement"), ) @@ -321,7 +321,7 @@ class RightEngagementType(models.Model): order = models.IntegerField() label = models.CharField(max_length=255) - category = models.IntegerField(choices=RIGHT_ENGAGEMENT_TYPE_CHOICE) + category = models.IntegerField(choices=CATEGORY_CHOICE) RightEngagementType_type = models.IntegerField(choices=TYPE_CHOICE) def __str__(self): diff --git a/src/comptabilite/urls.py b/src/comptabilite/urls.py index c0ba631..818e018 100644 --- a/src/comptabilite/urls.py +++ b/src/comptabilite/urls.py @@ -17,36 +17,36 @@ app_name = "annualcomptability" urlpatterns = [ url(r"^$", year_listing, name="year_listing"), url( - r"^listing/(?P[0-9]{4})/(?P[A-Za-z]+)$", + r"^listing/(?P[0-9]{4})/(?P[A-Za-z]+)$", transaction_by_year_listing, name="by_year_bank", ), url( - r"^listing/(?P[0-9]{4})/(?P[A-Za-z]+)$", + r"^listing/(?P[0-9]{4})/(?P[A-Za-z]+)$", transaction_by_year_listing, name="by_year_box", ), url( - r"^listing/(?P[0-9]{4})/(?P[0-9]+)$", + r"^listing/(?P[0-9]{4})/(?P[0-9]+)$", transaction_listing_for_year_and_type, name="transaction_listing_for_year_and_type", ), # http://127.0.0.1:8000/comptability/annual/listing/2017/3 - url(r"^listing/(?P[0-9]{4})$", transaction_by_year_listing, name="by_year"), + url(r"^listing/(?P[0-9]{4})$", transaction_by_year_listing, name="by_year"), url( r"^details/(?P[0-9]+)", transaction_details, name="compta_details", ), url( - r"^export/simple/(?P[0-9]{4})$", + r"^export/simple/(?P[0-9]{4})$", export_year_spf_finance, name="export_simple", ), url( - r"^export/(?P[0-9]{4})/(?P\w+)$", + r"^export/(?P[0-9]{4})/(?P\w+)$", comptability_export, name="export", ), - url(r"^export/pdf/(?P[0-9]{4})/", generate_pdf_for_spf, name="pdf_export"), + url(r"^export/pdf/(?P[0-9]{4})/", generate_pdf_for_spf, name="pdf_export"), ] diff --git a/src/comptabilite/views.py b/src/comptabilite/views.py index ac69585..1ea7da7 100644 --- a/src/comptabilite/views.py +++ b/src/comptabilite/views.py @@ -21,9 +21,9 @@ from .models import ( ) from .compta_tools import ( - get_transaction_and_sum_for_year_and_type, - get_transaction_and_sum_sxs, - get_transaction_and_sum_for_spf_export, + get_transactions_and_sums_for_year_and_type, + get_transactiontypes_and_total_amount_transactions, + get_transactiontype_and_sum_for_spf_export, get_right_engagement_and_sump_spf, get_asset_liability_and_sump_spf, ) @@ -33,7 +33,7 @@ from comptaClub.site_config import load import locale -def comptability_export(request, year, export_type): +def comptability_export(request, accounting_year, export_type): """ Définit une fonction d'export. @@ -46,47 +46,51 @@ def comptability_export(request, year, export_type): render_to_response sur la page HTML correspondante. """ if export_type == "sxs": - return export_year_sxs(request, year) + return export_year_sxs(request, accounting_year) else: - return export_year_ooo(request, year) + return export_year_ooo(request, accounting_year) -def export_year_ooo(request, year): +def export_year_ooo(request, accounting_year): """ Affichage et calcul des `Recettes` et `Dépenses` pour une année donnée dans deux tableaux l'un au dessus de l'autre (one over other - ooo). """ - transactions_list_expenses = get_transaction_and_sum_for_year_and_type(year, 0) - transactions_list_recettes = get_transaction_and_sum_for_year_and_type(year, 1) + transactions_list_expenses = get_transactions_and_sums_for_year_and_type(accounting_year, 0) + transactions_list_recettes = get_transactions_and_sums_for_year_and_type(accounting_year, 1) context = { "compta_expenses": transactions_list_expenses, - "year": year, + "accounting_year": accounting_year, "compta_recettes": transactions_list_recettes, } return render(request, "year_transaction_export_ooo.html", context) -def export_year_sxs(request, year): +#def two_table_side_by_side_export(request, accounting_year): +def export_year_sxs(request, accounting_year): """ Calcule et affiche la comptabilité d'une année passée en parametre dans un unique tableau (side by side). """ - transactions_list_expenses = get_transaction_and_sum_sxs(year, 0) - transactions_list_recettes = get_transaction_and_sum_sxs(year, 1) + expenses_transactions_list = get_transactiontypes_and_total_amount_transactions(accounting_year, 0) + recettes_transactions_list = get_transactiontypes_and_total_amount_transactions(accounting_year, 1) - transactions_list = zip_longest(transactions_list_recettes["sum"], transactions_list_expenses["sum"]) + transactiontypes_list = zip_longest( + recettes_transactions_list["transactiontypes_info_list"], + expenses_transactions_list["transactiontypes_info_list"] + ) context = { - "transactions_list": transactions_list, - "year": year, - "total_depense": transactions_list_expenses["total"], - "total_recette": transactions_list_recettes["total"], + "transactiontypes_list": transactiontypes_list, + "accounting_year": accounting_year, + "total_expenses": expenses_transactions_list["total"], + "total_recettes": recettes_transactions_list["total"], } return render(request, "year_transaction_export_sxs.html", context) -def export_year_spf_finance(request, year): +def export_year_spf_finance(request, accounting_year): """ Calcule et affiche la comptabilité d'une année passée en parametre dans un unique tableau (side by side). @@ -94,44 +98,47 @@ def export_year_spf_finance(request, year): La fonction va chercher chaque type de dépenses/recettes père (n'ayant pas de parent). Pour chacun de ces types, … <<< on fait quoi >>> ? """ - annuality = Annuality.objects.filter(year__year=year) + annuality = Annuality.objects.filter(year__year=accounting_year) # print(annuality[0].opening_balance) - transactions_list_expenses = get_transaction_and_sum_for_spf_export(year, 0) - transactions_list_recettes = get_transaction_and_sum_for_spf_export(year, 1) + transactiontypes_list_expenses = get_transactiontype_and_sum_for_spf_export(accounting_year, 0) + transactiontypes_list_recettes = get_transactiontype_and_sum_for_spf_export(accounting_year, 1) list_sum = [ - x for x in zip_longest(transactions_list_recettes["sum"], transactions_list_expenses["sum"]) + x + for x in zip_longest( + transactiontypes_list_recettes["sum"], transactiontypes_list_expenses["sum"] + ) ] # règle d'évaluation rules_list = EvaluationRules.objects.filter( - Q(stop_date__year__lte=year) | Q(stop_date__isnull=True) - ).exclude(start_date__year__gt=year) + Q(stop_date__year__lte=accounting_year) | Q(stop_date__isnull=True) + ).exclude(start_date__year__gt=accounting_year) rules_adaptation_list = EvaluationRulesAdaptation.objects.filter( - start_date__year=year + start_date__year=accounting_year ) complementary_informations = ComplementaryInformations.objects.filter( annuality=annuality[0] ) liquidity = 0 - assets_list = get_asset_liability_and_sump_spf(year, category=0) + assets_list = get_asset_liability_and_sump_spf(accounting_year, category=0) for item in assets_list: if item[0] == "Liquidité": item[1] += ( annuality[0].opening_balance - + transactions_list_recettes["sum_total_transaction"] - - transactions_list_expenses["sum_total_transaction"] + + transactiontypes_list_recettes["sum_total_transaction"] + - transactiontypes_list_expenses["sum_total_transaction"] ) liquidity = item[1] - liability_list = get_asset_liability_and_sump_spf(year, category=1) + liability_list = get_asset_liability_and_sump_spf(accounting_year, category=1) asset_liability_sum = [x for x in zip_longest(assets_list, liability_list)] - right_list = get_right_engagement_and_sump_spf(year, category=0) - engagement_list = get_right_engagement_and_sump_spf(year, category=1) + right_list = get_right_engagement_and_sump_spf(accounting_year, category=0) + engagement_list = get_right_engagement_and_sump_spf(accounting_year, category=1) # right_engagement_sum = zip_longest(right_list, engagement_list) right_engagement_sum = [x for x in zip_longest(right_list, engagement_list)] @@ -143,9 +150,9 @@ def export_year_spf_finance(request, year): context = { "list_sum": list_sum, - "year": year, - "total_depense": transactions_list_expenses["sum_total_transaction"], - "total_recette": transactions_list_recettes["sum_total_transaction"], + "accounting_year": accounting_year, + "total_expenses": transactiontypes_list_expenses["sum_total_transaction"], + "total_recette": transactiontypes_list_recettes["sum_total_transaction"], "rules_list": rules_list, "rules_adaptation_list": rules_adaptation_list, "complementary_informations": complementary_informations, @@ -247,36 +254,37 @@ class MyDocument(object): self.drawNewLine(INDENTED_X, "Siège social : " + info["SIEGE_SOCIAL"]) self.newline(BIG_LINE_HEIGHT) - def title(self, year): + def title(self, accounting_year): self.drawString( 130, - "Comptes simplifiés de l'exercice " + year, + "Comptes simplifiés de l'exercice " + accounting_year, font_decoration="Bold", font_size=20, ) self.newline(DOUBLE_LINE_HEIGHT) - def recette_depense(self, year): + def recette_depense(self, accounting_year): self.drawString( X, "Etat recettes/dépenses (en €)", font_decoration="Oblique", font_size=14 ) - self.__display_table_transaction(year) + self.__display_table_transaction(accounting_year) self.newline() - def __display_table_transaction(self, year): + def __display_table_transaction(self, accounting_year): self.__display_table_header("DEPENSES", "RECETTES") - tmp_compta_depenses = get_transaction_and_sum_for_spf_export(year, 0) - tmp_compta_recettes = get_transaction_and_sum_for_spf_export(year, 1) + tmp_compta_extenses = get_transactiontype_and_sum_for_spf_export(accounting_year, 0) + tmp_compta_recettes = get_transactiontype_and_sum_for_spf_export(accounting_year, 1) - self.__display_table_transaction_body(tmp_compta_depenses, tmp_compta_recettes) + self.__display_table_transaction_body(tmp_compta_extenses, tmp_compta_recettes) # print(tmp) # totaldepense = self.__display_table_two_column(tmp_compta_depenses, 1) # totalrecette = self.__display_table_two_column(tmp_compta_recettes, 2) self.__display_table_footer( - int(tmp_compta_depenses["sum_total_transaction"]), int(tmp_compta_recettes["sum_total_transaction"]) + int(tmp_compta_depenses["sum_total_transaction"]), + int(tmp_compta_recettes["sum_total_transaction"]), ) def __display_table_header(self, title_left, title_right): @@ -357,19 +365,19 @@ class MyDocument(object): str(locale.format("%d", int(value2), grouping=True)), ) - def annexes(self, year): + def annexes(self, accounting_year): self.drawNewLine(X, "Annexes", font_decoration="Oblique", font_size=14) - self.display_evaluation_rules(year) - self.display_modification_evaluation_rules(year) - self.display_additional_information(year) - self.display_patrimony(year) - self.display_right_engagement(year) + self.display_evaluation_rules(accounting_year) + self.display_modification_evaluation_rules(accounting_year) + self.display_additional_information(accounting_year) + self.display_patrimony(accounting_year) + self.display_right_engagement(accounting_year) - def display_evaluation_rules(self, year): + def display_evaluation_rules(self, accounting_year): self.drawNewLine(X, "1. Résumé des règles d'évaluation") rules_list = EvaluationRules.objects.filter( - Q(stop_date__year__lte=year) | Q(stop_date__isnull=True) - ).exclude(start_date__year__gt=year) + Q(stop_date__year__lte=accounting_year) | Q(stop_date__isnull=True) + ).exclude(start_date__year__gt=accounting_year) if rules_list: for rule in rules_list: self.drawNewLine( @@ -383,10 +391,10 @@ class MyDocument(object): ) self.newline() - def display_modification_evaluation_rules(self, year): + def display_modification_evaluation_rules(self, accounting_year): self.drawNewLine(X, "2. Adaptation des règles d'évaluation") rules_adaptation_list = EvaluationRulesAdaptation.objects.filter( - start_date__year=year + start_date__year=accounting_year ) if rules_adaptation_list: for line in rules_adaptation_list: @@ -403,9 +411,9 @@ class MyDocument(object): ) self.newline() - def display_additional_information(self, year): + def display_additional_information(self, accounting_year): self.drawNewLine(X, "3. Informations complémentaires") - annuality = Annuality.objects.filter(year__year=year) + annuality = Annuality.objects.filter(year__year=accounting_year) complementary_informations = ComplementaryInformations.objects.filter( annuality=annuality[0] ) @@ -424,23 +432,23 @@ class MyDocument(object): ) self.newline() - def display_patrimony(self, year): + def display_patrimony(self, accounting_year): self.drawNewLine(X, "4. Etat du patrimoine") - annuality = Annuality.objects.filter(year__year=year) - tmp_compta_depenses = get_transaction_and_sum_for_spf_export(year, 0) - tmp_compta_recettes = get_transaction_and_sum_for_spf_export(year, 1) + annuality = Annuality.objects.filter(year__year=accounting_year) + tmp_compta_extenses = get_transactiontype_and_sum_for_spf_export(accounting_year, 0) + tmp_compta_recettes = get_transactiontype_and_sum_for_spf_export(accounting_year, 1) - assets_list = get_asset_liability_and_sump_spf(year, category=0) + assets_list = get_asset_liability_and_sump_spf(accounting_year, category=0) for item in assets_list: if item[0] == "Liquidité": item[1] += ( annuality[0].opening_balance + tmp_compta_recettes["sum_total_transaction"] - - tmp_compta_depenses["sum_total_transaction"] + - tmp_compta_extenses["sum_total_transaction"] ) - liability_list = get_asset_liability_and_sump_spf(year, category=1) + liability_list = get_asset_liability_and_sump_spf(accounting_year, category=1) self.__display_table_header("AVOIRS", "DETTES") save = self.y @@ -485,7 +493,7 @@ class MyDocument(object): return total - def display_right_engagement(self, year): + def display_right_engagement(self, accounting_year): self.drawNewLine( X, "5. Droits et engagements importants qui ne sont pas susceptibles d'être quantifiés", @@ -510,27 +518,27 @@ class MyDocument(object): # document.rect(startx, y-5, 525, 15, fill=0) -def generate_pdf_for_spf(request, year): +def generate_pdf_for_spf(request, accounting_year): """ """ # Create the HttpResponse object with the appropriate PDF headers. response = HttpResponse(content_type="application/pdf") response["Content-Disposition"] = ( - 'attachment; filename="comptes_simplifies_annuels_' + year + '.pdf"' + 'attachment; filename="comptes_simplifies_annuels_' + accounting_year + '.pdf"' ) document = MyDocument(response) info = load(request) document.header(info) - document.title(year) - document.recette_depense(year) - document.annexes(year) + document.title(accounting_year) + document.recette_depense(accounting_year) + document.annexes(accounting_year) document.download() return response -def transaction_by_type(request, year, transaction_type_id): +def transaction_by_type(request, accounting_year, transaction_type_id): """ Liste toutes les lignes de comptabilité pour une année recue en paramètre """ @@ -623,7 +631,7 @@ def transaction_by_type(request, year, transaction_type_id): # return render(request, 'year_transaction_listing.html', context) -def transaction_by_year_listing(request, year, t_type=None): +def transaction_by_year_listing(request, accounting_year, t_type=None): """ Liste toutes les lignes de comptabilité pour une année recue en paramètre """ @@ -632,7 +640,7 @@ def transaction_by_year_listing(request, year, t_type=None): if t_type == "bank": t_type = "Banque" transaction_list = transaction_list = ( - Transaction.objects.filter(registrationDate__year=year) + Transaction.objects.filter(registrationDate__year=accounting_year) .filter(bkAmount__isnull=False) .exclude(bkAmount=0) .exclude(is_simulated=True) @@ -641,7 +649,7 @@ def transaction_by_year_listing(request, year, t_type=None): elif t_type == "box": t_type = "Caisse" transaction_list = transaction_list = ( - Transaction.objects.filter(registrationDate__year=year) + Transaction.objects.filter(registrationDate__year=accounting_year) .filter(bxAmount__isnull=False) .exclude(bxAmount=0) .exclude(is_simulated=True) @@ -650,7 +658,7 @@ def transaction_by_year_listing(request, year, t_type=None): else: t_type = "Tous" transaction_list = Transaction.objects.filter( - registrationDate__year=year + registrationDate__year=accounting_year ).order_by("registrationDate") # pour mon dictionnaire date/total @@ -659,8 +667,8 @@ def transaction_by_year_listing(request, year, t_type=None): tmp_Total = 0 tmp_Amount = 0 - sumdepense = 0 - sumdepense_simulated = 0 + sum_extense = 0 + sum_extense_simulated = 0 sumrecette = 0 sumrecette_simulated = 0 transaction_list_and_sum = [] @@ -674,9 +682,9 @@ def transaction_by_year_listing(request, year, t_type=None): # on ajoute le signe ("+" ou "-") afin de pouvoir l'utiliser dans des calculs après. tmp_Amount = transaction.totalAmount if transaction.transaction_type.transaction_type == 0: - sumdepense_simulated += tmp_Amount + sum_extense_simulated += tmp_Amount if transaction.is_simulated is not None and transaction.is_simulated == 0: - sumdepense += tmp_Amount + sum_extense += tmp_Amount tmp_Amount = -tmp_Amount else: sumrecette_simulated += tmp_Amount @@ -703,16 +711,16 @@ def transaction_by_year_listing(request, year, t_type=None): previous_date = transaction.registrationDate.date() - total = sumrecette - sumdepense - total_simulated = sumrecette_simulated - sumdepense_simulated + total = sumrecette - sum_extense + total_simulated = sumrecette_simulated - sum_extense_simulated nb_transaction = transaction_list.count() context = { "transaction_list": transaction_list_and_sum, - "year": year, - "totaldepense": sumdepense, + "accounting_year": accounting_year, + "totaldepense": sum_extense, "totalrecette": sumrecette, - "totaldepense_simulated": sumdepense_simulated, + "totaldepense_simulated": sum_extense_simulated, "totalrecette_simulated": sumrecette_simulated, "total": total, "total_simulated": total_simulated, @@ -742,13 +750,13 @@ def year_listing(request): return render(request, "year_listing.html", context) -def transaction_listing_for_year_and_type(request, year, transaction_type_id): +def transaction_listing_for_year_and_type(request, accounting_year, transaction_type_id): """ Liste toutes les transactions d'un `type de transaction` et pour une année (passés en paramètre). Args: request (???): - year (int): année + accounting_year (int): année transaction_type_id (int): id d'un type de transaction Returns: @@ -756,9 +764,10 @@ def transaction_listing_for_year_and_type(request, year, transaction_type_id): """ transaction_type = TransactionType.objects.get(pk=transaction_type_id) - by_year_condition = Q(registrationDate__year=year) + by_year_condition = Q(registrationDate__year=accounting_year) by_type_condition = Q(transaction_type=transaction_type_id) by_parent_type_condition = Q(transaction_type__parent=transaction_type_id) + transaction_list = Transaction.objects.filter( by_year_condition & (by_type_condition | by_parent_type_condition) ).order_by("registrationDate") @@ -773,16 +782,10 @@ def transaction_listing_for_year_and_type(request, year, transaction_type_id): transaction_list_and_sum.append((transaction, total)) - # nb_transaction = transaction_list.count() - # context = {'transaction_list': transaction_list_and_sum, - # 'transaction_type': str(transaction_type), - # 'nb_transaction': nb_transaction, - # 'year': year, - # 'total_simulated': total_simulated, 'total': total} context = { "transaction_list": transaction_list_and_sum, "transaction_type": str(transaction_type), - "year": year, + "accounting_year": accounting_year, "total_simulated": total_simulated, "total": total, } diff --git a/src/templates/compta.html b/src/templates/compta.html index ab07095..5b30240 100644 --- a/src/templates/compta.html +++ b/src/templates/compta.html @@ -41,7 +41,7 @@
--> - Comptabilité {{ year }} + Comptabilité {{ accounting_year }}

diff --git a/src/templates/event_transaction_listing.html b/src/templates/event_transaction_listing.html index d9d7b36..2479bb5 100644 --- a/src/templates/event_transaction_listing.html +++ b/src/templates/event_transaction_listing.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% block page_title %}{{ event }} {{ year }}{% endblock %} +{% block page_title %}{{ event }} {{ accounting_year }}{% endblock %} {% block content %} diff --git a/src/templates/transaction_listing.html b/src/templates/transaction_listing.html index 281976b..16d5e7c 100644 --- a/src/templates/transaction_listing.html +++ b/src/templates/transaction_listing.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% block page_title %}Comptabilité {{ year }} - {{t_type}}{% endblock %} +{% block page_title %}Comptabilité {{ accounting_year }} - {{t_type}}{% endblock %} {% block content %} @@ -10,11 +10,11 @@
-

{{ transaction_type }} ({{ year }})

+

{{ transaction_type }} ({{ accounting_year }})

diff --git a/src/templates/year_listing.html b/src/templates/year_listing.html index afe8cca..3dfe801 100644 --- a/src/templates/year_listing.html +++ b/src/templates/year_listing.html @@ -20,13 +20,13 @@
- {% for year in year_list %} + {% for accounting_year in year_list %} - - - - - + + + + + {% endfor %}
Suivi Export SPF Finance
{{ year.0 }}{{ year.1 }}BancaireCaisseexport{{ accounting_year.0 }}{{ accounting_year.1 }}BancaireCaisseexport
diff --git a/src/templates/year_transaction_export_ooo.html b/src/templates/year_transaction_export_ooo.html index 63f281e..2c91f3e 100644 --- a/src/templates/year_transaction_export_ooo.html +++ b/src/templates/year_transaction_export_ooo.html @@ -2,7 +2,7 @@ {% load tables %} -{% block page_title %}Comptabilité de l'année {{ year }}{% endblock %} +{% block page_title %}Comptabilité de l'année {{ accounting_year }}{% endblock %} {% block content %} @@ -12,11 +12,11 @@
-

Dépenses {{ year }}

+

Dépenses {{ accounting_year }}

@@ -25,14 +25,14 @@ {% display_table compta_depenses %}
-

Recettes {{ year }}

+

Recettes {{ accounting_year }}

{% display_table compta_recettes %}
diff --git a/src/templates/year_transaction_export_spf.html b/src/templates/year_transaction_export_spf.html index 456aa25..796f0a5 100644 --- a/src/templates/year_transaction_export_spf.html +++ b/src/templates/year_transaction_export_spf.html @@ -2,7 +2,7 @@ {% load humanize %} {% load intdot %} -{% block page_title %}Comptabilité {{ year }}{% endblock %} +{% block page_title %}Comptabilité {{ accounting_year }}{% endblock %} {% block content %} @@ -12,11 +12,11 @@
-

Comptes simplifiés de l'exercice {{ year }}

+

Comptes simplifiés de l'exercice {{ accounting_year }}

@@ -50,7 +50,7 @@ {% endfor %} Total des dépenses - {{ total_depense|floatformat:0|intdot }} + {{ total_expenses|floatformat:0|intdot }} Total des recettes {{ total_recette|floatformat:0|intdot }} @@ -155,7 +155,7 @@
diff --git a/src/templates/year_transaction_export_sxs.html b/src/templates/year_transaction_export_sxs.html index 5e80ba2..fbe1d57 100644 --- a/src/templates/year_transaction_export_sxs.html +++ b/src/templates/year_transaction_export_sxs.html @@ -3,7 +3,7 @@ {% load humanize %} {% load intdot %} -{% block page_title %}Comptabilité {{ year }}{% endblock %} +{% block page_title %}Comptabilité {{ accounting_year }}{% endblock %} {% block content %} @@ -13,11 +13,11 @@
-

Comptabilité {{ year }}

+

Comptabilité {{ accounting_year }}

@@ -36,57 +36,57 @@ Montants - {% for line in transactions_list %} - + {% for transactiontype in transactiontypes_list %} + - {% if line.1.2 %} + {% if transactiontype.1.2 %}      {% else %} {% endif %} - {{ line.1.0 }} - {% if line.1.2 == None %} + {{ transactiontype.1.0 }} + {% if transactiontype.1.2 == None %} {% endif %} - {% if line.1.2 %} + {% if transactiontype.1.2 %} - {% if line.1.0 %}{% if line.1.3 == None %}0,00{% else %}{{ line.1.3|floatformat:2|intdot }}{% endif %}{% endif %} + {% if transactiontype.1.0 %}{% if transactiontype.1.3 == None %}0,00{% else %}{{ transactiontype.1.3|floatformat:2|intdot }}{% endif %}{% endif %} {% else %} - {% if line.1.3 == None %}0,00{% else %}{{ line.1.3|floatformat:2|intdot }}{% endif %} + {% if transactiontype.1.3 == None %}0,00{% else %}{{ transactiontype.1.3|floatformat:2|intdot }}{% endif %} {% endif %} - {% if line.0.4 %} - {% if line.0.2 %} + {% if transactiontype.0.4 %} + {% if transactiontype.0.2 %}      {% else %} {% endif %} - {{ line.0.0 }} - {% if line.0.2 == None %} + {{ transactiontype.0.0 }} + {% if transactiontype.0.2 == None %} {% endif %} {% endif %} - {% if line.0.2 %} + {% if transactiontype.0.2 %} - {% if line.0.0 %}{% if line.0.3 == None %}0,00{% else %}{{ line.0.3|floatformat:2|intdot }}{% endif %}{% endif %} + {% if transactiontype.0.0 %}{% if transactiontype.0.3 == None %}0,00{% else %}{{ transactiontype.0.3|floatformat:2|intdot }}{% endif %}{% endif %} {% else %} - {% if line.0.0 %}{% if line.0.3 == None %}0,00{% else %}{{ line.0.3|floatformat:2|intdot }}{% endif %}{% endif %} + {% if transactiontype.0.0 %}{% if transactiontype.0.3 == None %}0,00{% else %}{{ transactiontype.0.3|floatformat:2|intdot }}{% endif %}{% endif %} {% endif %} @@ -101,7 +101,7 @@
-

ListingAffichage 2 tableauxAffichage 1 tableaux simplifié

+

ListingAffichage 2 tableauxAffichage 1 tableaux simplifié


diff --git a/src/templates/year_transaction_listing.html b/src/templates/year_transaction_listing.html index b5ca636..10fdb25 100644 --- a/src/templates/year_transaction_listing.html +++ b/src/templates/year_transaction_listing.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% block page_title %}Comptabilité {{ year }} - {{t_type}}{% endblock %} +{% block page_title %}Comptabilité {{ accounting_year }} - {{t_type}}{% endblock %} {% block content %} @@ -10,11 +10,11 @@
-

Année {{ year }} ({% if t_type %}{{t_type}} uniquement - {% endif %}{{ nb_transaction }} transactions)

+

Année {{ accounting_year }} ({% if t_type %}{{t_type}} uniquement - {% endif %}{{ nb_transaction }} transactions)

@@ -115,7 +115,7 @@ }, title: { - text: 'Année {{ year }} : évolution financière' + text: 'Année {{ accounting_year }} : évolution financière' }, // subtitle: { diff --git a/src/tests/test_comptabilite_forms.py b/src/tests/test_comptabilite_forms.py index 3951197..083c147 100644 --- a/src/tests/test_comptabilite_forms.py +++ b/src/tests/test_comptabilite_forms.py @@ -356,4 +356,3 @@ def test_update_transaction_dict(): transaction_dict["description"] = None result = update_transaction_dict(transaction_dict) assert result == transaction_dict - \ No newline at end of file diff --git a/src/tests/test_comptabilite_models.py b/src/tests/test_comptabilite_models.py index c22be54..ded177d 100644 --- a/src/tests/test_comptabilite_models.py +++ b/src/tests/test_comptabilite_models.py @@ -18,10 +18,15 @@ def test_transaction_str(): def test_transaction_total_amount(): """ """ - transaction_type = TransactionType(label="", category=0, order=0, transaction_type=1) - new_transaction = Transaction(bkAmount=50, bxAmount=50, transaction_type=transaction_type) + transaction_type = TransactionType( + label="", category=0, order=0, transaction_type=1 + ) + new_transaction = Transaction( + bkAmount=50, bxAmount=50, transaction_type=transaction_type + ) assert 100 == new_transaction.total_amount + # class TestModelTransaction(TestCase): # """Tests relatifs à la classe `BaseTransaction`.""" diff --git a/src/tests/test_comptabilite_utils.py b/src/tests/test_comptabilite_utils.py index d5654e4..cc3b102 100644 --- a/src/tests/test_comptabilite_utils.py +++ b/src/tests/test_comptabilite_utils.py @@ -1,6 +1,4 @@ -from comptabilite.utils import ( - zero_or_value -) +from comptabilite.utils import zero_or_value def test_zero_or_value():