[WIP] Improve code lisibility.

This commit is contained in:
Trullemans Gregory 2020-02-21 08:50:12 +01:00
parent 9c38f171d1
commit 843a9b0c78
17 changed files with 231 additions and 211 deletions

View File

@ -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(
sum_value += zero_or_value(
list(
Transaction.objects.filter(
registrationDate__year=year,
registrationDate__year=accounting_year,
transaction_type__parent=transaction_type,
is_simulated=False,
is_done=True,
)
.aggregate(Sum("totalAmount"))
.values()
)[0])
)[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

View File

@ -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)

View File

@ -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):

View File

@ -17,36 +17,36 @@ app_name = "annualcomptability"
urlpatterns = [
url(r"^$", year_listing, name="year_listing"),
url(
r"^listing/(?P<year>[0-9]{4})/(?P<t_type>[A-Za-z]+)$",
r"^listing/(?P<accounting_year>[0-9]{4})/(?P<t_type>[A-Za-z]+)$",
transaction_by_year_listing,
name="by_year_bank",
),
url(
r"^listing/(?P<year>[0-9]{4})/(?P<t_type>[A-Za-z]+)$",
r"^listing/(?P<accounting_year>[0-9]{4})/(?P<t_type>[A-Za-z]+)$",
transaction_by_year_listing,
name="by_year_box",
),
url(
r"^listing/(?P<year>[0-9]{4})/(?P<transaction_type_id>[0-9]+)$",
r"^listing/(?P<accounting_year>[0-9]{4})/(?P<transaction_type_id>[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<year>[0-9]{4})$", transaction_by_year_listing, name="by_year"),
url(r"^listing/(?P<accounting_year>[0-9]{4})$", transaction_by_year_listing, name="by_year"),
url(
r"^details/(?P<transactionid>[0-9]+)",
transaction_details,
name="compta_details",
),
url(
r"^export/simple/(?P<year>[0-9]{4})$",
r"^export/simple/(?P<accounting_year>[0-9]{4})$",
export_year_spf_finance,
name="export_simple",
),
url(
r"^export/(?P<year>[0-9]{4})/(?P<export_type>\w+)$",
r"^export/(?P<accounting_year>[0-9]{4})/(?P<export_type>\w+)$",
comptability_export,
name="export",
),
url(r"^export/pdf/(?P<year>[0-9]{4})/", generate_pdf_for_spf, name="pdf_export"),
url(r"^export/pdf/(?P<accounting_year>[0-9]{4})/", generate_pdf_for_spf, name="pdf_export"),
]

View File

@ -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,
}

View File

@ -41,7 +41,7 @@
<div class="container">
<div id="frame2">
<div id="content"> -->
<font size="5"><b><u>Comptabilité {{ year }}</b></u></font>
<font size="5"><b><u>Comptabilité {{ accounting_year }}</b></u></font>
<br />
<br />
<table class="table table-striped table-bordered table-condensed sort sortable-onload-5-6r rowstyle-alt colstyle-alt" id="comptaTable">

View File

@ -1,6 +1,6 @@
{% extends "base.html" %}
{% block page_title %}{{ event }} {{ year }}{% endblock %}
{% block page_title %}{{ event }} {{ accounting_year }}{% endblock %}
{% block content %}

View File

@ -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 @@
<div id="content">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
<h1>{{ transaction_type }} <small>({{ year }})</small></h1>
<h1>{{ transaction_type }} <small>({{ accounting_year }})</small></h1>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
<p align="right" class="noprint">
<a href="{% url 'annualcomptability:export' year 'sxs' %}">1 tableau</a> | <a href="{% url 'annualcomptability:export' year 'ooo' %}">2 tableaux</a> | <a href="{% url 'annualcomptability:export_simple' year %}">Export SPF</a>
<a href="{% url 'annualcomptability:export' accounting_year 'sxs' %}">1 tableau</a> | <a href="{% url 'annualcomptability:export' accounting_year 'ooo' %}">2 tableaux</a> | <a href="{% url 'annualcomptability:export_simple' accounting_year %}">Export SPF</a>
</p>
</div>
</div>

View File

