Browse Source

[MIG] account_bank_reconciliation_summary_xlsx from v10 to v12

pull/520/head
Alexis de Lattre 6 years ago
parent
commit
19dd67e86d
  1. 2
      account_bank_reconciliation_summary_xlsx/__init__.py
  2. 12
      account_bank_reconciliation_summary_xlsx/__manifest__.py
  3. 2
      account_bank_reconciliation_summary_xlsx/models/__init__.py
  4. 6
      account_bank_reconciliation_summary_xlsx/models/account_move_line.py
  5. 1
      account_bank_reconciliation_summary_xlsx/readme/CONFIGURE.rst
  6. 1
      account_bank_reconciliation_summary_xlsx/readme/CONTRIBUTORS.rst
  7. 8
      account_bank_reconciliation_summary_xlsx/readme/DESCRIPTION.rst
  8. 5
      account_bank_reconciliation_summary_xlsx/readme/USAGE.rst
  9. 2
      account_bank_reconciliation_summary_xlsx/report/__init__.py
  10. 155
      account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py
  11. 5
      account_bank_reconciliation_summary_xlsx/report/report.xml
  12. 3
      account_bank_reconciliation_summary_xlsx/views/account_bank_statement.xml
  13. 5
      account_bank_reconciliation_summary_xlsx/views/account_journal.xml
  14. 5
      account_bank_reconciliation_summary_xlsx/views/account_move_line.xml
  15. 2
      account_bank_reconciliation_summary_xlsx/wizard/__init__.py
  16. 21
      account_bank_reconciliation_summary_xlsx/wizard/bank_reconciliation_report_wizard.py
  17. 11
      account_bank_reconciliation_summary_xlsx/wizard/bank_reconciliation_report_wizard_view.xml

2
account_bank_reconciliation_summary_xlsx/__init__.py

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
from . import models
from . import report
from . import wizard

12
account_bank_reconciliation_summary_xlsx/__manifest__.py

@ -1,15 +1,15 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# Copyright 2017-2019 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# 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',

2
account_bank_reconciliation_summary_xlsx/models/__init__.py

@ -1,3 +1 @@
# -*- coding: utf-8 -*-
from . import account_move_line

6
account_bank_reconciliation_summary_xlsx/models/account_move_line.py

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# Copyright 2017-2019 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# 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)

1
account_bank_reconciliation_summary_xlsx/readme/CONFIGURE.rst

@ -0,0 +1 @@
This module doesn't require any configuration.

1
account_bank_reconciliation_summary_xlsx/readme/CONTRIBUTORS.rst

@ -0,0 +1 @@
* Alexis de Lattre <alexis.delattre@akretion.com>

8
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.

5
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*.

2
account_bank_reconciliation_summary_xlsx/report/__init__.py

@ -1,3 +1 @@
# -*- coding: utf-8 -*-
from . import bank_reconciliation_xlsx

155
account_bank_reconciliation_summary_xlsx/report/bank_reconciliation_xlsx.py

@ -1,14 +1,76 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion France (Alexis de Lattre <alexis.delattre@akretion.com>)
# Copyright 2017-2019 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# 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')

5
account_bank_reconciliation_summary_xlsx/report/report.xml

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
Copyright 2017-2019 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
@ -13,6 +14,8 @@
report_type="xlsx"
name="bank.reconciliation.xlsx"
file="bank.reconciliation.xlsx"
print_report_name="'bank_reconciliation-%s' % (object.date)"
/>
<!-- print_report_name doesn't work here... -->
</odoo>

3
account_bank_reconciliation_summary_xlsx/views/account_bank_statement.xml

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
Copyright 2017-2019 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->

5
account_bank_reconciliation_summary_xlsx/views/account_journal.xml

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2018 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
Copyright 2018-2019 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
@ -13,7 +14,7 @@
<field name="inherit_id" ref="account.account_journal_dashboard_kanban_view"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='bank_cash_commands']/.." position="after">
<div class="col-xs-4 o_kanban_card_manage_section o_kanban_manage_new">
<div class="col-4 o_kanban_card_manage_section o_kanban_manage_new">
<div class="o_kanban_card_manage_title">
<span>Report</span>
</div>

5
account_bank_reconciliation_summary_xlsx/views/account_move_line.xml

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
Copyright 2017-2019 Akretion France (http://www.akretion.com/)
Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
@ -8,7 +9,7 @@
<record id="view_move_line_form" model="ir.ui.view">
<field name="name">bank_rec_summarry.account_move_line_form</field>
<field name="name">bank_rec_summary.account_move_line_form</field>
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account.view_move_line_form"/>
<field name="arch" type="xml">

2
account_bank_reconciliation_summary_xlsx/wizard/__init__.py

@ -1,3 +1 @@
# -*- coding: utf-8 -*-
from . import bank_reconciliation_report_wizard

21
account_bank_reconciliation_summary_xlsx/wizard/bank_reconciliation_report_wizard.py

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# Copyright 2017-2019 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# 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

11
account_bank_reconciliation_summary_xlsx/wizard/bank_reconciliation_report_wizard_view.xml

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
Copyright 2017-2019 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
@ -18,7 +19,7 @@
</group>
<footer>
<button name="open_xlsx" string="Export XLSX" type="object" class="btn-primary"/>
<button special="cancel" string="Cancel" class="oe_link"/>
<button special="cancel" string="Cancel"/>
</footer>
</form>
</field>
@ -31,7 +32,11 @@
<field name="target">new</field>
</record>
<menuitem id="bank_reconciliation_report_wizard_menu" action="bank_reconciliation_report_wizard_action" parent="account_financial_report_qweb.menu_oca_reports" groups="account.group_account_manager,account.group_account_user" sequence="100"/>
<menuitem id="bank_reconciliation_report_wizard_menu"
action="bank_reconciliation_report_wizard_action"
parent="account_financial_report.menu_oca_reports"
groups="account.group_account_manager,account.group_account_user"
sequence="100"/>
</odoo>
Loading…
Cancel
Save