[MIG] 12.0 account_bank_statement_import_adyen, account_bank_statement_clearing_account

This commit is contained in:
Martin Pishpecki
2020-05-13 17:05:05 +02:00
committed by Ronald Portier (Therp BV)
parent 80d28d4d57
commit 10d9639646
12 changed files with 111 additions and 40 deletions

View File

@@ -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 <https://pypi.org/project/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 <https://github.com/OCA/maintainer-tools>`_.

View File

@@ -0,0 +1,15 @@
# © 2017 Opener BV (<https://opener.amsterdam>)
# © 2020 Vanmoof BV (<https://www.vanmoof.com>)
# 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,
}

View File

@@ -1,14 +0,0 @@
# coding: utf-8
# © 2017 Opener BV (<https://opener.amsterdam>)
# 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,
}

View File

@@ -1,5 +1,7 @@
# coding: utf-8
from openerp import api, models
# © 2017 Opener BV (<https://opener.amsterdam>)
# © 2020 Vanmoof BV (<https://www.vanmoof.com>)
# 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()

View File

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

View File

@@ -0,0 +1,2 @@
* Stefan Rijnhart <stefan@opener.amsterdam> (https://opener.amsterdam)
* Martin Pishpecki <pishpecki@gmail.com> (https://www.vanmoof.com)

View File

@@ -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`