@ -20,13 +20,13 @@
<th class="centered" colspan="2">Suivi</th>
<th class="centered">Export SPF Finance</th>
</thead>
{% for year in year_list %}
{% for accounting_year in year_list %}
<tr>
<td><a href="{% url 'annualcomptability:by_year' year.0 %}">{{ year.0 }}</a></td>
<td class="push-right">{{ year.1 }}</td>
<td class="centered"><a href="{% url 'annualcomptability:by_year_bank' year.0 'bank' %}">Bancaire</a></td>
<td class="centered"><a href="{% url 'annualcomptability:by_year_box' year.0 'box' %}">Caisse</a></td>
<td class="centered"><a href="{% url 'annualcomptability:export_simple' year.0 %}">export</a></td>
<td><a href="{% url 'annualcomptability:by_year' accounting_year.0 %}">{{ accounting_year.0 }}</a></td>
<td class="push-right">{{ accounting_year.1 }}</td>
<td class="centered"><a href="{% url 'annualcomptability:by_year_bank' accounting_year.0 'bank' %}">Bancaire</a></td>
<td class="centered"><a href="{% url 'annualcomptability:by_year_box' accounting_year.0 'box' %}">Caisse</a></td>
<td class="centered"><a href="{% url 'annualcomptability:export_simple' accounting_year.0 %}">export</a></td>
</tr>
{% endfor %}
</table>

View File

@ -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 @@
<div id="content">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<h3>Dépenses {{ year }}</h3>
<h3>Dépenses {{ accounting_year }}</h3>
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<p align="right" class="noprint">
<a href="{% url 'annualcomptability:by_year' year %}">Listing</a> | <a href="{% url 'annualcomptability:export' year 'sxs' %}">1 tableau</a> | <a href="{% url 'annualcomptability:export_simple' year %}">Export SPF</a>
<a href="{% url 'annualcomptability:by_year' accounting_year %}">Listing</a> | <a href="{% url 'annualcomptability:export' accounting_year 'sxs' %}">1 tableau</a> | <a href="{% url 'annualcomptability:export_simple' accounting_year %}">Export SPF</a>
</p>
</div>
</div>
@ -25,14 +25,14 @@
{% display_table compta_depenses %}
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<h3>Recettes {{ year }}</h3>
<h3>Recettes {{ accounting_year }}</h3>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
{% display_table compta_recettes %}
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<p align="center" class="noprint">
<a href="{% url 'annualcomptability:by_year' year %}">Listing</a> | <a href="{% url 'annualcomptability:export' year 'sxs' %}">Affichage 1 tableau</a>
<a href="{% url 'annualcomptability:by_year' accounting_year %}">Listing</a> | <a href="{% url 'annualcomptability:export' accounting_year 'sxs' %}">Affichage 1 tableau</a>
</p>
</div>
</div>

View File

@ -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 @@
<div id="content">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
<h2>Comptes simplifiés de l'exercice {{ year }}</h2>
<h2>Comptes simplifiés de l'exercice {{ accounting_year }}</h2>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
<p align="right" class="noprint">
<a href="{% url 'annualcomptability:by_year' year %}">Listing</a> | <a href="{% url 'annualcomptability:export' year 'sxs' %}">1 tableau</a> | <a href="{% url 'annualcomptability:export' year 'ooo' %}">2 tableaux</a>
<a href="{% url 'annualcomptability:by_year' accounting_year %}">Listing</a> | <a href="{% url 'annualcomptability:export' accounting_year 'sxs' %}">1 tableau</a> | <a href="{% url 'annualcomptability:export' accounting_year 'ooo' %}">2 tableaux</a>
</p>
</div>
</div>
@ -50,7 +50,7 @@
{% endfor %}
<tr>
<td class="push-right"><b>Total des dépenses</b></td>
<td class="push-right"><b>{{ total_depense|floatformat:0|intdot }}</b></td>
<td class="push-right"><b>{{ total_expenses|floatformat:0|intdot }}</b></td>
<td class="push-right"><b>Total des recettes</b></td>
<td class="push-right"><b>{{ total_recette|floatformat:0|intdot }}</b></td>
</tr>
@ -155,7 +155,7 @@
</div>
<div class="row">
<div class="span12">
<p class="right"><a href="{% url 'annualcomptability:pdf_export' year %}" class="btn btn-default btn-primary" role="button">Comptes PDF</a></p>
<p class="right"><a href="{% url 'annualcomptability:pdf_export' accounting_year %}" class="btn btn-default btn-primary" role="button">Comptes PDF</a></p>
</div>
</div>
</div>

View File

