From 19dd67e86da8160fc2782f410423a7cb32049278 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Sat, 2 Mar 2019 18:31:32 +0100 Subject: [PATCH] [MIG] account_bank_reconciliation_summary_xlsx from v10 to v12 --- .../__init__.py | 2 - .../__manifest__.py | 12 +- .../models/__init__.py | 2 - .../models/account_move_line.py | 6 +- .../readme/CONFIGURE.rst | 1 + .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 8 + .../readme/USAGE.rst | 5 + .../report/__init__.py | 2 - .../report/bank_reconciliation_xlsx.py | 155 ++++++++++-------- .../report/report.xml | 5 +- .../views/account_bank_statement.xml | 3 +- .../views/account_journal.xml | 5 +- .../views/account_move_line.xml | 5 +- .../wizard/__init__.py | 2 - .../bank_reconciliation_report_wizard.py | 21 +-- ...bank_reconciliation_report_wizard_view.xml | 11 +- 17 files changed, 139 insertions(+), 107 deletions(-) create mode 100644 account_bank_reconciliation_summary_xlsx/readme/CONFIGURE.rst create mode 100644 account_bank_reconciliation_summary_xlsx/readme/CONTRIBUTORS.rst create mode 100644 account_bank_reconciliation_summary_xlsx/readme/DESCRIPTION.rst create mode 100644 account_bank_reconciliation_summary_xlsx/readme/USAGE.rst diff --git a/account_bank_reconciliation_summary_xlsx/__init__.py b/account_bank_reconciliation_summary_xlsx/__init__.py index de9509a6..7660e7bf 100644 --- a/account_bank_reconciliation_summary_xlsx/__init__.py +++ b/account_bank_reconciliation_summary_xlsx/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from . import models from . import report from . import wizard diff --git a/account_bank_reconciliation_summary_xlsx/__manifest__.py b/account_bank_reconciliation_summary_xlsx/__manifest__.py index de9c9a43..c81f9948 100644 --- a/account_bank_reconciliation_summary_xlsx/__manifest__.py +++ b/account_bank_reconciliation_summary_xlsx/__manifest__.py @@ -1,15 +1,15 @@ -# -*- coding: utf-8 -*- -# © 2017 Akretion (Alexis de Lattre ) +# Copyright 2017-2019 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Bank Reconciliation Report', - 'version': '10.0.1.0.0', + 'version': '12.0.1.0.0', 'license': 'AGPL-3', 'author': "Akretion,Odoo Community Association (OCA)", - 'website': 'http://www.akretion.com', - 'summary': 'Adds an XLSX report to help on bank reconciliation', - 'depends': ['account_financial_report_qweb', 'report_xlsx'], + 'website': 'https://github.com/OCA/account-financial-reporting', + 'summary': 'XLSX report to help on bank reconciliation', + 'depends': ['account_financial_report', 'report_xlsx'], 'data': [ 'report/report.xml', 'wizard/bank_reconciliation_report_wizard_view.xml', diff --git a/account_bank_reconciliation_summary_xlsx/models/__init__.py b/account_bank_reconciliation_summary_xlsx/models/__init__.py index 0c1006db..8795b3be 100644 --- a/account_bank_reconciliation_summary_xlsx/models/__init__.py +++ b/account_bank_reconciliation_summary_xlsx/models/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - from . import account_move_line diff --git a/account_bank_reconciliation_summary_xlsx/models/account_move_line.py b/account_bank_reconciliation_summary_xlsx/models/account_move_line.py index 21727012..a9f2605c 100644 --- a/account_bank_reconciliation_summary_xlsx/models/account_move_line.py +++ b/account_bank_reconciliation_summary_xlsx/models/account_move_line.py @@ -1,5 +1,5 @@ -# -*- coding: utf-8 -*- -# © 2017 Akretion (Alexis de Lattre ) +# Copyright 2017-2019 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models @@ -10,4 +10,4 @@ class AccountMoveLine(models.Model): statement_line_date = fields.Date( string='Statement Line Date', - related='move_id.statement_line_id.date', store=True, readonly=True) + related='statement_line_id.date', store=True) diff --git a/account_bank_reconciliation_summary_xlsx/readme/CONFIGURE.rst b/account_bank_reconciliation_summary_xlsx/readme/CONFIGURE.rst new file mode 100644 index 00000000..8b3e6561 --- /dev/null +++ b/account_bank_reconciliation_summary_xlsx/readme/CONFIGURE.rst @@ -0,0 +1 @@ +This module doesn't require any configuration. diff --git a/account_bank_reconciliation_summary_xlsx/readme/CONTRIBUTORS.rst b/account_bank_reconciliation_summary_xlsx/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..ff65d68c --- /dev/null +++ b/account_bank_reconciliation_summary_xlsx/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Alexis de Lattre diff --git a/account_bank_reconciliation_summary_xlsx/readme/DESCRIPTION.rst b/account_bank_reconciliation_summary_xlsx/readme/DESCRIPTION.rst new file mode 100644 index 00000000..d75d9ec3 --- /dev/null +++ b/account_bank_reconciliation_summary_xlsx/readme/DESCRIPTION.rst @@ -0,0 +1,8 @@ +This module adds a Bank Reconciliation Report in Odoo in XLSX format. For each bank journal, the report displays: + +1. The balance of the bank account in the accounting, +2. The list of journal items of the bank account not linked to any bank statement lines, +3. The list of draft bank statement lines not linked to any journal items, +4. The computed balance of the bank account at the bank. + +The last field (computed balance of the bank account at the bank) must be compared to the real bank account balance at the bank. If there is a difference, you need to find the error in the accounting. The field *Computed balance of the bank account at the bank* is a formula, so you can easily change its computation to try to find the difference with the real bank account balance at the bank. diff --git a/account_bank_reconciliation_summary_xlsx/readme/USAGE.rst b/account_bank_reconciliation_summary_xlsx/readme/USAGE.rst new file mode 100644 index 00000000..49384754 --- /dev/null +++ b/account_bank_reconciliation_summary_xlsx/readme/USAGE.rst @@ -0,0 +1,5 @@ +You can launch the Bank Reconciliation Report wizard from: + +* the menu *Invoicing > Reporting > OCA accounting reports > Bank Reconciliation*, +* the form view of a bank statement: click on the button *Bank Reconciliation Report*, +* the invoicing dashboard: on a bank journal, click on the options, then select *Bank Reconciliation*. diff --git a/account_bank_reconciliation_summary_xlsx/report/__init__.py b/account_bank_reconciliation_summary_xlsx/report/__init__.py index ce3ccb2c..c23e36d8 100644 --- a/account_bank_reconciliation_summary_xlsx/report/__init__.py +++ b/account_bank_reconciliation_summary_xlsx/report/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - from . import bank_reconciliation_xlsx 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 635de784..c415b43d 100644 --- a/account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py +++ b/account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py @@ -1,14 +1,76 @@ -# -*- coding: utf-8 -*- -# © 2017 Akretion France (Alexis de Lattre ) +# Copyright 2017-2019 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo.addons.report_xlsx.report.report_xlsx import ReportXlsx -from odoo import fields, _ -from odoo.tools import DEFAULT_SERVER_DATE_FORMAT -from datetime import datetime +from odoo import _, fields, models -class BankReconciliationXlsx(ReportXlsx): +class BankReconciliationXlsx(models.AbstractModel): + _name = 'report.bank.reconciliation.xlsx' + _inherit = 'report.report_xlsx.abstract' + + def _compute_account_balance(self, journal, date): + bank_account = journal.default_debit_account_id + amount_field = 'balance' + # TODO: add support for bank accounts in foreign currency + # if not o.currency_id else 'amount_currency' + query = """ + SELECT sum(%s) FROM account_move_line + WHERE account_id=%%s AND date <= %%s""" % (amount_field, ) + self.env.cr.execute(query, (bank_account.id, date)) + query_results = self.env.cr.dictfetchall() + if query_results: + account_bal = query_results[0].get('sum') or 0.0 + else: + account_bal = 0.0 + return account_bal + + def _prepare_move_lines(self, journal, date): + bank_account = journal.default_debit_account_id + mlines = self.env['account.move.line'].search([ + ('account_id', '=', bank_account.id), + ('journal_id', '=', journal.id), # to avoid initial line + ('date', '<=', date), + '|', ('statement_line_date', '=', False), + ('statement_line_date', '>', date)]) + res = [] + for mline in mlines: + move = mline.move_id + cpart = [] + for line in move.line_ids: + if ( + line.account_id != bank_account and + line.account_id.code not in cpart): + cpart.append(line.account_id.code) + counterpart = ' ,'.join(cpart) + res.append({ + 'date': mline.date, + 'label': mline.name, + 'ref': mline.ref or '', + 'partner': mline.partner_id.display_name or '', + 'amount': mline.balance, + 'statement_line_date': mline.statement_line_date or '', + 'move_number': move.name, + 'counterpart': counterpart, + }) + return res + + def _prepare_draft_statement_lines(self, journal, date): + blines = self.env['account.bank.statement.line'].search([ + ('journal_entry_ids', '=', False), + ('journal_id', '=', journal.id), + ('date', '<=', date)]) + res = [] + for bline in blines: + res.append({ + 'date': bline.date, + 'label': bline.name, + 'ref': bline.ref or '', + 'partner': bline.partner_id.display_name or '', + 'amount': bline.amount, + 'statement_ref': bline.statement_id.display_name, + }) + return res def generate_xlsx_report(self, workbook, data, wizard): date = wizard.date @@ -92,18 +154,7 @@ class BankReconciliationXlsx(ReportXlsx): sheet.write( row, 3, _('Balance %s:') % bank_account.code, title_right) - amount_field = 'balance' - # TODO: add support for bank accounts in foreign currency - # if not o.currency_id else 'amount_currency' - query = """ - SELECT sum(%s) FROM account_move_line - WHERE account_id=%%s AND date <= %%s""" % (amount_field, ) - self.env.cr.execute(query, (bank_account.id, date)) - query_results = self.env.cr.dictfetchall() - if query_results: - account_bal = query_results[0].get('sum') or 0.0 - else: - account_bal = 0.0 + account_bal = self._compute_account_balance(o, date) sheet.write(row, 4, account_bal, regular_currency_bg) bank_bal = account_bal @@ -116,12 +167,7 @@ class BankReconciliationXlsx(ReportXlsx): 'Journal items of account %s not linked to a bank ' 'statement line:') % bank_account.code, label_bold) - mlines = self.env['account.move.line'].search([ - ('account_id', '=', bank_account.id), - ('journal_id', '=', o.id), # to avoid initial line - ('date', '<=', date), - '|', ('statement_line_date', '=', False), - ('statement_line_date', '>', date)]) + mlines = self._prepare_move_lines(o, date) if not mlines: sheet.write(row, 4, _('NONE'), none) else: @@ -138,30 +184,16 @@ class BankReconciliationXlsx(ReportXlsx): for mline in mlines: row += 1 m_end_row = row - move = mline.move_id - bank_bal -= mline.balance - date_dt = fields.Date.from_string(mline.date) - sheet.write(row, 0, date_dt, regular_date) - sheet.write(row, 1, mline.name, regular) - sheet.write(row, 2, mline.ref or '', regular) + bank_bal -= mline['amount'] + sheet.write(row, 0, mline['date'], regular_date) + sheet.write(row, 1, mline['label'], regular) + sheet.write(row, 2, mline['ref'], regular) + sheet.write(row, 3, mline['partner'], regular) + sheet.write(row, 4, mline['amount'], regular_currency) sheet.write( - row, 3, mline.partner_id.display_name or '', regular) - sheet.write(row, 4, mline.balance, regular_currency) - if mline.statement_line_date: - stl_date_dt = fields.Date.from_string( - mline.statement_line_date) - else: - stl_date_dt = '' - sheet.write(row, 5, stl_date_dt, regular_date) - sheet.write(row, 6, move.name, regular) - # counter-part accounts - cpart = [] - for line in move.line_ids: - if ( - line.account_id != bank_account and - line.account_id.code not in cpart): - cpart.append(line.account_id.code) - sheet.write(row, 7, ' ,'.join(cpart), regular) + row, 5, mline['statement_line_date'], regular_date) + sheet.write(row, 6, mline['move_number'], regular) + sheet.write(row, 7, mline['counterpart'], regular) formula += '-SUM(E%d:E%d)' % (m_start_row + 1, m_end_row + 1) @@ -171,10 +203,7 @@ class BankReconciliationXlsx(ReportXlsx): row, 0, _( 'Draft bank statement lines:'), label_bold) - blines = self.env['account.bank.statement.line'].search([ - ('journal_entry_ids', '=', False), - ('journal_id', '=', o.id), - ('date', '<=', date)]) + blines = self._prepare_draft_statement_lines(o, date) if not blines: sheet.write(row, 4, _('NONE'), none) else: @@ -190,18 +219,14 @@ class BankReconciliationXlsx(ReportXlsx): for bline in blines: row += 1 b_end_row = row - bank_bal += bline.amount - date_dt = datetime.strptime( - bline.date, DEFAULT_SERVER_DATE_FORMAT) - sheet.write(row, 0, date_dt, regular_date) - sheet.write(row, 1, bline.name, regular) - sheet.write(row, 2, bline.ref or '', regular) - sheet.write( - row, 3, bline.partner_id.display_name or '', regular) - sheet.write(row, 4, bline.amount, regular_currency) + bank_bal += bline['amount'] + sheet.write(row, 0, bline['date'], regular_date) + sheet.write(row, 1, bline['label'], regular) + sheet.write(row, 2, bline['ref'], regular) + sheet.write(row, 3, bline['partner'], regular) + sheet.write(row, 4, bline['amount'], regular_currency) sheet.write( - row, 5, bline.statement_id.display_name or '', - regular_currency) + row, 5, bline['statement_ref'], regular_currency) formula += '+SUM(E%d:E%d)' % (b_start_row + 1, b_end_row + 1) # 4) Theoric bank account balance at the bank @@ -222,7 +247,3 @@ class BankReconciliationXlsx(ReportXlsx): 0, 0, _( "No bank journal selected. " "This report is only for bank journals."), warn_msg) - - -BankReconciliationXlsx( - 'report.bank.reconciliation.xlsx', 'bank.reconciliation.report.wizard') diff --git a/account_bank_reconciliation_summary_xlsx/report/report.xml b/account_bank_reconciliation_summary_xlsx/report/report.xml index 8a855b44..0ad61e12 100644 --- a/account_bank_reconciliation_summary_xlsx/report/report.xml +++ b/account_bank_reconciliation_summary_xlsx/report/report.xml @@ -1,6 +1,7 @@ @@ -13,6 +14,8 @@ report_type="xlsx" name="bank.reconciliation.xlsx" file="bank.reconciliation.xlsx" + print_report_name="'bank_reconciliation-%s' % (object.date)" /> + diff --git a/account_bank_reconciliation_summary_xlsx/views/account_bank_statement.xml b/account_bank_reconciliation_summary_xlsx/views/account_bank_statement.xml index 63a36f61..6b0b087b 100644 --- a/account_bank_reconciliation_summary_xlsx/views/account_bank_statement.xml +++ b/account_bank_reconciliation_summary_xlsx/views/account_bank_statement.xml @@ -1,6 +1,7 @@ diff --git a/account_bank_reconciliation_summary_xlsx/views/account_journal.xml b/account_bank_reconciliation_summary_xlsx/views/account_journal.xml index 35c9d999..4f85740c 100644 --- a/account_bank_reconciliation_summary_xlsx/views/account_journal.xml +++ b/account_bank_reconciliation_summary_xlsx/views/account_journal.xml @@ -1,6 +1,7 @@ @@ -13,7 +14,7 @@ -
+
Report
diff --git a/account_bank_reconciliation_summary_xlsx/views/account_move_line.xml b/account_bank_reconciliation_summary_xlsx/views/account_move_line.xml index 7e03af6c..0bddde15 100644 --- a/account_bank_reconciliation_summary_xlsx/views/account_move_line.xml +++ b/account_bank_reconciliation_summary_xlsx/views/account_move_line.xml @@ -1,6 +1,7 @@ @@ -8,7 +9,7 @@ - bank_rec_summarry.account_move_line_form + bank_rec_summary.account_move_line_form account.move.line diff --git a/account_bank_reconciliation_summary_xlsx/wizard/__init__.py b/account_bank_reconciliation_summary_xlsx/wizard/__init__.py index 02696cfe..4ca3cb46 100644 --- a/account_bank_reconciliation_summary_xlsx/wizard/__init__.py +++ b/account_bank_reconciliation_summary_xlsx/wizard/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - from . import bank_reconciliation_report_wizard diff --git a/account_bank_reconciliation_summary_xlsx/wizard/bank_reconciliation_report_wizard.py b/account_bank_reconciliation_summary_xlsx/wizard/bank_reconciliation_report_wizard.py index 61040e2b..e93752be 100644 --- a/account_bank_reconciliation_summary_xlsx/wizard/bank_reconciliation_report_wizard.py +++ b/account_bank_reconciliation_summary_xlsx/wizard/bank_reconciliation_report_wizard.py @@ -1,5 +1,5 @@ -# -*- coding: utf-8 -*- -# © 2017 Akretion (Alexis de Lattre ) +# Copyright 2017-2019 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models @@ -24,18 +24,11 @@ class BankReconciliationReportWizard(models.TransientModel): journal_ids = fields.Many2many( 'account.journal', string='Bank Journals', domain=[('type', '=', 'bank')], required=True, - default=_default_journal_ids) + default=lambda self: self._default_journal_ids()) def open_xlsx(self): - action = { - 'type': 'ir.actions.report.xml', - 'report_name': 'bank.reconciliation.xlsx', - 'datas': { - 'model': self._name, - 'ids': self.ids, - 'journal_ids': self.journal_ids.ids, - 'date': self.date, - }, - 'context': self._context, - } + report = self.env.ref( + 'account_bank_reconciliation_summary_xlsx.' + 'bank_reconciliation_xlsx') + action = report.report_action(self) return action diff --git a/account_bank_reconciliation_summary_xlsx/wizard/bank_reconciliation_report_wizard_view.xml b/account_bank_reconciliation_summary_xlsx/wizard/bank_reconciliation_report_wizard_view.xml index 13227916..ebcd4db7 100644 --- a/account_bank_reconciliation_summary_xlsx/wizard/bank_reconciliation_report_wizard_view.xml +++ b/account_bank_reconciliation_summary_xlsx/wizard/bank_reconciliation_report_wizard_view.xml @@ -1,6 +1,7 @@ @@ -18,7 +19,7 @@
@@ -31,7 +32,11 @@ new
- +