From f3a6cfade6dab9136cf1eda43094eb3fb66bd64a Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 23 Oct 2024 12:20:26 +0200 Subject: [PATCH] [IMP] account_bank_reconciliation_summary_xlsx: add block to have difference et justification (entered by user) --- .../i18n/fr.po | 32 ++++++++- .../report/bank_reconciliation_xlsx.py | 68 +++++++++++++++---- 2 files changed, 84 insertions(+), 16 deletions(-) diff --git a/account_bank_reconciliation_summary_xlsx/i18n/fr.po b/account_bank_reconciliation_summary_xlsx/i18n/fr.po index 158cec0..c981285 100644 --- a/account_bank_reconciliation_summary_xlsx/i18n/fr.po +++ b/account_bank_reconciliation_summary_xlsx/i18n/fr.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 14.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-10-22 10:40+0000\n" -"PO-Revision-Date: 2024-10-22 10:40+0000\n" +"POT-Creation-Date: 2024-10-23 10:04+0000\n" +"PO-Revision-Date: 2024-10-23 10:04+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -17,6 +17,7 @@ msgstr "" #. module: account_bank_reconciliation_summary_xlsx #: code:addons/account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py:0 +#: code:addons/account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py:0 #, python-format msgid "Amount" msgstr "Montant" @@ -27,6 +28,12 @@ msgstr "Montant" msgid "Balance %s:" msgstr "Solde %s :" +#. module: account_bank_reconciliation_summary_xlsx +#: code:addons/account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py:0 +#, python-format +msgid "Bank Balance:" +msgstr "Solde bancaire :" + #. module: account_bank_reconciliation_summary_xlsx #: model:ir.model.fields,field_description:account_bank_reconciliation_summary_xlsx.field_bank_reconciliation_report_wizard__journal_ids msgid "Bank Journals" @@ -103,10 +110,23 @@ msgstr "Devise" #. module: account_bank_reconciliation_summary_xlsx #: code:addons/account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py:0 #: code:addons/account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py:0 +#: code:addons/account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py:0 #: model:ir.model.fields,field_description:account_bank_reconciliation_summary_xlsx.field_bank_reconciliation_report_wizard__date #, python-format msgid "Date" -msgstr "" +msgstr "Date" + +#. module: account_bank_reconciliation_summary_xlsx +#: code:addons/account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py:0 +#, python-format +msgid "Description" +msgstr "Description" + +#. module: account_bank_reconciliation_summary_xlsx +#: code:addons/account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py:0 +#, python-format +msgid "Difference:" +msgstr "Écart :" #. module: account_bank_reconciliation_summary_xlsx #: model:ir.model.fields,field_description:account_bank_reconciliation_summary_xlsx.field_bank_reconciliation_report_wizard__display_name @@ -155,6 +175,12 @@ msgstr "" msgid "Journal Entry" msgstr "Pièce" +#. module: account_bank_reconciliation_summary_xlsx +#: code:addons/account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py:0 +#, python-format +msgid "Justification:" +msgstr "Justification :" + #. module: account_bank_reconciliation_summary_xlsx #: code:addons/account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py:0 #, python-format diff --git a/account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py b/account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py index 9f17d84..16c01ce 100644 --- a/account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py +++ b/account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py @@ -65,6 +65,10 @@ class BankReconciliationXlsx(models.AbstractModel): return res def _write_move_lines_block(self, jdi, row, account, add2total=True): + # Returns row + # For suspense lines, it may not add any cells if there are no suspense lines + # => in this case, it doesn't increment row + # If it adds cells, it returns row + 2 to add 2 empty rows at the end sheet = jdi['sheet'] style = jdi['style'] style_suffix = not add2total and '_warn' or '' @@ -78,7 +82,7 @@ class BankReconciliationXlsx(models.AbstractModel): if add2total: sheet.write(row, 2, _("None"), style['none']) else: - return + return row else: row += 1 col_labels = [ @@ -112,13 +116,12 @@ class BankReconciliationXlsx(models.AbstractModel): sheet.write(row, col, "", style[f"title{style_suffix}"]) sheet.write(row, 1, _("Sub-total:") + ' ', style[f"title_right{style_suffix}"]) - formula = '=SUM(%s%d:%s%d)' % ( - jdi['total_col'], start_line, jdi['total_col'], end_line) + formula = f"=SUM({jdi['total_col']}{start_line}:{jdi['total_col']}{end_line})" sheet.write_formula(row, 2, formula, style[f"{jdi['currency']}_bg{style_suffix}"], subtotal) if add2total: jdi['total'] += subtotal - jdi['total_formula'] += '+%s%d' % (jdi['total_col'], row + 1) - return row + jdi['total_formula'] += f"+{jdi['total_col']}{row + 1}" + return row + 2 def generate_xlsx_report(self, workbook, data, wizard): lang = self.env.user.lang @@ -224,37 +227,74 @@ class BankReconciliationXlsx(models.AbstractModel): sheet.write(row, 2, account_bal, style[f"{jdi['currency']}_bg"]) jdi['total'] += account_bal - jdi['total_formula'] += '%s%d' % (jdi['total_col'], row + 1) + jdi['total_formula'] += f"{jdi['total_col']}{row + 1}" row += 2 # 2) Show payment lines IN (debit) debit_account = journal.payment_debit_account_id row = self._write_move_lines_block(jdi, row, debit_account) - row += 2 # 3) Show payment lines OUT (credit) credit_account = journal.payment_credit_account_id row = self._write_move_lines_block(jdi, row, credit_account) - row += 2 for col in range(1): sheet.write(row, col, "", style['title']) sheet.write(row, 1, _("TOTAL:") + ' ', style['title_right']) sheet.write_formula( row, 2, jdi['total_formula'], style[f"{jdi['currency']}_bg"], jdi['total']) - row += 3 + total_row = row + row += 2 # 4) Show suspense account lines row = self._write_move_lines_block( jdi, row, journal.suspense_account_id, add2total=False) + # Static cells + for col in range(1): + sheet.write(row, col, "", style['title']) + sheet.write(row, 1, _("Bank Balance:") + ' ', style['title_right']) + sheet.write(row, 2, 0, style[f"{jdi['currency']}_bg_manual"]) + bank_bal_row = row + row += 2 + for col in range(1): + sheet.write(row, col, "", style['title']) + sheet.write(row, 1, _("Difference:") + ' ', style['title_right']) + sheet.write_formula( + row, 2, f"={jdi['total_col']}{total_row + 1}-{jdi['total_col']}{bank_bal_row + 1}", + style[f"{jdi['currency']}_bg"], jdi['total']) + row += 2 + for col in range(1): + sheet.write(row, col, "", style['title']) + sheet.write(row, 1, _("Justification:") + ' ', style['title_right']) + justif_lines = 6 + sheet.write_formula( + row, 2, f"=SUM({jdi['total_col']}{row+3}:{jdi['total_col']}{row+3+justif_lines-1})", + style[f"{jdi['currency']}_bg"], 0) + row += 1 + col_labels = [ + _("Date"), + _("Description"), + _("Amount"), + ] + col = 0 + for col_label in col_labels: + sheet.write(row, col, col_label, style['col_header']) + col += 1 + for x in range(justif_lines): + row += 1 + sheet.write(row, 0, "", style['regular_date']) + sheet.write(row, 1, "", style['regular']) + sheet.write(row, 2, "", style[jdi['currency']]) + def _get_style(self, workbook, company): style = {} font_size = 10 light_grey = "#eeeeee" light_blue = "#e0edff" subtotal_orange = "#ffcc00" - title_warn = "#ff9999" subtotal_warn = "#ffff99" + amount_manual = "#ffeeab" + title_warn = "#ff9999" lang_code = self.env.user.lang lang = False if lang_code: @@ -307,12 +347,12 @@ class BankReconciliationXlsx(models.AbstractModel): dict(title_style, align="left", bg_color=title_warn)) style['title_right_warn'] = workbook.add_format( dict(title_style, align="right", bg_color=title_warn)) - style['regular'] = workbook.add_format({"font_size": font_size}) + style['regular'] = workbook.add_format({"font_size": font_size, "border": 1}) if "%" in xls_date_format: # fallback xls_date_format = "yyyy-mm-dd" style['regular_date'] = workbook.add_format( - {"num_format": xls_date_format, "font_size": font_size, "align": "left"} + {"num_format": xls_date_format, "font_size": font_size, "align": "left", "border": 1} ) for currency in self.env['res.currency'].search([]): symbol = currency.symbol or currency.name @@ -325,9 +365,11 @@ class BankReconciliationXlsx(models.AbstractModel): # and thousand separator by those of the language under which # Excel runs currency_style = {"num_format": cur_format, "font_size": font_size} - style[currency] = workbook.add_format(currency_style) + style[currency] = workbook.add_format(dict(currency_style, border=1)) style[f'{currency}_bg'] = workbook.add_format( dict(currency_style, bg_color=subtotal_orange)) style[f'{currency}_bg_warn'] = workbook.add_format( dict(currency_style, bg_color=subtotal_warn)) + style[f'{currency}_bg_manual'] = workbook.add_format( + dict(currency_style, bg_color=amount_manual)) return style