@ -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 @@
<div id="content">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<h3>Comptabilité {{ year }}</h3>
<h3>Comptabilité {{ accounting_year }}</h3>
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<p align="right" class="noprint">
<a href="{% url 'annualcomptability:by_year' year %}">Listing</a> | <a href="{% url 'annualcomptability:export' year 'ooo' %}">2 tableaux</a> | <a href="{% url 'annualcomptability:export_simple' year %}">Export SPF</a>
<a href="{% url 'annualcomptability:by_year' accounting_year %}">Listing</a> | <a href="{% url 'annualcomptability:export' accounting_year 'ooo' %}">2 tableaux</a> | <a href="{% url 'annualcomptability:export_simple' accounting_year %}">Export SPF</a>
</p>
</div>
</div>
@ -36,57 +36,57 @@
<th class="col-md-2 centered" colspan="2">Montants</th>
</tr>
</thead>
{% for line in transactions_list %}
<tr {% if line.1.2 %} class="noprint" {% endif %}>
{% for transactiontype in transactiontypes_list %}
<tr {% if transactiontype.1.2 %} class="noprint" {% endif %}>
<!-- FIRST COLUMN -->
<td>
{% if line.1.2 %}
{% if transactiontype.1.2 %}
&nbsp;&nbsp;&nbsp;&nbsp;
{% else %}
<b>
{% endif %}
<a href="{% url 'annualcomptability:transaction_listing_for_year_and_type' year line.1.4 %}">{{ line.1.0 }}</a>
{% if line.1.2 == None %}
<a href="{% url 'annualcomptability:transaction_listing_for_year_and_type' accounting_year transactiontype.1.id %}">{{ transactiontype.1.0 }}</a>
{% if transactiontype.1.2 == None %}
</b>
{% endif %}
</td>
{% if line.1.2 %}
{% if transactiontype.1.2 %}
<td class="col-md-1 push-right">
{% 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 %}
</td>
<td class="col-md-1"></td>
{% else %}
<td></td>
<td class="push-right">
{% 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 %}
</td>
{% endif %}
<!-- SECOND COLUMN -->
<td>
{% if line.0.4 %}
{% if line.0.2 %}
{% if transactiontype.0.4 %}
{% if transactiontype.0.2 %}
&nbsp;&nbsp;&nbsp;&nbsp;
{% else %}
<b>
{% endif %}
<a href="{% url 'annualcomptability:transaction_listing_for_year_and_type' year line.0.4 %}">{{ line.0.0 }}</a>
{% if line.0.2 == None %}
<a href="{% url 'annualcomptability:transaction_listing_for_year_and_type' accounting_year transactiontype.0.4 %}">{{ transactiontype.0.0 }}</a>
{% if transactiontype.0.2 == None %}
</b>
{% endif %}
{% endif %}
</td>
{% if line.0.2 %}
{% if transactiontype.0.2 %}
<td class="col-md-1 push-right">
{% 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 %}
</td>
<td class="col-md-1"></td>
{% else %}
<td></td>
<td class="push-right">
{% 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 %}
</td>
{% endif %}
</tr>
@ -101,7 +101,7 @@
</tfoot>
</table>
<br>
<p align="center" class="noprint"><a href="{% url 'annualcomptability:by_year' year %}">Listing</a> | <a href="{% url 'annualcomptability:export' year 'ooo' %}">Affichage 2 tableaux</a> | <a href="{% url 'annualcomptability:export_simple' year %}">Affichage 1 tableaux simplifié</a></p>
<p align="center" class="noprint"><a href="{% url 'annualcomptability:by_year' accounting_year %}">Listing</a> | <a href="{% url 'annualcomptability:export' accounting_year 'ooo' %}">Affichage 2 tableaux</a> | <a href="{% url 'annualcomptability:export_simple' accounting_year %}">Affichage 1 tableaux simplifié</a></p>
<br>
</div>
</div>

View File

@ -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 @@
<div id="content">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
<h1>Année {{ year }} <small>({% if t_type %}{{t_type}} uniquement - {% endif %}{{ nb_transaction }} transactions)</small></h1>
<h1>Année {{ accounting_year }} <small>({% if t_type %}{{t_type}} uniquement - {% endif %}{{ nb_transaction }} transactions)</small></h1>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
<p align="right" class="noprint">
<a href="{% url 'annualcomptability:export' year 'sxs' %}">1 tableau</a> | <a href="{% url 'annualcomptability:export' year 'ooo' %}">2 tableaux</a> | <a href="{% url 'annualcomptability:export_simple' year %}">Export SPF</a>
<a href="{% url 'annualcomptability:export' accounting_year 'sxs' %}">1 tableau</a> | <a href="{% url 'annualcomptability:export' accounting_year 'ooo' %}">2 tableaux</a> | <a href="{% url 'annualcomptability:export_simple' accounting_year %}">Export SPF</a>
</p>
</div>
</div>
@ -115,7 +115,7 @@
},
title: {
text: 'Année {{ year }} : évolution financière'
text: 'Année {{ accounting_year }} : évolution financière'
},
// subtitle: {

View File

@ -356,4 +356,3 @@ def test_update_transaction_dict():
transaction_dict["description"] = None
result = update_transaction_dict(transaction_dict)
assert result == transaction_dict

View File

@ -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`."""

View File

@ -1,6 +1,4 @@
from comptabilite.utils import (
zero_or_value
)
from comptabilite.utils import zero_or_value
def test_zero_or_value():