Improve Code Lisibility.
This commit is contained in:
parent
a1615bfe11
commit
deb48294fc
|
@ -8,7 +8,7 @@ from django.utils import timezone
|
|||
|
||||
from eventCompta.models import Event
|
||||
|
||||
from .utils import zero_or_value as zov
|
||||
from .utils import zero_or_value
|
||||
|
||||
|
||||
class RuleOfEvaluation(models.Model):
|
||||
|
@ -60,11 +60,19 @@ class Annuality(models.Model):
|
|||
return "%s (%s - %s)" % (self.year, self.opening_balance, self.closing_balance)
|
||||
|
||||
|
||||
class ComptabilityManager(models.Manager):
|
||||
"""
|
||||
"""
|
||||
def by_year(self, year):
|
||||
return super().get_queryset().filter(registrationDate__year=year)
|
||||
|
||||
|
||||
class Comptability(models.Model):
|
||||
"""
|
||||
Classe représentant les champs communs aux lignes de comptabilité, aux droits en
|
||||
engagements, … etc.
|
||||
"""
|
||||
objects = ComptabilityManager()
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
@ -174,8 +182,16 @@ class TransactionType(models.Model):
|
|||
return "%s (%s)" % (self.label, self.get_transaction_type_display())
|
||||
|
||||
|
||||
class TransactionManager(ComptabilityManager):
|
||||
"""
|
||||
"""
|
||||
def by_type(self, transaction_type):
|
||||
return super().get_queryset().filter(transaction_type=transaction_type)
|
||||
|
||||
|
||||
class Transaction(Comptability):
|
||||
""" Classe représentant un mouvement d'argent. """
|
||||
objects = TransactionManager()
|
||||
|
||||
class Meta:
|
||||
verbose_name = "0. Transaction"
|
||||
|
@ -224,7 +240,7 @@ class Transaction(Comptability):
|
|||
|
||||
def __compute_total_amount(self):
|
||||
""" Calcule le montant total de la transaction. """
|
||||
self.totalAmount = zov(self.bkAmount) + zov(self.bxAmount)
|
||||
self.totalAmount = zero_or_value(self.bkAmount) + zero_or_value(self.bxAmount)
|
||||
|
||||
def __compute_amount(self):
|
||||
"""Calcule le montant de la transaction s'il n'est pas déjà fourni. """
|
||||
|
|
|
@ -4,5 +4,5 @@ register = template.Library()
|
|||
|
||||
|
||||
@register.inclusion_tag("export_table.html")
|
||||
def display_table(table):
|
||||
return {"table": table}
|
||||
def display_table(transactions_list):
|
||||
return {"transactions_list": transactions_list}
|
||||
|
|
|
@ -15,17 +15,17 @@ from .utils import zero_or_value
|
|||
|
||||
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.
|
||||
Récupère les transactions associées à une année et un type et additionne les valeurs obtenues.
|
||||
|
||||
Args:
|
||||
year (int): année
|
||||
accounting_year (int): année
|
||||
transaction_type_id (int): type de transaction
|
||||
|
||||
Returns:
|
||||
dict
|
||||
(dict)
|
||||
"""
|
||||
transaction_list = (
|
||||
Transaction.objects.filter(registrationDate__year=accounting_year)
|
||||
transactions_list = (
|
||||
Transaction.objects.by_year(accounting_year)
|
||||
.filter(transaction_type__transaction_type=transaction_type_id)
|
||||
.order_by("registrationDate")
|
||||
)
|
||||
|
@ -33,26 +33,26 @@ def get_transactions_and_sums_for_year_and_type(accounting_year, transaction_typ
|
|||
sum_box_amount = 0
|
||||
sum_total_amount = 0
|
||||
|
||||
for transaction in transaction_list:
|
||||
for transaction in transactions_list:
|
||||
sum_bank_amount += transaction.bkAmount
|
||||
sum_box_amount += transaction.bxAmount
|
||||
sum_total_amount += transaction.totalAmount
|
||||
|
||||
return {
|
||||
"transaction_list": transaction_list,
|
||||
"sum_BkAmount": sum_bank_amount,
|
||||
"sum_BxAmount": sum_box_amount,
|
||||
"sum_TotalAmount": sum_total_amount,
|
||||
"transactions_list": transactions_list,
|
||||
"sum_bank_amount": sum_bank_amount,
|
||||
"sum_box_amount": sum_box_amount,
|
||||
"sum_total_amount": sum_total_amount,
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
Récupère les transactions associées à une année et un type et additionne le montant total des
|
||||
records obtenus.
|
||||
|
||||
Args:
|
||||
year (int): année
|
||||
accounting_year (int): année
|
||||
transaction_type (id): type de transaction
|
||||
|
||||
Returns:
|
||||
|
@ -60,8 +60,7 @@ def get_transactions_totalamount_sum_value(accounting_year, transaction_type):
|
|||
"""
|
||||
return zero_or_value(
|
||||
list(
|
||||
Transaction.objects.filter(
|
||||
registrationDate__year=accounting_year,
|
||||
Transaction.objects.by_year(accounting_year).filter(
|
||||
transaction_type=transaction_type,
|
||||
is_simulated=False,
|
||||
is_done=True,
|
||||
|
@ -141,7 +140,7 @@ def get_transactiontype_and_sum_for_spf_export(accounting_year, transaction_type
|
|||
du type de transaction.
|
||||
|
||||
Args:
|
||||
year (int): année
|
||||
accounting_year (int): année
|
||||
transaction_type_id (int): type de transaction
|
||||
|
||||
Returns:
|
||||
|
@ -160,8 +159,7 @@ def get_transactiontype_and_sum_for_spf_export(accounting_year, transaction_type
|
|||
# Selection des fils
|
||||
sum_value += zero_or_value(
|
||||
list(
|
||||
Transaction.objects.filter(
|
||||
registrationDate__year=accounting_year,
|
||||
Transaction.objects.by_year(accounting_year).filter(
|
||||
transaction_type__parent=transaction_type,
|
||||
is_simulated=False,
|
||||
is_done=True,
|
||||
|
@ -195,7 +193,7 @@ def get_right_engagement_and_sump_spf(accounting_year, category):
|
|||
additionne les montants.
|
||||
|
||||
Args:
|
||||
year (int): année
|
||||
accounting_year (int): année
|
||||
category (int): choix de la catégorie (i.e. "droits" ou "engagements")
|
||||
|
||||
Returns:
|
||||
|
@ -209,9 +207,7 @@ def get_right_engagement_and_sump_spf(accounting_year, category):
|
|||
|
||||
for right_engagement in right_engagement_list:
|
||||
tmp = list(
|
||||
RightEngagement.objects.filter(
|
||||
registrationDate__year=accounting_year, r_e_type=right_engagement
|
||||
)
|
||||
RightEngagement.objects.by_year(accounting_year).filter(r_e_type=right_engagement)
|
||||
.aggregate(Sum("amount"))
|
||||
.values()
|
||||
)[0]
|
||||
|
@ -228,7 +224,7 @@ def get_asset_liability_and_sump_spf(accounting_year, category):
|
|||
l'ensemble lignes correspondantes et additionne les montants.
|
||||
|
||||
Args:
|
||||
year (int): année
|
||||
accounting_year (int): année
|
||||
category (int): choix de la catégorie (i.e. "droits" ou "engagements")
|
||||
|
||||
Returns:
|
||||
|
@ -242,7 +238,7 @@ def get_asset_liability_and_sump_spf(accounting_year, category):
|
|||
|
||||
for item in asset_liability_list:
|
||||
tmp = list(
|
||||
Patrimony.objects.filter(registrationDate__year=accounting_year, patrimony_type=item)
|
||||
Patrimony.objects.by_year(accounting_year).filter(patrimony_type=item)
|
||||
.aggregate(Sum("totalAmount"))
|
||||
.values()
|
||||
)[0]
|
|
@ -1,3 +1,5 @@
|
|||
from decimal import Decimal
|
||||
|
||||
def zero_or_value(value):
|
||||
"""Retourne zéro si la valeur est nulle."""
|
||||
return value if value else 0
|
||||
return value if value else Decimal(0.00)
|
||||
|
|
|
@ -20,7 +20,7 @@ from .models import (
|
|||
ComplementaryInformations,
|
||||
)
|
||||
|
||||
from .compta_tools import (
|
||||
from .tools import (
|
||||
get_transactions_and_sums_for_year_and_type,
|
||||
get_transactiontypes_and_total_amount_transactions,
|
||||
get_transactiontype_and_sum_for_spf_export,
|
||||
|
@ -32,6 +32,8 @@ from comptaClub.site_config import load
|
|||
|
||||
import locale
|
||||
|
||||
EXTENSES = 0
|
||||
RECETTES = 1
|
||||
|
||||
def comptability_export(request, accounting_year, export_type):
|
||||
"""
|
||||
|
@ -39,42 +41,42 @@ def comptability_export(request, accounting_year, export_type):
|
|||
|
||||
Args:
|
||||
request: La requête HTTP
|
||||
year (int): L'année à exporter.
|
||||
accounting_year (int): L'année à exporter.
|
||||
export_type: à choisir parmi `sxs` (side by side) ou `ooo` (one over other).
|
||||
|
||||
Returns:
|
||||
render_to_response sur la page HTML correspondante.
|
||||
"""
|
||||
if export_type == "sxs":
|
||||
return export_year_sxs(request, accounting_year)
|
||||
return get_transaction_list_for_accountingyear_sxs(request, accounting_year)
|
||||
else:
|
||||
return export_year_ooo(request, accounting_year)
|
||||
return get_transaction_list_for_accountingyear_ooo(request, accounting_year)
|
||||
|
||||
|
||||
def export_year_ooo(request, accounting_year):
|
||||
def get_transaction_list_for_accountingyear_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_transactions_and_sums_for_year_and_type(accounting_year, 0)
|
||||
transactions_list_recettes = get_transactions_and_sums_for_year_and_type(accounting_year, 1)
|
||||
transactions_list_expenses = get_transactions_and_sums_for_year_and_type(accounting_year, EXTENSES)
|
||||
transactions_list_recettes = get_transactions_and_sums_for_year_and_type(accounting_year, RECETTES)
|
||||
context = {
|
||||
"compta_expenses": transactions_list_expenses,
|
||||
"transactions_list_expenses": transactions_list_expenses,
|
||||
"accounting_year": accounting_year,
|
||||
"compta_recettes": transactions_list_recettes,
|
||||
"transactions_list_recettes": transactions_list_recettes,
|
||||
}
|
||||
|
||||
return render(request, "year_transaction_export_ooo.html", context)
|
||||
|
||||
|
||||
#def two_table_side_by_side_export(request, accounting_year):
|
||||
def export_year_sxs(request, accounting_year):
|
||||
def get_transaction_list_for_accountingyear_sxs(request, accounting_year):
|
||||
"""
|
||||
Calcule et affiche la comptabilité d'une année passée en parametre dans un unique tableau (side
|
||||
by side).
|
||||
"""
|
||||
expenses_transactiontypes_list = get_transactiontypes_and_total_amount_transactions(accounting_year, 0)
|
||||
recettes_transactiontypes_list = get_transactiontypes_and_total_amount_transactions(accounting_year, 1)
|
||||
expenses_transactiontypes_list = get_transactiontypes_and_total_amount_transactions(accounting_year, EXTENSES)
|
||||
recettes_transactiontypes_list = get_transactiontypes_and_total_amount_transactions(accounting_year, RECETTES)
|
||||
|
||||
transactiontypes_list = zip_longest(
|
||||
recettes_transactiontypes_list["transactiontypes_info_list"],
|
||||
|
@ -100,10 +102,8 @@ def export_year_spf_finance(request, accounting_year):
|
|||
"""
|
||||
annuality = Annuality.objects.filter(year__year=accounting_year)
|
||||
|
||||
# print(annuality[0].opening_balance)
|
||||
|
||||
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)
|
||||
transactiontypes_list_expenses = get_transactiontype_and_sum_for_spf_export(accounting_year, EXTENSES)
|
||||
transactiontypes_list_recettes = get_transactiontype_and_sum_for_spf_export(accounting_year, RECETTES)
|
||||
list_sum = [
|
||||
x
|
||||
for x in zip_longest(
|
||||
|
@ -185,10 +185,7 @@ HUGE_LINE_HEIGHT = COMMON_LINE_HEIGHT * 4
|
|||
|
||||
|
||||
class MyDocument(object):
|
||||
# Create the PDF object, using the response object as its "file."
|
||||
# http://www.reportlab.com/docs/reportlab-userguide.pdf
|
||||
# canvas.rect(x, y, width, height, stroke=1, fill=0)
|
||||
# localhost:8000/billing/contract/pdf/2
|
||||
|
||||
def __init__(self, response):
|
||||
# Create the PDF object, using the response object as its "file."
|
||||
|
@ -197,12 +194,12 @@ class MyDocument(object):
|
|||
|
||||
def newline(self, height=None):
|
||||
"""
|
||||
Passe à la ligne, la hauteur de la ligne étant passée en paramètre.
|
||||
Passe à la ligne, la hauteur de la ligne est passée en paramètre.
|
||||
"""
|
||||
if height == SMALL_LINE_HEIGHT:
|
||||
self.y += SMALL_LINE_HEIGHT
|
||||
|
||||
if height == DOUBLE_LINE_HEIGHT:
|
||||
elif height == DOUBLE_LINE_HEIGHT:
|
||||
self.y += DOUBLE_LINE_HEIGHT
|
||||
|
||||
elif height == BIG_LINE_HEIGHT:
|
||||
|
@ -273,18 +270,14 @@ class MyDocument(object):
|
|||
def __display_table_transaction(self, accounting_year):
|
||||
self.__display_table_header("DEPENSES", "RECETTES")
|
||||
|
||||
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)
|
||||
transactions_extenses = get_transactiontype_and_sum_for_spf_export(accounting_year, EXTENSES)
|
||||
transactions_recettes = get_transactiontype_and_sum_for_spf_export(accounting_year, 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_transaction_body(transactions_extenses, transactions_recettes)
|
||||
|
||||
self.__display_table_footer(
|
||||
int(tmp_compta_depenses["sum_total_transaction"]),
|
||||
int(tmp_compta_recettes["sum_total_transaction"]),
|
||||
int(transactions_extenses["sum_total_transaction"]),
|
||||
int(transactions_recettes["sum_total_transaction"]),
|
||||
)
|
||||
|
||||
def __display_table_header(self, title_left, title_right):
|
||||
|
@ -297,15 +290,15 @@ class MyDocument(object):
|
|||
|
||||
# TODO : à revoir !!!!!!
|
||||
def __display_table_transaction_body(
|
||||
self, tmp_compta_depenses, tmp_compta_recettes
|
||||
self, transactions_extenses, transactions_recettes
|
||||
):
|
||||
|
||||
for i in range(4):
|
||||
self.__display_table_line(
|
||||
tmp_compta_depenses["sum"][i][0],
|
||||
int(tmp_compta_depenses["sum"][i][1]),
|
||||
tmp_compta_recettes["sum"][i][0],
|
||||
int(tmp_compta_recettes["sum"][i][1]),
|
||||
transactions_extenses["sum"][i][0],
|
||||
int(transactions_extenses["sum"][i][1]),
|
||||
transactions_recettes["sum"][i][0],
|
||||
int(transactions_recettes["sum"][i][1]),
|
||||
)
|
||||
self.newline()
|
||||
self.document.rect(
|
||||
|
@ -366,6 +359,14 @@ class MyDocument(object):
|
|||
)
|
||||
|
||||
def annexes(self, accounting_year):
|
||||
""" Ajoute les annexes du document au PDF
|
||||
|
||||
Args:
|
||||
accounting_year (int): année comptable
|
||||
|
||||
Returns:
|
||||
Ne retourne rien
|
||||
"""
|
||||
self.drawNewLine(X, "Annexes", font_decoration="Oblique", font_size=14)
|
||||
self.display_evaluation_rules(accounting_year)
|
||||
self.display_modification_evaluation_rules(accounting_year)
|
||||
|
@ -374,6 +375,14 @@ class MyDocument(object):
|
|||
self.display_right_engagement(accounting_year)
|
||||
|
||||
def display_evaluation_rules(self, accounting_year):
|
||||
""" Ajoute les règles d'évaluation au PDF
|
||||
|
||||
Args:
|
||||
accounting_year (int): année comptable
|
||||
|
||||
Returns:
|
||||
Ne retourne rien
|
||||
"""
|
||||
self.drawNewLine(X, "1. Résumé des règles d'évaluation")
|
||||
rules_list = EvaluationRules.objects.filter(
|
||||
Q(stop_date__year__lte=accounting_year) | Q(stop_date__isnull=True)
|
||||
|
@ -392,6 +401,14 @@ class MyDocument(object):
|
|||
self.newline()
|
||||
|
||||
def display_modification_evaluation_rules(self, accounting_year):
|
||||
""" Ajoute les modifications d'évaluation au PDF
|
||||
|
||||
Args:
|
||||
accounting_year (int): année comptable
|
||||
|
||||
Returns:
|
||||
Ne retourne rien
|
||||
"""
|
||||
self.drawNewLine(X, "2. Adaptation des règles d'évaluation")
|
||||
rules_adaptation_list = EvaluationRulesAdaptation.objects.filter(
|
||||
start_date__year=accounting_year
|
||||
|
@ -412,6 +429,14 @@ class MyDocument(object):
|
|||
self.newline()
|
||||
|
||||
def display_additional_information(self, accounting_year):
|
||||
""" Ajoute les informations complémentaires au PDF
|
||||
|
||||
Args:
|
||||
accounting_year (int): année comptable
|
||||
|
||||
Returns:
|
||||
Ne retourne rien
|
||||
"""
|
||||
self.drawNewLine(X, "3. Informations complémentaires")
|
||||
annuality = Annuality.objects.filter(year__year=accounting_year)
|
||||
complementary_informations = ComplementaryInformations.objects.filter(
|
||||
|
@ -433,11 +458,19 @@ class MyDocument(object):
|
|||
self.newline()
|
||||
|
||||
def display_patrimony(self, accounting_year):
|
||||
""" Ajoute les informations du patrimoine au PDF
|
||||
|
||||
Args:
|
||||
accounting_year (int): année comptable
|
||||
|
||||
Returns:
|
||||
Ne retourne rien
|
||||
"""
|
||||
self.drawNewLine(X, "4. Etat du patrimoine")
|
||||
|
||||
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)
|
||||
tmp_compta_extenses = get_transactiontype_and_sum_for_spf_export(accounting_year, EXTENSES)
|
||||
tmp_compta_recettes = get_transactiontype_and_sum_for_spf_export(accounting_year, RECETTES)
|
||||
|
||||
assets_list = get_asset_liability_and_sump_spf(accounting_year, category=0)
|
||||
for item in assets_list:
|
||||
|
@ -494,6 +527,14 @@ class MyDocument(object):
|
|||
return total
|
||||
|
||||
def display_right_engagement(self, accounting_year):
|
||||
""" Ajoute les droits & engagements au PDF
|
||||
|
||||
Args:
|
||||
accounting_year (int): année comptable
|
||||
|
||||
Returns:
|
||||
Ne retourne rien
|
||||
"""
|
||||
self.drawNewLine(
|
||||
X,
|
||||
"5. Droits et engagements importants qui ne sont pas susceptibles d'être quantifiés",
|
||||
|
@ -503,25 +544,17 @@ class MyDocument(object):
|
|||
INDENTED_X + INDENT * 2, "Pas de droits ou d'engagements.", font_size=9
|
||||
)
|
||||
self.newline()
|
||||
# document.rect(startx, y-50, 255, 60) # Séparation en deux
|
||||
# document.rect(startx, y-50, 205, 45) # Séparation descriptif et montant
|
||||
# document.rect(290, y-50, 220, 45) # Séparation descriptif et montant
|
||||
|
||||
# y -= 15
|
||||
# document.setFont("Helvetica", 9)
|
||||
# document.rect(startx, y-5, 525, 15, fill=0)
|
||||
|
||||
# y -= 15
|
||||
# document.rect(startx, y-5, 525, 15, fill=0)
|
||||
|
||||
# y -= 15
|
||||
# document.rect(startx, y-5, 525, 15, fill=0)
|
||||
|
||||
|
||||
def generate_pdf_for_spf(request, accounting_year):
|
||||
""" Génère un fichier PDF suivant les contraintes du SPF Finances
|
||||
|
||||
Args:
|
||||
accounting_year (int): année
|
||||
|
||||
Returns:
|
||||
???
|
||||
"""
|
||||
"""
|
||||
# Create the HttpResponse object with the appropriate PDF headers.
|
||||
response = HttpResponse(content_type="application/pdf")
|
||||
response["Content-Disposition"] = (
|
||||
'attachment; filename="comptes_simplifies_annuels_' + accounting_year + '.pdf"'
|
||||
|
@ -538,128 +571,37 @@ def generate_pdf_for_spf(request, accounting_year):
|
|||
return response
|
||||
|
||||
|
||||
def transaction_by_type(request, accounting_year, transaction_type_id):
|
||||
def __get_transactions_for_accounting_year_and_kind(accounting_year, transaction_kind=None):
|
||||
"""
|
||||
Liste toutes les lignes de comptabilité pour une année recue en paramètre
|
||||
"""
|
||||
|
||||
# Selection des transactions par rapport au type passé en paramètre
|
||||
pass
|
||||
# if t_type == "bank":
|
||||
# t_type = "Banque"
|
||||
# transaction_list = transaction_list = Transaction.objects.filter(
|
||||
# registrationDate__year=year)\
|
||||
# .filter(bkAmount__isnull = False)\
|
||||
# .exclude(bkAmount = 0)\
|
||||
# .exclude(is_simulated = True)\
|
||||
# .order_by('registrationDate')
|
||||
# elif t_type == "box":
|
||||
# t_type = "Caisse"
|
||||
# transaction_list = transaction_list = Transaction.objects.filter(
|
||||
# registrationDate__year=year)\
|
||||
# .filter(bxAmount__isnull = False)\
|
||||
# .exclude(bxAmount = 0)\
|
||||
# .exclude(is_simulated = True)\
|
||||
# .order_by('registrationDate')
|
||||
# else:
|
||||
# t_type = "Tous"
|
||||
# transaction_list = Transaction.objects.filter(registrationDate__year=year)\
|
||||
# .order_by('registrationDate')
|
||||
transactions_list = Transaction.objects.by_year(accounting_year)
|
||||
|
||||
# # pour mon dictionnaire date/total
|
||||
# previous_date = None
|
||||
# date_sum = OrderedDict()
|
||||
if transaction_kind == "bank":
|
||||
transaction_kind = "Banque"
|
||||
transactions_list = transactions_list.filter(bkAmount__isnull=False).exclude(bkAmount=0)
|
||||
|
||||
# tmp_Total = 0
|
||||
# tmp_Amount = 0
|
||||
# sumdepense = 0
|
||||
# sumdepense_simulated = 0
|
||||
# sumrecette = 0
|
||||
# sumrecette_simulated = 0
|
||||
# transaction_list_and_sum = []
|
||||
elif transaction_kind == "box":
|
||||
transaction_kind = "Caisse"
|
||||
transactions_list = transactions_list.filter(bxAmount__isnull=False).exclude(bxAmount=0)
|
||||
|
||||
# for transaction in transaction_list:
|
||||
|
||||
# # transaction type :
|
||||
# # 0 : dépense
|
||||
# # 1 : recette
|
||||
# # Suivant le type de la transaction, on ajoute son montant aux recettes ou au dépenses et
|
||||
# # 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
|
||||
# if transaction.is_simulated is not None and transaction.is_simulated == 0:
|
||||
# sumdepense += tmp_Amount
|
||||
# tmp_Amount = -tmp_Amount
|
||||
# else:
|
||||
# sumrecette_simulated += tmp_Amount
|
||||
# if transaction.is_simulated is not None and transaction.is_simulated == 0:
|
||||
# sumrecette += tmp_Amount
|
||||
|
||||
# # Si la transaction n'est pas simulée on ajoute la transaction au total temporaire.
|
||||
# if (transaction.is_simulated is not None and transaction.is_simulated == 0)\
|
||||
# and (transaction.is_done is not None and transaction.is_done == 1):
|
||||
# tmp_Total += tmp_Amount
|
||||
|
||||
# transaction_list_and_sum.append((transaction, tmp_Total))
|
||||
|
||||
# if transaction.registrationDate.date() in date_sum:
|
||||
# date_sum[transaction.registrationDate.date()] += tmp_Amount
|
||||
# else:
|
||||
# if previous_date is not None:
|
||||
# date_sum[transaction.registrationDate.date()]=date_sum[previous_date]+tmp_Amount
|
||||
# else:
|
||||
# date_sum[transaction.registrationDate.date()] = tmp_Amount
|
||||
|
||||
# previous_date = transaction.registrationDate.date()
|
||||
|
||||
# total = sumrecette - sumdepense
|
||||
# total_simulated = sumrecette_simulated - sumdepense_simulated
|
||||
|
||||
# nb_transaction = transaction_list.count()
|
||||
# context = {'transaction_list': transaction_list_and_sum,
|
||||
# 'year': year,
|
||||
# 'totaldepense': sumdepense,
|
||||
# 'totalrecette': sumrecette,
|
||||
# 'totaldepense_simulated': sumdepense_simulated,
|
||||
# 'totalrecette_simulated': sumrecette_simulated,
|
||||
# 'total': total,
|
||||
# 'total_simulated': total_simulated,
|
||||
# 'date_sum': date_sum,
|
||||
# 'nb_transaction': nb_transaction,
|
||||
# 't_type': t_type}
|
||||
# return render(request, 'year_transaction_listing.html', context)
|
||||
|
||||
|
||||
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
|
||||
"""
|
||||
|
||||
# Selection des transactions par rapport au type passé en paramètre
|
||||
if t_type == "bank":
|
||||
t_type = "Banque"
|
||||
transaction_list = transaction_list = (
|
||||
Transaction.objects.filter(registrationDate__year=accounting_year)
|
||||
.filter(bkAmount__isnull=False)
|
||||
.exclude(bkAmount=0)
|
||||
.exclude(is_simulated=True)
|
||||
.order_by("registrationDate")
|
||||
)
|
||||
elif t_type == "box":
|
||||
t_type = "Caisse"
|
||||
transaction_list = transaction_list = (
|
||||
Transaction.objects.filter(registrationDate__year=accounting_year)
|
||||
.filter(bxAmount__isnull=False)
|
||||
.exclude(bxAmount=0)
|
||||
.exclude(is_simulated=True)
|
||||
.order_by("registrationDate")
|
||||
)
|
||||
else:
|
||||
t_type = "Tous"
|
||||
transaction_list = Transaction.objects.filter(
|
||||
registrationDate__year=accounting_year
|
||||
).order_by("registrationDate")
|
||||
transaction_kind = "Tous"
|
||||
|
||||
transactions_list = transactions_list.order_by("registrationDate")
|
||||
|
||||
return transactions_list, transaction_kind
|
||||
|
||||
|
||||
def transaction_by_year_listing(request, accounting_year, transaction_kind=None):
|
||||
""" Liste toutes les lignes de comptabilité pour une année recue en paramètre
|
||||
|
||||
Args:
|
||||
accounting_year (int): année comptable
|
||||
transaction_kind (string):
|
||||
"""
|
||||
|
||||
transactions_list, transaction_kind = __get_transactions_for_accounting_year_and_kind(accounting_year, transaction_kind)
|
||||
|
||||
# pour mon dictionnaire date/total
|
||||
previous_date = None
|
||||
|
@ -673,7 +615,7 @@ def transaction_by_year_listing(request, accounting_year, t_type=None):
|
|||
sumrecette_simulated = 0
|
||||
transaction_list_and_sum = []
|
||||
|
||||
for transaction in transaction_list:
|
||||
for transaction in transactions_list:
|
||||
|
||||
# transaction type :
|
||||
# 0 : dépense
|
||||
|
@ -681,7 +623,7 @@ def transaction_by_year_listing(request, accounting_year, t_type=None):
|
|||
# Suivant le type de la transaction, on ajoute son montant aux recettes ou au dépenses et
|
||||
# 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:
|
||||
if transaction.transaction_type.transaction_type == EXTENSES:
|
||||
sum_extense_simulated += tmp_Amount
|
||||
if transaction.is_simulated is not None and transaction.is_simulated == 0:
|
||||
sum_extense += tmp_Amount
|
||||
|
@ -714,7 +656,7 @@ def transaction_by_year_listing(request, accounting_year, t_type=None):
|
|||
total = sumrecette - sum_extense
|
||||
total_simulated = sumrecette_simulated - sum_extense_simulated
|
||||
|
||||
nb_transaction = transaction_list.count()
|
||||
nb_transaction = transactions_list.count()
|
||||
context = {
|
||||
"transaction_list": transaction_list_and_sum,
|
||||
"accounting_year": accounting_year,
|
||||
|
@ -726,7 +668,7 @@ def transaction_by_year_listing(request, accounting_year, t_type=None):
|
|||
"total_simulated": total_simulated,
|
||||
"date_sum": date_sum,
|
||||
"nb_transaction": nb_transaction,
|
||||
"t_type": t_type,
|
||||
"t_type": transaction_kind,
|
||||
}
|
||||
return render(request, "year_transaction_listing.html", context)
|
||||
|
||||
|
@ -742,7 +684,7 @@ def year_listing(request):
|
|||
year_list.append(
|
||||
(
|
||||
year.year,
|
||||
Transaction.objects.filter(registrationDate__year=year.year).count(),
|
||||
Transaction.objects.by_year(year.year).count(),
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -763,14 +705,11 @@ def transaction_listing_for_year_and_type(request, accounting_year, transaction_
|
|||
(???)
|
||||
"""
|
||||
transaction_type = TransactionType.objects.get(pk=transaction_type_id)
|
||||
|
||||
by_year_condition = Q(registrationDate__year=accounting_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")
|
||||
transaction_list = Transaction.objects.by_year(accounting_year).filter((by_type_condition | by_parent_type_condition)).order_by("registrationDate")
|
||||
|
||||
total = 0
|
||||
total_simulated = 0
|
||||
|
|
|
@ -15,22 +15,22 @@
|
|||
<th class="centered">Montant</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for line in table.lines %}
|
||||
{% for transaction in transactions_list.transactions_list %}
|
||||
<tr>
|
||||
<td>{{ line.id }}</td>
|
||||
<td class="push-right">{{ line.registrationDate | date:"d-m-Y" }}</td>
|
||||
<td><a href="{% url 'annualcomptability:compta_details' line.id %}">{{ line.description }}</a></td>
|
||||
<td>{% if line.bkExtractNumber %}{{ line.bkExtractNumber }}{% endif %}</td>
|
||||
<td class="push-right">{{ line.bkAmount }}</td>
|
||||
<td>{% if line.bxExtractNumber %}{{ line.bxExtractNumber }}{% endif %}</td>
|
||||
<td class="push-right">{{ line.bxAmount }}</td>
|
||||
<td class="push-right">{{ line.totalAmount }}</td>
|
||||
<td>{{ transaction.id }}</td>
|
||||
<td class="push-right">{{ transaction.registrationDate | date:"d-m-Y" }}</td>
|
||||
<td><a href="{% url 'annualcomptability:compta_details' transaction.id %}">{{ transaction.description }}</a></td>
|
||||
<td>{% if transaction.bkExtractNumber %}{{ transaction.bkExtractNumber }}{% endif %}</td>
|
||||
<td class="push-right">{{ transaction.bkAmount }}</td>
|
||||
<td>{% if transaction.bxExtractNumber %}{{ transaction.bxExtractNumber }}{% endif %}</td>
|
||||
<td class="push-right">{{ transaction.bxAmount }}</td>
|
||||
<td class="push-right">{{ transaction.totalAmount }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
<td colspan="3" class="push-right"><b>TOTAL</b></td>
|
||||
<td colspan="2" class="push-right"><b>{{ table.sum_BkAmount }}</b></td>
|
||||
<td colspan="2" class="push-right"><b>{{ table.sum_BxAmount }}</b></td>
|
||||
<td class="push-right"><b>{{ table.sum_TotalAmount }}</b></td>
|
||||
<td colspan="2" class="push-right"><b>{{ transactions_list.sum_bank_amount }}</b></td>
|
||||
<td colspan="2" class="push-right"><b>{{ transactions_list.sum_box_amount }}</b></td>
|
||||
<td class="push-right"><b>{{ transactions_list.sum_total_amount }}</b></td>
|
||||
</tr>
|
||||
</table>
|
|
@ -15,8 +15,8 @@
|
|||
<div class="col-md-8 col-md-offset-2">
|
||||
<table class="table table-striped table-bordered table-condensed col-md-8">
|
||||
<thead>
|
||||
<th class="centered">Années comptables</th>
|
||||
<th class="centered">Transactions</th>
|
||||
<th class="centered">Années </th>
|
||||
<th class="centered"># Transactions</th>
|
||||
<th class="centered" colspan="2">Suivi</th>
|
||||
<th class="centered">Export SPF Finance</th>
|
||||
</thead>
|
||||
|
|
|
@ -22,17 +22,17 @@
|
|||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
||||
{% display_table compta_depenses %}
|
||||
{% display_table transactions_list_expenses %}
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
||||
<h3>Recettes {{ accounting_year }}</h3>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
||||
{% display_table compta_recettes %}
|
||||
{% display_table transactions_list_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' accounting_year %}">Listing</a> | <a href="{% url 'annualcomptability:export' accounting_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> | <a href="{% url 'annualcomptability:export_simple' accounting_year %}">Export SPF</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<div id="content">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
|
||||
<h1>Année {{ accounting_year }} <small>({% if t_type %}{{t_type}} uniquement - {% endif %}{{ nb_transaction }} transactions)</small></h1>
|
||||
<h1>Année {{ accounting_year }} <small>({% if t_type != 'Tous' %}{{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">
|
||||
|
|
Loading…
Reference in New Issue