Code refactoring and lisibility improvement.

This commit is contained in:
Trullemans Gregory 2020-02-27 13:10:20 +01:00
parent 0172ec1d6a
commit c5b76ffacf
2 changed files with 178 additions and 195 deletions

View File

@ -174,7 +174,7 @@ def get_transactiontypes_and_total_amount_transactions(
def get_transactiontype_and_sum_for_spf_export(accounting_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, 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 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 simulées` appartenant à ce type de transactions et va ensuite additionner les montants totaux
du type de transaction. du type de transaction.

View File

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