Code refactoring and lisibility improvement.
This commit is contained in:
parent
0172ec1d6a
commit
c5b76ffacf
|
@ -174,7 +174,7 @@ def get_transactiontypes_and_total_amount_transactions(
|
|||
|
||||
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,
|
||||
Récupère tous les types de transactions sans parent 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.
|
||||
|
|
|
@ -65,9 +65,9 @@ class PDFDocument(object):
|
|||
# Create the PDF object, using the response object as its "file."
|
||||
self.document = canvas.Canvas(response, pagesize=A4)
|
||||
self.y = Y - X
|
||||
self.load_config()
|
||||
self.__load_config()
|
||||
|
||||
def load_config(self):
|
||||
def __load_config(self):
|
||||
""" Charge le contenu du fichier SITE_CONFIG.YAML qui contient les données relatives à l'ASBL
|
||||
"""
|
||||
current_path = os.path.dirname(os.path.realpath(__file__))
|
||||
|
@ -80,22 +80,22 @@ class PDFDocument(object):
|
|||
|
||||
def generate_spf_export(self, accounting_year):
|
||||
""" Genère un document aux normes du SPF Finance """
|
||||
self.header()
|
||||
self.title_spf(accounting_year)
|
||||
self.recette_expenses(accounting_year)
|
||||
self.annexes(accounting_year)
|
||||
self.add_header()
|
||||
self.add_title_spf(accounting_year)
|
||||
self.add_recette_expenses(accounting_year)
|
||||
self.add_annexes(accounting_year)
|
||||
|
||||
def generate_bill_paper(self, contract):
|
||||
""" Génère une facture pour un contrat """
|
||||
self.amount = 0
|
||||
self.header(contract)
|
||||
self.title_billing(contract)
|
||||
self.prestations(contract)
|
||||
self.conclusion(contract)
|
||||
self.addSignature()
|
||||
self.footer()
|
||||
self.add_header(contract)
|
||||
self.add_title_billing(contract)
|
||||
self.add_prestations(contract)
|
||||
self.add_conclusion(contract)
|
||||
self.add_signature()
|
||||
self.add_footer()
|
||||
|
||||
def newline(self, height=None):
|
||||
def add_vspace(self, height=None):
|
||||
""" Passe à la ligne, la hauteur de la ligne étant passée en paramètre.
|
||||
|
||||
Args:
|
||||
|
@ -114,16 +114,15 @@ class PDFDocument(object):
|
|||
# document.PageBreak()
|
||||
# y = 790
|
||||
|
||||
def drawString(
|
||||
def add_string(
|
||||
self, x, string, font_family="Helvetica", font_decoration=None, font_size=10
|
||||
):
|
||||
font = font_family
|
||||
if font_decoration is not None:
|
||||
font += "-" + font_decoration
|
||||
self.document.setFont(font, font_size)
|
||||
font_family += "-" + font_decoration
|
||||
self.document.setFont(font_family, font_size)
|
||||
self.document.drawString(x, self.y, string)
|
||||
|
||||
def drawNewLine(
|
||||
def add_new_line(
|
||||
self,
|
||||
x,
|
||||
string,
|
||||
|
@ -132,22 +131,22 @@ class PDFDocument(object):
|
|||
font_decoration=None,
|
||||
font_size=10,
|
||||
):
|
||||
self.newline(height)
|
||||
self.drawString(x, string, font_family, font_decoration, font_size)
|
||||
self.add_vspace(height)
|
||||
self.add_string(x, string, font_family, font_decoration, font_size)
|
||||
|
||||
def header(self, contract=None):
|
||||
""" Génère le header de la facture.
|
||||
def add_header(self, contract=None):
|
||||
""" Génère le header du document.
|
||||
|
||||
Args:
|
||||
contract (contract): instance de la class Contract.
|
||||
"""
|
||||
rect_height = 40
|
||||
self.document.rect(X, self.y, RIGHT_X - X, -rect_height, fill=0)
|
||||
self.drawNewLine(INDENTED_X, self.club_infos["NAME"])
|
||||
self.add_new_line(INDENTED_X, self.club_infos["NAME"])
|
||||
self.document.drawRightString(
|
||||
INDENTED_RIGHT_X, self.y, "N° Entreprise : " + self.club_infos["BCE_NUMBER"]
|
||||
)
|
||||
self.drawNewLine(
|
||||
self.add_new_line(
|
||||
INDENTED_X,
|
||||
"Siège social : "
|
||||
+ self.club_infos["ADDRESS"]
|
||||
|
@ -160,9 +159,9 @@ class PDFDocument(object):
|
|||
self.document.drawRightString(
|
||||
INDENTED_RIGHT_X, self.y, "N° de Référence : " + str(contract.reference)
|
||||
)
|
||||
self.newline(BIG_LINE_HEIGHT)
|
||||
self.add_vspace(BIG_LINE_HEIGHT)
|
||||
|
||||
def title_billing(self, contract):
|
||||
def add_title_billing(self, contract):
|
||||
""" Génère le "titre" de la facture.
|
||||
|
||||
Args:
|
||||
|
@ -175,43 +174,43 @@ class PDFDocument(object):
|
|||
res += contract.client.contact.count("f")
|
||||
# res += contract.client.contact.count('r')
|
||||
|
||||
self.drawString(TITLED_X, "A l'attention de")
|
||||
self.drawString(194.25, contract.client.contact, font_decoration="Bold")
|
||||
self.add_string(TITLED_X, "A l'attention de")
|
||||
self.add_string(194.25, contract.client.contact, font_decoration="Bold")
|
||||
|
||||
if contract.client.is_company:
|
||||
self.drawString(
|
||||
self.add_string(
|
||||
194.25 + ((len(contract.client.contact) - res / 1.5) * 5.8), " pour la"
|
||||
)
|
||||
self.drawNewLine(TITLED_X, contract.client.name, font_decoration="Bold")
|
||||
self.add_new_line(TITLED_X, contract.client.name, font_decoration="Bold")
|
||||
|
||||
self.drawNewLine(TITLED_X, contract.client.address)
|
||||
self.drawNewLine(
|
||||
self.add_new_line(TITLED_X, contract.client.address)
|
||||
self.add_new_line(
|
||||
TITLED_X, str(contract.client.postal_code) + " " + contract.client.city
|
||||
)
|
||||
self.newline()
|
||||
self.drawNewLine(TITLED_X, "Concernant la/le")
|
||||
self.drawString(200, contract.name, font_decoration="Bold")
|
||||
self.newline()
|
||||
self.add_vspace()
|
||||
self.add_new_line(TITLED_X, "Concernant la/le")
|
||||
self.add_string(200, contract.name, font_decoration="Bold")
|
||||
self.add_vspace()
|
||||
|
||||
def title_spf(self, accounting_year):
|
||||
self.drawString(
|
||||
def add_title_spf(self, accounting_year):
|
||||
self.add_string(
|
||||
130,
|
||||
"Comptes simplifiés de l'exercice " + accounting_year,
|
||||
font_decoration="Bold",
|
||||
font_size=20,
|
||||
)
|
||||
self.newline(DOUBLE_LINE_HEIGHT)
|
||||
self.add_vspace(DOUBLE_LINE_HEIGHT)
|
||||
|
||||
def payementInformation(self, contract):
|
||||
def add_payement_informations(self, contract):
|
||||
""" Génère les informations de payement.
|
||||
|
||||
Args:
|
||||
contract (contract): instance de la class Contract.
|
||||
"""
|
||||
self.newline()
|
||||
self.add_vspace()
|
||||
height = 40
|
||||
self.document.rect(X, self.y - height, RIGHT_X - X, height, fill=0)
|
||||
self.drawNewLine(INDENTED_X, "N° Entreprise : " + self.club_infos["BCE_NUMBER"])
|
||||
self.add_new_line(INDENTED_X, "N° Entreprise : " + self.club_infos["BCE_NUMBER"])
|
||||
|
||||
if contract.client.company_number:
|
||||
self.document.drawRightString(
|
||||
|
@ -219,7 +218,7 @@ class PDFDocument(object):
|
|||
self.y,
|
||||
"Votre N° Entreprise : " + contract.client.company_number,
|
||||
)
|
||||
self.drawNewLine(
|
||||
self.add_new_line(
|
||||
INDENTED_X,
|
||||
"IBAN : "
|
||||
+ self.club_infos["IBAN"]
|
||||
|
@ -229,61 +228,60 @@ class PDFDocument(object):
|
|||
+ self.club_infos["BANK"]
|
||||
+ ")",
|
||||
)
|
||||
self.newline(DOUBLE_LINE_HEIGHT)
|
||||
self.add_vspace(DOUBLE_LINE_HEIGHT)
|
||||
|
||||
def prestations(self, contract):
|
||||
def add_prestations(self, contract):
|
||||
""" Génère l'affichage des prestations : tableau, liste des prestations, …
|
||||
|
||||
Args:
|
||||
contract (contract): instance de la class Contract.
|
||||
"""
|
||||
self.drawNewLine(X, "Prestations", font_decoration="Bold")
|
||||
total = self.drawPrestationsTable(contract.get_prestation.all())
|
||||
self.newline(DOUBLE_LINE_HEIGHT)
|
||||
self.add_new_line(X, "Prestations", font_decoration="Bold")
|
||||
total = self.draw_prestations_table(contract.get_prestation.all())
|
||||
self.add_vspace(DOUBLE_LINE_HEIGHT)
|
||||
self.document.setFont("Helvetica", 10)
|
||||
self.document.drawRightString(INDENTED_X + 445, self.y, "Acompte")
|
||||
self.document.drawRightString(INDENTED_RIGHT_X, self.y, str(contract.advance))
|
||||
self.newline()
|
||||
self.add_vspace()
|
||||
self.document.setFont("Helvetica-Bold", 10)
|
||||
self.document.drawRightString(INDENTED_X + 445, self.y, "Solde à payer")
|
||||
self.amount = total - contract.advance
|
||||
self.document.drawRightString(INDENTED_RIGHT_X, self.y, str(self.amount))
|
||||
|
||||
def drawColoredRow(self):
|
||||
def draw_colored_row(self, c=0.43, m=0.2, y=0, k=0):
|
||||
""" Génère une ligne colorée. """
|
||||
self.document.setFillColorCMYK(0.43, 0.2, 0, 0)
|
||||
self.document.setFillColorCMYK(c, y, m, k)
|
||||
self.document.rect(
|
||||
X, self.y - 4, RIGHT_X - X, COMMON_LINE_HEIGHT, fill=True, stroke=False
|
||||
)
|
||||
self.document.setFillColorCMYK(0, 0, 0, 1)
|
||||
|
||||
def drawHeaderPrestationsTable(self):
|
||||
def draw_prestations_table_header(self):
|
||||
""" Génère le header de la table des prestations. """
|
||||
self.drawColoredRow()
|
||||
self.newline()
|
||||
self.draw_colored_row()
|
||||
self.add_vspace()
|
||||
|
||||
self.document.setFillColorCMYK(0, 0, 0, 1)
|
||||
self.drawString(INDENTED_X, "Date")
|
||||
self.drawString(PRESTATION_COLUMN_2, "Libellé")
|
||||
self.drawString(INDENTED_X + 365, "Nbre")
|
||||
self.drawString(INDENTED_X + 420, "Prix Unit.")
|
||||
self.add_string(INDENTED_X, "Date")
|
||||
self.add_string(PRESTATION_COLUMN_2, "Libellé")
|
||||
self.add_string(INDENTED_X + 365, "Nbre")
|
||||
self.add_string(INDENTED_X + 420, "Prix Unit.")
|
||||
|
||||
self.document.setFont("Helvetica-Bold", 10)
|
||||
self.document.drawRightString(INDENTED_X + 510, self.y, "Total")
|
||||
|
||||
def drawFooterPrestationTable(self, total):
|
||||
def draw_prestations_table_footer(self, total):
|
||||
""" Génère le footer de la table des prestations.
|
||||
|
||||
Args:
|
||||
total (int): somme totale des prestations.
|
||||
"""
|
||||
self.drawColoredRow()
|
||||
self.newline()
|
||||
self.draw_colored_row()
|
||||
self.add_vspace()
|
||||
self.document.setFont("Helvetica-Bold", 10)
|
||||
self.document.drawRightString(INDENTED_X + 445, self.y, "Total")
|
||||
self.document.drawRightString(INDENTED_RIGHT_X, self.y, str(total))
|
||||
|
||||
def displayPrestation(self, prestation, total):
|
||||
def display_prestations(self, prestation, total):
|
||||
""" Affiche une ligne de prestation dans le tableau.
|
||||
|
||||
Args:
|
||||
|
@ -294,8 +292,8 @@ class PDFDocument(object):
|
|||
total (int): somme totale des prestations.
|
||||
"""
|
||||
total += prestation.total_amount
|
||||
self.drawNewLine(INDENTED_X, str(prestation.date))
|
||||
self.drawString(PRESTATION_COLUMN_2, prestation.label)
|
||||
self.add_new_line(INDENTED_X, str(prestation.date))
|
||||
self.add_string(PRESTATION_COLUMN_2, prestation.label)
|
||||
self.document.drawRightString(PRESTATION_COLUMN_3, self.y, str(prestation.unit))
|
||||
self.document.drawRightString(
|
||||
PRESTATION_COLUMN_4, self.y, str(prestation.unit_price)
|
||||
|
@ -305,39 +303,39 @@ class PDFDocument(object):
|
|||
)
|
||||
return total
|
||||
|
||||
def drawPrestationsTable(self, prestations_list):
|
||||
def draw_prestations_table(self, prestations_list):
|
||||
""" Génère le tableau des prestations.
|
||||
|
||||
Args:
|
||||
prestations_list (list): liste des prestations d'un contrat
|
||||
"""
|
||||
self.drawHeaderPrestationsTable()
|
||||
self.draw_prestations_table_header()
|
||||
total = 0
|
||||
for prestation in prestations_list:
|
||||
total = self.displayPrestation(prestation, total)
|
||||
self.drawFooterPrestationTable(total)
|
||||
total = self.display_prestations(prestation, total)
|
||||
self.draw_prestations_table_footer(total)
|
||||
return total
|
||||
|
||||
def conclusion(self, contract):
|
||||
""" Affiche la conclusion de la facture.
|
||||
def add_conclusion(self, contract):
|
||||
""" Affiche la add_add_conclusion de la facture.
|
||||
|
||||
Args:
|
||||
contract (contract): instance de la class Contract.
|
||||
"""
|
||||
self.newline(DOUBLE_LINE_HEIGHT)
|
||||
self.add_vspace(DOUBLE_LINE_HEIGHT)
|
||||
self.document.rect(X, self.y, RIGHT_X - X, BIG_LINE_HEIGHT, fill=0)
|
||||
self.drawNewLine(INDENTED_X, "Merci de bien vouloir payer la somme de ")
|
||||
self.drawString(INDENTED_X + 184, str(self.amount), font_decoration="Bold")
|
||||
self.drawString(INDENTED_X + 215, "€ sur le compte ")
|
||||
self.drawString(INDENTED_X + 290, self.club_infos["IBAN"], font_decoration="Bold")
|
||||
self.drawString(INDENTED_X + 390, " (" + self.club_infos["BIC"] + " - " + self.club_infos["BANK"] + ")")
|
||||
self.newline(COMMON_LINE_HEIGHT)
|
||||
self.add_new_line(INDENTED_X, "Merci de bien vouloir payer la somme de ")
|
||||
self.add_string(INDENTED_X + 184, str(self.amount), font_decoration="Bold")
|
||||
self.add_string(INDENTED_X + 215, "€ sur le compte ")
|
||||
self.add_string(INDENTED_X + 290, self.club_infos["IBAN"], font_decoration="Bold")
|
||||
self.add_string(INDENTED_X + 390, " (" + self.club_infos["BIC"] + " - " + self.club_infos["BANK"] + ")")
|
||||
self.add_vspace(COMMON_LINE_HEIGHT)
|
||||
|
||||
if not contract.is_paid:
|
||||
the_date = datetime.now()
|
||||
pay_date = the_date + timedelta(days=15)
|
||||
self.drawString(INDENTED_X, "Pour le ")
|
||||
self.drawString(
|
||||
self.add_string(INDENTED_X, "Pour le ")
|
||||
self.add_string(
|
||||
INDENTED_X + 35,
|
||||
str(pay_date.day)
|
||||
+ "/"
|
||||
|
@ -346,16 +344,16 @@ class PDFDocument(object):
|
|||
+ str(pay_date.year),
|
||||
font_decoration="Bold",
|
||||
)
|
||||
self.drawString(INDENTED_X + 85, " au plus tard, avec la référence :")
|
||||
self.drawString(
|
||||
self.add_string(INDENTED_X + 85, " au plus tard, avec la référence :")
|
||||
self.add_string(
|
||||
INDENTED_X + 230,
|
||||
'"' + str(contract.reference) + '"',
|
||||
font_decoration="Bold",
|
||||
)
|
||||
|
||||
def addSignature(self):
|
||||
def add_signature(self):
|
||||
""" Génère la signature. """
|
||||
self.newline(BIG_LINE_HEIGHT)
|
||||
self.add_vspace(BIG_LINE_HEIGHT)
|
||||
self.document.drawString(
|
||||
INDENTED_X,
|
||||
self.y,
|
||||
|
@ -363,78 +361,79 @@ class PDFDocument(object):
|
|||
)
|
||||
self.document.drawRightString(RIGHT_X, self.y, "Président")
|
||||
url = os.path.join(settings.STATICFILES_DIRS[0], "img/signature.png")
|
||||
self.newline(DOUBLE_LINE_HEIGHT)
|
||||
self.add_vspace(DOUBLE_LINE_HEIGHT)
|
||||
self.document.drawImage(url, INDENTED_X + 340, self.y, width=180, height=39)
|
||||
|
||||
def footer(self):
|
||||
def add_footer(self):
|
||||
""" Ajoute les conditions générales de payement. """
|
||||
self.y = 175
|
||||
self.newline(DOUBLE_LINE_HEIGHT)
|
||||
self.drawNewLine(
|
||||
self.add_vspace(DOUBLE_LINE_HEIGHT)
|
||||
self.add_new_line(
|
||||
INDENTED_X, "CONDITIONS GENERALES DE PAIEMENT", font_decoration="Bold"
|
||||
)
|
||||
self.drawNewLine(INDENTED_X, "Facture payable au comptant.")
|
||||
self.drawNewLine(
|
||||
self.add_new_line(INDENTED_X, "Facture payable au comptant.")
|
||||
self.add_new_line(
|
||||
INDENTED_X,
|
||||
"""En cas de défaut de paiement à l'échéance, il est dû de plein droit et sans mise en demeure, un interêt fixé au taux de""",
|
||||
)
|
||||
self.drawNewLine(INDENTED_X, "15% l'an.")
|
||||
self.drawNewLine(
|
||||
self.add_new_line(INDENTED_X, "15% l'an.")
|
||||
self.add_new_line(
|
||||
INDENTED_X,
|
||||
"""Tout réclamation, pour être admise, doit être faite dans les huit jours de la réception de la facture.""",
|
||||
)
|
||||
self.drawNewLine(
|
||||
self.add_new_line(
|
||||
INDENTED_X,
|
||||
"""En cas de litige concernant la présente facture, seuls les tribunaux de MONS seront compétents.""",
|
||||
)
|
||||
|
||||
def recette_expenses(self, accounting_year):
|
||||
self.drawString(
|
||||
def add_recette_expenses(self, accounting_year):
|
||||
self.add_string(
|
||||
X, "Etat recettes/dépenses (en €)", font_decoration="Oblique", font_size=14
|
||||
)
|
||||
self.__display_transactions_table(accounting_year)
|
||||
self.newline()
|
||||
self.__display_transactiontypes_table(accounting_year)
|
||||
self.add_vspace()
|
||||
|
||||
def __display_transactions_table(self, accounting_year):
|
||||
self.__display_table_header("DEPENSES", "RECETTES")
|
||||
def __display_transactiontypes_table(self, accounting_year):
|
||||
""" Ajoute le table pour les recettes & dépenses d'une année comptable.
|
||||
|
||||
transactiontypes_extenses = get_transactiontype_and_sum_for_spf_export(
|
||||
Args:
|
||||
accounting_year (int): année comptable
|
||||
"""
|
||||
extenses = get_transactiontype_and_sum_for_spf_export(
|
||||
accounting_year, EXTENSES
|
||||
)
|
||||
transactiontypes_recettes = get_transactiontype_and_sum_for_spf_export(
|
||||
recettes = get_transactiontype_and_sum_for_spf_export(
|
||||
accounting_year, RECETTES
|
||||
)
|
||||
|
||||
self.__display_table_header("DEPENSES", "RECETTES")
|
||||
self.__display_transactiontype_table_body(
|
||||
transactiontypes_extenses, transactiontypes_recettes
|
||||
)
|
||||
|
||||
self.__display_transactiontype_table_footer(
|
||||
int(transactiontypes_extenses["sum_total_transaction"]),
|
||||
int(transactiontypes_recettes["sum_total_transaction"]),
|
||||
extenses,
|
||||
recettes,
|
||||
int(extenses["sum_total_transaction"]),
|
||||
int(recettes["sum_total_transaction"]),
|
||||
)
|
||||
|
||||
def __display_table_header(self, title_left, title_right):
|
||||
self.newline()
|
||||
self.add_vspace()
|
||||
self.document.rect(X, self.y - 5, RIGHT_X - X, -COMMON_LINE_HEIGHT, fill=0)
|
||||
self.drawString(INDENTED_X, title_left, font_decoration="Bold", font_size=9)
|
||||
self.drawString(
|
||||
self.add_string(INDENTED_X, title_left, font_decoration="Bold", font_size=9)
|
||||
self.add_string(
|
||||
MIDDLE + INDENTED_X, title_right, font_decoration="Bold", font_size=9
|
||||
)
|
||||
|
||||
# TODO : à revoir !!!!!!
|
||||
def __display_transactiontype_table_body(
|
||||
self, transactions_extenses, transactions_recettes
|
||||
self, extenses, recettes, totalexpenses, totalrecettes
|
||||
):
|
||||
|
||||
for i in range(4):
|
||||
self.__display_table_line(
|
||||
transactions_extenses["transaction_type_info"][i]["label"],
|
||||
int(transactions_extenses["transaction_type_info"][i]["sum_total_amount"]),
|
||||
transactions_recettes["transaction_type_info"][i]["label"],
|
||||
int(transactions_recettes["transaction_type_info"][i]["sum_total_amount"]),
|
||||
extenses["transaction_type_info"][i]["label"],
|
||||
int(extenses["transaction_type_info"][i]["sum_total_amount"]),
|
||||
recettes["transaction_type_info"][i]["label"],
|
||||
int(recettes["transaction_type_info"][i]["sum_total_amount"]),
|
||||
)
|
||||
self.newline()
|
||||
self.add_vspace()
|
||||
self.document.rect(
|
||||
X, self.y - 5, MIDDLE, 5 * -COMMON_LINE_HEIGHT
|
||||
) # Séparation en deux
|
||||
|
@ -442,57 +441,41 @@ class PDFDocument(object):
|
|||
MIDDLE, self.y - 5, MIDDLE, 5 * -COMMON_LINE_HEIGHT
|
||||
) # Séparation descriptif et montant recettes
|
||||
self.y -= COMMON_LINE_HEIGHT
|
||||
self.__display_table_line("Total des dépenses", totalexpenses, "Total des recettes", totalrecettes, font_decoration="Bold")
|
||||
|
||||
def __display_transactiontype_table_footer(self, totalexpenses, totalrecette):
|
||||
def __display_key_part(self, column_number, key, font_decoration=None):
|
||||
if column_number == 1:
|
||||
space = INDENTED_X
|
||||
else:
|
||||
space = MIDDLE + INDENTED_X
|
||||
self.add_string(
|
||||
space, key, font_decoration=font_decoration, font_size=9
|
||||
)
|
||||
|
||||
def __display_value_part(self, column_number, value):
|
||||
if column_number == 1:
|
||||
space = MIDDLE + X - INDENT
|
||||
else:
|
||||
space = INDENTED_RIGHT_X
|
||||
|
||||
self.document.drawRightString(
|
||||
space,
|
||||
self.y,
|
||||
str(locale.format("%d", int(value), grouping=True)),
|
||||
)
|
||||
|
||||
def __display_column(self, column_number, key, value, font_decoration):
|
||||
self.__display_key_part(column_number, key, font_decoration)
|
||||
self.__display_value_part(column_number, value)
|
||||
|
||||
def __display_table_line(self, key1, value1, key2, value2, font_decoration=None):
|
||||
locale.setlocale(locale.LC_ALL, "pt_br.utf-8")
|
||||
self.document.rect(X, self.y - 5, RIGHT_X - X, COMMON_LINE_HEIGHT, fill=0)
|
||||
self.newline()
|
||||
self.add_vspace()
|
||||
self.__display_column(1, key1, value1, font_decoration)
|
||||
self.__display_column(2, key2, value2, font_decoration)
|
||||
|
||||
# first column
|
||||
self.drawString(
|
||||
INDENTED_X, "Total des dépenses ", font_decoration="Bold", font_size=9
|
||||
)
|
||||
self.document.drawRightString(
|
||||
MIDDLE + X - INDENT,
|
||||
self.y,
|
||||
str(locale.format("%d", int(totalexpenses), grouping=True)),
|
||||
)
|
||||
|
||||
# second column
|
||||
self.drawString(
|
||||
(MIDDLE + INDENTED_X),
|
||||
"Total des recettes ",
|
||||
font_decoration="Bold",
|
||||
font_size=9,
|
||||
)
|
||||
self.document.drawRightString(
|
||||
INDENTED_RIGHT_X,
|
||||
self.y,
|
||||
str(locale.format("%d", int(totalrecette), grouping=True)),
|
||||
)
|
||||
|
||||
def __display_table_line(self, key1, value1, key2, value2):
|
||||
locale.setlocale(locale.LC_ALL, "pt_br.utf-8")
|
||||
self.newline()
|
||||
self.document.rect(X, self.y - 5, RIGHT_X - X, 15, fill=0) # ligne entière
|
||||
|
||||
# first column
|
||||
self.drawString(INDENTED_X, key1, font_size=9)
|
||||
self.document.drawRightString(
|
||||
MIDDLE + X - INDENT,
|
||||
self.y,
|
||||
str(locale.format("%d", int(value1), grouping=True)),
|
||||
)
|
||||
|
||||
# second column
|
||||
self.drawString((MIDDLE + INDENTED_X), key2, font_size=9)
|
||||
self.document.drawRightString(
|
||||
INDENTED_RIGHT_X,
|
||||
self.y,
|
||||
str(locale.format("%d", int(value2), grouping=True)),
|
||||
)
|
||||
|
||||
def annexes(self, accounting_year):
|
||||
def add_annexes(self, accounting_year):
|
||||
""" Ajoute les annexes du document au PDF
|
||||
|
||||
Args:
|
||||
|
@ -501,14 +484,14 @@ class PDFDocument(object):
|
|||
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)
|
||||
self.display_additional_information(accounting_year)
|
||||
self.display_patrimony(accounting_year)
|
||||
self.display_right_engagement(accounting_year)
|
||||
self.add_new_line(X, "Annexes", font_decoration="Oblique", font_size=14)
|
||||
self.add_evaluation_rules(accounting_year)
|
||||
self.add_modification_evaluation_rules(accounting_year)
|
||||
self.add_additional_information(accounting_year)
|
||||
self.add_patrimony(accounting_year)
|
||||
self.add_right_engagement(accounting_year)
|
||||
|
||||
def display_evaluation_rules(self, accounting_year):
|
||||
def add_evaluation_rules(self, accounting_year):
|
||||
""" Ajoute les règles d'évaluation au PDF
|
||||
|
||||
Args:
|
||||
|
@ -517,24 +500,24 @@ class PDFDocument(object):
|
|||
Returns:
|
||||
Ne retourne rien
|
||||
"""
|
||||
self.drawNewLine(X, "1. Résumé des règles d'évaluation")
|
||||
self.add_new_line(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)
|
||||
).exclude(start_date__year__gt=accounting_year)
|
||||
if rules_list:
|
||||
for rule in rules_list:
|
||||
self.drawNewLine(
|
||||
self.add_new_line(
|
||||
INDENTED_X + INDENT * 2,
|
||||
rule.label + " : " + rule.explanation,
|
||||
font_size=9,
|
||||
)
|
||||
else:
|
||||
self.drawNewLine(
|
||||
self.add_new_line(
|
||||
INDENTED_X + INDENT * 2, "Pas de règle d'évaluation.", font_size=9
|
||||
)
|
||||
self.newline()
|
||||
self.add_vspace()
|
||||
|
||||
def display_modification_evaluation_rules(self, accounting_year):
|
||||
def add_modification_evaluation_rules(self, accounting_year):
|
||||
""" Ajoute les modifications d'évaluation au PDF
|
||||
|
||||
Args:
|
||||
|
@ -543,26 +526,26 @@ class PDFDocument(object):
|
|||
Returns:
|
||||
Ne retourne rien
|
||||
"""
|
||||
self.drawNewLine(X, "2. Adaptation des règles d'évaluation")
|
||||
self.add_new_line(X, "2. Adaptation des règles d'évaluation")
|
||||
rules_adaptation_list = EvaluationRulesAdaptation.objects.filter(
|
||||
start_date__year=accounting_year
|
||||
)
|
||||
if rules_adaptation_list:
|
||||
for line in rules_adaptation_list:
|
||||
self.drawNewLine(
|
||||
self.add_new_line(
|
||||
INDENTED_X + INDENT * 2,
|
||||
line.label + " : " + line.information,
|
||||
font_size=9,
|
||||
)
|
||||
else:
|
||||
self.drawNewLine(
|
||||
self.add_new_line(
|
||||
INDENTED_X + INDENT * 2,
|
||||
"Pas d'adaptation des règles d'évaluation.",
|
||||
font_size=9,
|
||||
)
|
||||
self.newline()
|
||||
self.add_vspace()
|
||||
|
||||
def display_additional_information(self, accounting_year):
|
||||
def add_additional_information(self, accounting_year):
|
||||
""" Ajoute les informations complémentaires au PDF
|
||||
|
||||
Args:
|
||||
|
@ -571,27 +554,27 @@ class PDFDocument(object):
|
|||
Returns:
|
||||
Ne retourne rien
|
||||
"""
|
||||
self.drawNewLine(X, "3. Informations complémentaires")
|
||||
self.add_new_line(X, "3. Informations complémentaires")
|
||||
annuality = Annuality.objects.filter(year__year=accounting_year)
|
||||
complementary_informations = ComplementaryInformations.objects.filter(
|
||||
annuality=annuality[0]
|
||||
)
|
||||
if complementary_informations:
|
||||
for line in complementary_informations:
|
||||
self.drawNewLine(
|
||||
self.add_new_line(
|
||||
INDENTED_X + INDENT * 2,
|
||||
line.label + " : " + line.information,
|
||||
font_size=9,
|
||||
)
|
||||
else:
|
||||
self.drawNewLine(
|
||||
self.add_new_line(
|
||||
INDENTED_X + INDENT * 2,
|
||||
"Pas d'informations complémentaires.",
|
||||
font_size=9,
|
||||
)
|
||||
self.newline()
|
||||
self.add_vspace()
|
||||
|
||||
def display_patrimony(self, accounting_year):
|
||||
def add_patrimony(self, accounting_year):
|
||||
""" Ajoute les informations du patrimoine au PDF
|
||||
|
||||
Args:
|
||||
|
@ -600,7 +583,7 @@ class PDFDocument(object):
|
|||
Returns:
|
||||
Ne retourne rien
|
||||
"""
|
||||
self.drawNewLine(X, "4. Etat du patrimoine")
|
||||
self.add_new_line(X, "4. Etat du patrimoine")
|
||||
|
||||
annuality = Annuality.objects.filter(year__year=accounting_year)
|
||||
tmp_compta_extenses = get_transactiontype_and_sum_for_spf_export(
|
||||
|
@ -631,7 +614,7 @@ class PDFDocument(object):
|
|||
if self.y > longest_y:
|
||||
self.y = longest_y
|
||||
|
||||
self.newline()
|
||||
self.add_vspace()
|
||||
|
||||
def __display_table_two_column(self, list, column=1):
|
||||
if column == 1:
|
||||
|
@ -655,7 +638,7 @@ class PDFDocument(object):
|
|||
self.document.rect(
|
||||
begin_rect_res, self.y - 5, X, COMMON_LINE_HEIGHT, fill=0
|
||||
)
|
||||
self.drawNewLine(begin_text, line[0], font_size=9)
|
||||
self.add_new_line(begin_text, line[0], font_size=9)
|
||||
self.document.drawRightString(
|
||||
begin_res, self.y, str(locale.format("%d", int(line[1]), grouping=True))
|
||||
)
|
||||
|
@ -664,7 +647,7 @@ class PDFDocument(object):
|
|||
|
||||
return total
|
||||
|
||||
def display_right_engagement(self, accounting_year):
|
||||
def add_right_engagement(self, accounting_year):
|
||||
""" Ajoute les droits & engagements au PDF
|
||||
|
||||
Args:
|
||||
|
@ -673,15 +656,15 @@ class PDFDocument(object):
|
|||
Returns:
|
||||
Ne retourne rien
|
||||
"""
|
||||
self.drawNewLine(
|
||||
self.add_new_line(
|
||||
X,
|
||||
"5. Droits et engagements importants qui ne sont pas susceptibles d'être quantifiés",
|
||||
)
|
||||
# self.__display_table_header("DROITS", "ENGAGEMENT")
|
||||
self.drawNewLine(
|
||||
self.add_new_line(
|
||||
INDENTED_X + INDENT * 2, "Pas de droits ou d'engagements.", font_size=9
|
||||
)
|
||||
self.newline()
|
||||
self.add_vspace()
|
||||
|
||||
def download(self):
|
||||
# Close the PDF object cleanly, and we're done.
|
||||
|
|
Loading…
Reference in New Issue