From 10d963964643c91d502d5e8011e16b9b2719b7dd Mon Sep 17 00:00:00 2001 From: Martin Pishpecki Date: Wed, 13 May 2020 17:05:05 +0200 Subject: [PATCH] [MIG] 12.0 account_bank_statement_import_adyen, account_bank_statement_clearing_account --- .../README.rst | 35 +++++++++++ .../__manifest__.py | 15 +++++ .../__openerp__.py | 14 ----- .../models/account_bank_statement.py | 61 +++++++++++-------- .../readme/CONFIGURE.rst | 4 ++ .../readme/CONTRIBUTORS.rst | 2 + .../readme/CREDITS.rst | 0 .../readme/DESCRIPTION.rst | 20 ++++++ .../readme/HISTORY.rst | 0 .../readme/INSTALL.rst | 0 .../readme/ROADMAP.rst | 0 .../readme/USAGE.rst | 0 12 files changed, 111 insertions(+), 40 deletions(-) create mode 100644 account_bank_statement_clearing_account/README.rst create mode 100644 account_bank_statement_clearing_account/__manifest__.py delete mode 100644 account_bank_statement_clearing_account/__openerp__.py create mode 100644 account_bank_statement_clearing_account/readme/CONFIGURE.rst create mode 100644 account_bank_statement_clearing_account/readme/CONTRIBUTORS.rst create mode 100644 account_bank_statement_clearing_account/readme/CREDITS.rst create mode 100644 account_bank_statement_clearing_account/readme/DESCRIPTION.rst create mode 100644 account_bank_statement_clearing_account/readme/HISTORY.rst create mode 100644 account_bank_statement_clearing_account/readme/INSTALL.rst create mode 100644 account_bank_statement_clearing_account/readme/ROADMAP.rst create mode 100644 account_bank_statement_clearing_account/readme/USAGE.rst diff --git a/account_bank_statement_clearing_account/README.rst b/account_bank_statement_clearing_account/README.rst new file mode 100644 index 00000000..38929e87 --- /dev/null +++ b/account_bank_statement_clearing_account/README.rst @@ -0,0 +1,35 @@ +**This file is going to be generated by oca-gen-addon-readme.** + +*Manual changes will be overwritten.* + +Please provide content in the ``readme`` directory: + +* **DESCRIPTION.rst** (required) +* INSTALL.rst (optional) +* CONFIGURE.rst (optional) +* **USAGE.rst** (optional, highly recommended) +* DEVELOP.rst (optional) +* ROADMAP.rst (optional) +* HISTORY.rst (optional, recommended) +* **CONTRIBUTORS.rst** (optional, highly recommended) +* CREDITS.rst (optional) + +Content of this README will also be drawn from the addon manifest, +from keys such as name, authors, maintainers, development_status, +and license. + +A good, one sentence summary in the manifest is also highly recommended. + + +Automatic changelog generation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`HISTORY.rst` can be auto generated using `towncrier `_. + +Just put towncrier compatible changelog fragments into `readme/newsfragments` +and the changelog file will be automatically generated and updated when a new fragment is added. + +Please refer to `towncrier` documentation to know more. + +NOTE: the changelog will be automatically generated when using `/ocabot merge $option`. +If you need to run it manually, refer to `OCA/maintainer-tools README `_. diff --git a/account_bank_statement_clearing_account/__manifest__.py b/account_bank_statement_clearing_account/__manifest__.py new file mode 100644 index 00000000..04d914fc --- /dev/null +++ b/account_bank_statement_clearing_account/__manifest__.py @@ -0,0 +1,15 @@ +# © 2017 Opener BV () +# © 2020 Vanmoof BV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Reconcile entries from pseudo bank statements", + "version": "12.0.1.0.0", + "author": "Opener B.V., Vanmoof BV, Odoo Community Association (OCA)", + "category": "Banking addons", + "website": "https://opener.am", + "license": "AGPL-3", + "depends": [ + "account_cancel", + ], + "installable": True, +} diff --git a/account_bank_statement_clearing_account/__openerp__.py b/account_bank_statement_clearing_account/__openerp__.py deleted file mode 100644 index f69fe697..00000000 --- a/account_bank_statement_clearing_account/__openerp__.py +++ /dev/null @@ -1,14 +0,0 @@ -# coding: utf-8 -# © 2017 Opener BV () -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -{ - 'name': 'Reconcile entries from pseudo bank statements', - 'version': '8.0.1.0.0', - 'author': 'Opener B.V.', - 'category': 'Banking addons', - 'website': 'https://opener.am', - 'depends': [ - 'account_cancel', - ], - 'installable': True, -} diff --git a/account_bank_statement_clearing_account/models/account_bank_statement.py b/account_bank_statement_clearing_account/models/account_bank_statement.py index 06ee1e16..eb30d373 100644 --- a/account_bank_statement_clearing_account/models/account_bank_statement.py +++ b/account_bank_statement_clearing_account/models/account_bank_statement.py @@ -1,5 +1,7 @@ -# coding: utf-8 -from openerp import api, models +# © 2017 Opener BV () +# © 2020 Vanmoof BV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import api, models class BankStatement(models.Model): @@ -7,25 +9,26 @@ class BankStatement(models.Model): @api.multi def get_reconcile_clearing_account_lines(self): + """ If this statement qualifies for clearing account reconciliation, + return the relevant lines to (un)reconcile. This is the case if the + default journal account is reconcilable, each statement line has a + counterpart line on this account for the full amount and the sum of + the counterpart lines is zero. + """ + self.ensure_one() if (self.journal_id.default_debit_account_id != self.journal_id.default_credit_account_id or not self.journal_id.default_debit_account_id.reconcile): return False account = self.journal_id.default_debit_account_id - currency = self.journal_id.currency or self.company_id.currency_id + currency = self.journal_id.currency_id or self.company_id.currency_id def get_bank_line(st_line): - for line in st_line.journal_entry_id.line_id: - if st_line.amount > 0: - compare_amount = st_line.amount - field = 'debit' - else: - compare_amount = -st_line.amount - field = 'credit' - if (line[field] and - not currency.compare_amounts( - line[field], compare_amount) and - line.account_id == account): + for line in st_line.journal_entry_ids: + field = 'debit' if st_line.amount > 0 else 'credit' + if (line.account_id == account and + not currency.compare_amounts( + line[field], abs(st_line.amount))): return line return False @@ -42,31 +45,35 @@ class BankStatement(models.Model): @api.multi def reconcile_clearing_account(self): + """ If applicable, reconcile the clearing account lines in case + all lines are still unreconciled. """ self.ensure_one() lines = self.get_reconcile_clearing_account_lines() - if not lines: + if not lines or any( + li.matched_debit_ids or li.matched_credit_ids + for li in lines): return False - if any(line.reconcile_id or line.reconcile_partial_id - for line in lines): - return False - lines.reconcile_partial() + lines.reconcile() + return True @api.multi def unreconcile_clearing_account(self): + """ If applicable, unreconcile the clearing account lines + if still fully reconciled with each other. """ self.ensure_one() lines = self.get_reconcile_clearing_account_lines() if not lines: return False - reconciliation = lines[0].reconcile_id - if reconciliation and all( - line.reconcile_id == reconciliation - for line in lines) and all( - line in lines - for line in reconciliation.line_id): - reconciliation.unlink() + reconciliation = lines[0].full_reconcile_id + if reconciliation and lines == reconciliation.reconciled_line_ids: + lines.remove_move_reconcile() + return True + return False @api.multi def button_draft(self): + """ When setting the statement back to draft, unreconcile the + reconciliation on the clearing account """ res = super(BankStatement, self).button_draft() for statement in self: statement.unreconcile_clearing_account() @@ -74,6 +81,8 @@ class BankStatement(models.Model): @api.multi def button_confirm_bank(self): + """ When confirming the statement, trigger the reconciliation of + the lines on the clearing account (if applicable) """ res = super(BankStatement, self).button_confirm_bank() for statement in self: statement.reconcile_clearing_account() diff --git a/account_bank_statement_clearing_account/readme/CONFIGURE.rst b/account_bank_statement_clearing_account/readme/CONFIGURE.rst new file mode 100644 index 00000000..b29c2ce6 --- /dev/null +++ b/account_bank_statement_clearing_account/readme/CONFIGURE.rst @@ -0,0 +1,4 @@ +In order to enable the reconcilation of the counterparts of zero-balance +statement files from payment providers, you need to make sure that the journal +that is used for these statements have the same default debit account as their +default credit account, and this account is configured for reconciliation. diff --git a/account_bank_statement_clearing_account/readme/CONTRIBUTORS.rst b/account_bank_statement_clearing_account/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..58e9f494 --- /dev/null +++ b/account_bank_statement_clearing_account/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Stefan Rijnhart (https://opener.amsterdam) +* Martin Pishpecki (https://www.vanmoof.com) diff --git a/account_bank_statement_clearing_account/readme/CREDITS.rst b/account_bank_statement_clearing_account/readme/CREDITS.rst new file mode 100644 index 00000000..e69de29b diff --git a/account_bank_statement_clearing_account/readme/DESCRIPTION.rst b/account_bank_statement_clearing_account/readme/DESCRIPTION.rst new file mode 100644 index 00000000..7043715f --- /dev/null +++ b/account_bank_statement_clearing_account/readme/DESCRIPTION.rst @@ -0,0 +1,20 @@ +This is a technical modules that you can use to improve the processing of +statement files from payment providers. These statements usually consist +of lines that to be reconciled by customer debts, offset by lines that are +to be reconciled by the imbursements from the payment provider, corrected +for customer credits and the costs of the payment provider. Typically, the +balance of such a statement is zero. Effectively, the counterpart of each +statement line is made on a clearing account and you should keep track of +the balance of the clearing account to see if the payment provider still owes +you money. You can keep track of the account by reconciling each entry on it. + +That is where this module comes in. When importing such a statement, this +module reconciles all the counterparts on the clearing account with one +another. Reconciliation is executed when validating the statement. When +reopening the statement, the reconcilation is undone. + +Known issues +============ +This module does not come with its own tests because it depends on a +statement filter being installed. Instead, it is tested in +`account_bank_statement_import_adyen` diff --git a/account_bank_statement_clearing_account/readme/HISTORY.rst b/account_bank_statement_clearing_account/readme/HISTORY.rst new file mode 100644 index 00000000..e69de29b diff --git a/account_bank_statement_clearing_account/readme/INSTALL.rst b/account_bank_statement_clearing_account/readme/INSTALL.rst new file mode 100644 index 00000000..e69de29b diff --git a/account_bank_statement_clearing_account/readme/ROADMAP.rst b/account_bank_statement_clearing_account/readme/ROADMAP.rst new file mode 100644 index 00000000..e69de29b diff --git a/account_bank_statement_clearing_account/readme/USAGE.rst b/account_bank_statement_clearing_account/readme/USAGE.rst new file mode 100644 index 00000000..e69de29b