Browse Source

[MIG] Migrate account_bank_statement_import_auto_reconcile

pull/204/head
George Daramouskas 5 years ago
committed by Holger Brunn
parent
commit
f87c5fc275
No known key found for this signature in database GPG Key ID: 1C9760FECA3AE18
  1. 1
      account_bank_statement_import_auto_reconcile/README.rst
  2. 3
      account_bank_statement_import_auto_reconcile/__init__.py
  3. 7
      account_bank_statement_import_auto_reconcile/__manifest__.py
  4. 26
      account_bank_statement_import_auto_reconcile/demo/account_bank_statement_import_auto_reconcile_rule.xml
  5. 3
      account_bank_statement_import_auto_reconcile/models/__init__.py
  6. 69
      account_bank_statement_import_auto_reconcile/models/account_bank_statement_import.py
  7. 38
      account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile.py
  8. 11
      account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile_exact_amount.py
  9. 14
      account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile_odoo.py
  10. 8
      account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile_rule.py
  11. 8
      account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_reapply_rules.py
  12. 6
      account_bank_statement_import_auto_reconcile/models/account_journal.py
  13. 3
      account_bank_statement_import_auto_reconcile/tests/__init__.py
  14. 25
      account_bank_statement_import_auto_reconcile/tests/test_account_bank_statement_import_auto_reconcile.py
  15. 22
      account_bank_statement_import_auto_reconcile/views/account_bank_statement.xml
  16. 24
      account_bank_statement_import_auto_reconcile/views/account_bank_statement_import.xml
  17. 48
      account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_auto_reconcile_exact_amount.xml
  18. 44
      account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_auto_reconcile_rule.xml
  19. 39
      account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_reapply_rules.xml
  20. 22
      account_bank_statement_import_auto_reconcile/views/account_journal.xml

1
account_bank_statement_import_auto_reconcile/README.rst

@ -69,6 +69,7 @@ Contributors
------------
* Holger Brunn <hbrunn@therp.nl>
* George Daramouskas <gdaramouskas@therp.nl>
Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:community@mail.odoo.com>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues.

3
account_bank_statement_import_auto_reconcile/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models

7
account_bank_statement_import_auto_reconcile/__openerp__.py → account_bank_statement_import_auto_reconcile/__manifest__.py

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# Copyright 2017 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Automatic reconciliation after import",
"version": "8.0.1.0.0",
"version": "10.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": 'Banking addons',
@ -11,7 +11,6 @@
"reconciliation rules to be run after a bank statement is imported",
"depends": [
'account_bank_statement_import',
'web_widget_one2many_tags',
'base_domain_operator',
],
"demo": [

26
account_bank_statement_import_auto_reconcile/demo/account_bank_statement_import_auto_reconcile_rule.xml

@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="rule_amount_exact" model="account.bank.statement.import.auto.reconcile.rule">
<field name="journal_id" ref="account.bank_journal" />
<field name="rule_type">account.bank.statement.import.auto.reconcile.exact.amount</field>
<field name="match_st_name" eval="True" />
<field name="match_st_ref" eval="True" />
<field name="match_move_name" eval="True" />
<field name="match_move_ref" eval="True" />
<field name="match_line_name" eval="True" />
<field name="match_line_ref" eval="True" />
</record>
</data>
</openerp>
<odoo>
<record id="rule_amount_exact" model="account.bank.statement.import.auto.reconcile.rule">
<field name="journal_id" ref="account.bank_journal" />
<field name="rule_type">account.bank.statement.import.auto.reconcile.exact.amount</field>
<field name="match_st_name" eval="True" />
<field name="match_st_ref" eval="True" />
<field name="match_move_name" eval="True" />
<field name="match_move_ref" eval="True" />
<field name="match_line_name" eval="True" />
<field name="match_line_ref" eval="True" />
</record>
</odoo>

3
account_bank_statement_import_auto_reconcile/models/__init__.py

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import account_bank_statement_import_auto_reconcile
from . import account_bank_statement_import_auto_reconcile_rule
from . import account_journal

69
account_bank_statement_import_auto_reconcile/models/account_bank_statement_import.py

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import _, api, fields, models
# Copyright 2017 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
# pylint: disable=R7980
@ -11,37 +11,34 @@ class AccountBankStatementImport(models.TransientModel):
auto_reconcile = fields.Boolean('Auto reconcile', default=True)
@api.model
def _create_bank_statement(self, stmt_vals):
statement_id, notifications = super(
def _create_bank_statements(self, stmt_vals):
statement_ids, notifications = super(
AccountBankStatementImport, self
)._create_bank_statement(stmt_vals)
if not statement_id:
return statement_id, notifications
statement = self.env['account.bank.statement'].browse(statement_id)
if (
not statement.journal_id
.statement_import_auto_reconcile_rule_ids or
not self.auto_reconcile
):
return statement_id, notifications
reconcile_rules = statement.journal_id\
.statement_import_auto_reconcile_rule_ids.get_rules()
auto_reconciled_ids = []
for line in statement.line_ids:
for rule in reconcile_rules:
if rule.reconcile(line):
auto_reconciled_ids.append(line.id)
break
if auto_reconciled_ids:
notifications.append({
'type': 'warning',
'message':
_("%d transactions were reconciled automatically.") %
len(auto_reconciled_ids),
'details': {
'name': _('Automatically reconciled'),
'model': 'account.bank.statement.line',
'ids': auto_reconciled_ids,
},
})
return statement_id, notifications
)._create_bank_statements(stmt_vals)
if not statement_ids or not self.auto_reconcile:
return statement_ids, notifications
statements = self.env['account.bank.statement'].browse(statement_ids)
for statement in statements.filtered(
lambda x: x.journal_id.
statement_import_auto_reconcile_rule_ids):
reconcile_rules = statement.journal_id\
.statement_import_auto_reconcile_rule_ids.get_rules()
auto_reconciled_ids = []
for line in statement.line_ids:
for rule in reconcile_rules:
if rule.reconcile(line):
auto_reconciled_ids.append(line.id)
break
if auto_reconciled_ids:
notifications.append({
'type': 'warning',
'message':
_("%d transactions were reconciled automatically.") %
len(auto_reconciled_ids),
'details': {
'name': _('Automatically reconciled'),
'model': 'account.bank.statement.line',
'ids': auto_reconciled_ids,
},
})
return statement_ids, notifications

38
account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile.py

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tools import float_compare, float_round
from openerp import api, fields, models
# Copyright 2017 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.tools import float_compare, float_round
from odoo import api, fields, models
class AccountBankStatementImportAutoReconcile(models.AbstractModel):
@ -46,24 +46,22 @@ class AccountBankStatementImportAutoReconcile(models.AbstractModel):
@api.model
def _reconcile_move_line(self, statement_line, move_line_id):
"""Helper to reconcile some move line with a bank statement.
This will create a move to reconcile with and assigns journal_entry_id
""" Given a bank statement line and an account move line (Journal Item)
which we know that can be reconciled, reconcile them.
:param statement_line: The account.bank.statement.line to reconcile.
:param move_line_id: The id of the account.move.line to reconcile.
"""
move = self.env['account.move'].create(
self.env['account.bank.statement']._prepare_move(
statement_line,
(
statement_line.statement_id.name or statement_line.name
) + "/" + str(statement_line.sequence or '')
)
acc_move_line = self.env['account.move.line']
acc_move = self.env['account.move']
move = acc_move.create(statement_line._prepare_reconciliation_move(
statement_line.ref))
move_line_dict = statement_line._prepare_reconciliation_move_line(
move,
-acc_move_line.browse(move_line_id).balance,
)
move_line_dict = self.env['account.bank.statement']\
._prepare_bank_move_line(
statement_line, move.id, -statement_line.amount,
statement_line.statement_id.company_id.currency_id.id,
)
move_line_dict['counterpart_move_line_id'] = move_line_id
statement_line.process_reconciliation([move_line_dict])
move_line = acc_move_line.with_context(
check_move_validity=False).create(move_line_dict)
@api.multi
def reconcile(self, statement_line):

11
account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile_exact_amount.py

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import api, fields, models
# Copyright 2017 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
# pylint: disable=R7980
@ -34,7 +34,7 @@ class AccountBankStatementImportAutoReconcileExactAmount(models.AbstractModel):
amount_field = 'debit'
sign = 1
if statement_line.currency_id or statement_line.journal_id.currency:
if statement_line.currency_id or statement_line.journal_id.currency_id:
amount_field = 'amount_currency'
elif statement_line.amount < 0:
amount_field = 'credit'
@ -53,8 +53,7 @@ class AccountBankStatementImportAutoReconcileExactAmount(models.AbstractModel):
])
domain = [
('reconcile_id', '=', False),
('state', '=', 'valid'),
('reconciled', '=', False),
('account_id.reconcile', '=', True),
('partner_id', '=', statement_line.partner_id.id),
(amount_field, '=', self._round(sign * statement_line.amount)),

14
account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile_odoo.py

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import api, models
# Copyright 2017 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, models
class AccountBankStatementImportAutoReconcileOdoo(models.AbstractModel):
@ -11,8 +11,12 @@ class AccountBankStatementImportAutoReconcileOdoo(models.AbstractModel):
@api.multi
def reconcile(self, statement_line):
"""Find an open invoice for the statement line's partner"""
matches = statement_line.get_reconciliation_proposition(statement_line)
""" Reconcile the given statement line with the appropriate
account move line.
:param statement_line: The account.bank.statement.line to reconcile.
"""
matches = statement_line.get_reconciliation_proposition()
if len(matches) == 1 and self._matches_amount(
statement_line, matches[0]['debit'], -matches[0]['credit'],
):

8
account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile_rule.py

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# Copyright 2017 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from lxml import etree
from openerp import _, api, exceptions, fields, models, tools
from odoo import _, api, exceptions, fields, models, tools
from .account_bank_statement_import_auto_reconcile import\
AccountBankStatementImportAutoReconcile as auto_reconcile_base
@ -87,6 +87,8 @@ class AccountBankStatementImportAutoReconcileRule(models.Model):
result = super(AccountBankStatementImportAutoReconcileRule, self)\
.fields_view_get(view_id=view_id, view_type=view_type,
toolbar=toolbar, submenu=submenu)
if view_type != 'form':
return result
standard_fields = set(self.env[auto_reconcile_base._name]._fields)
arch = etree.fromstring(result['arch'])
container = arch.xpath('//div[@name="rule_options"]')[0]

8
account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_reapply_rules.py

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import _, api, fields, models
from openerp.exceptions import Warning as UserError
# Copyright 2017 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import Warning as UserError
class AccountBankStatementImportReapplyRules(models.TransientModel):

6
account_bank_statement_import_auto_reconcile/models/account_journal.py

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import fields, models
# Copyright 2017 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class AccountJournal(models.Model):

3
account_bank_statement_import_auto_reconcile/tests/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import test_account_bank_statement_import_auto_reconcile

25
account_bank_statement_import_auto_reconcile/tests/test_account_bank_statement_import_auto_reconcile.py

@ -1,22 +1,35 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# Copyright 2017 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import base64
from datetime import timedelta
from openerp import fields
from openerp.tests.common import TransactionCase
from openerp.addons.account_bank_statement_import.models\
from odoo import fields
from odoo.tests.common import TransactionCase
from odoo.addons.account_bank_statement_import\
.account_bank_statement_import import AccountBankStatementImport
class TestAccountBankStatementImportAutoReconcile(TransactionCase):
post_install = True
at_install = False
def setUp(self):
super(TestAccountBankStatementImportAutoReconcile, self).setUp()
# we don't really have something to import, so we patch the
# import routine to return what we want for our tests
self.original_parse_file = AccountBankStatementImport._parse_file
AccountBankStatementImport._parse_file = self._parse_file
self.invoice = self.env.ref('account.invoice_4')
invoice_account = self.env['account.account'].search([
('user_type_id', '=', self.env.ref(
'account.data_account_type_receivable').id)],
limit=1,
)
self.invoice = self.env['account.invoice'].create({
'partner_id': self.env.ref('base.res_partner_2').id,
'account_id': invoice_account.id,
'type': 'in_invoice',
})
self.rule = self.env.ref(
'account_bank_statement_import_auto_reconcile.rule_amount_exact'
)

22
account_bank_statement_import_auto_reconcile/views/account_bank_statement.xml

@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<act_window
id="action_reapply_rules"
src_model="account.bank.statement"
res_model="account.bank.statement.import.reapply.rules"
name="Reapply matching rules"
target="new"
view_id="account_bank_statement_import_reapply_rules_form"
/>
</data>
</openerp>
<odoo>
<act_window
id="action_reapply_rules"
src_model="account.bank.statement"
res_model="account.bank.statement.import.reapply.rules"
name="Reapply matching rules"
target="new"
view_id="account_bank_statement_import_reapply_rules_form"
/>
</odoo>

24
account_bank_statement_import_auto_reconcile/views/account_bank_statement_import.xml

@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="account_bank_statement_import_view" model="ir.ui.view">
<field name="model">account.bank.statement.import</field>
<field name="inherit_id" ref="account_bank_statement_import.account_bank_statement_import_view" />
<field name="arch" type="xml">
<field name="journal_id" position="after">
<field name="auto_reconcile" attrs="{'invisible': [('hide_journal_field', '=', True)]}" class="oe_inline" />
<label for="auto_reconcile" />
</field>
<odoo>
<record id="account_bank_statement_import_view" model="ir.ui.view">
<field name="model">account.bank.statement.import</field>
<field name="inherit_id" ref="account_bank_statement_import.account_bank_statement_import_view" />
<field name="arch" type="xml">
<field name="data_file" position="after">
<field name="auto_reconcile" class="oe_inline" />
<label for="auto_reconcile" />
</field>
</record>
</data>
</openerp>
</field>
</record>
</odoo>

48
account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_auto_reconcile_exact_amount.xml

@ -1,26 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="account_bank_statement_import_auto_reconcile_exact_amount_form" model="ir.ui.view">
<field name="model">account.bank.statement.import.auto.reconcile.exact.amount</field>
<field name="arch" type="xml">
<form>
<group name="statement_fields" string="On the statement, match...">
<field name="match_st_ref" />
<field name="match_st_name" />
</group>
<group name="move_line_fields" string="... with the following fields">
<field name="match_move_ref" />
<field name="match_move_name" />
<field name="match_line_ref" />
<field name="match_line_name" />
</group>
<group name="options" string="Options">
<field name="substring_match" />
<field name="case_sensitive" />
</group>
</form>
</field>
</record>
</data>
</openerp>
<odoo>
<record id="account_bank_statement_import_auto_reconcile_exact_amount_form" model="ir.ui.view">
<field name="model">account.bank.statement.import.auto.reconcile.exact.amount</field>
<field name="arch" type="xml">
<form>
<group name="statement_fields" string="On the statement, match...">
<field name="match_st_ref" />
<field name="match_st_name" />
</group>
<group name="move_line_fields" string="... with the following fields">
<field name="match_move_ref" />
<field name="match_move_name" />
<field name="match_line_ref" />
<field name="match_line_name" />
</group>
<group name="options" string="Options">
<field name="substring_match" />
<field name="case_sensitive" />
</group>
</form>
</field>
</record>
</odoo>

44
account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_auto_reconcile_rule.xml

@ -1,24 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="account_bank_statement_import_auto_reconcile_rule_form" model="ir.ui.view">
<field name="model">account.bank.statement.import.auto.reconcile.rule</field>
<field name="arch" type="xml">
<form>
<group>
<field name="rule_type" />
</group>
<div name="rule_options" attrs="{'invisible': [('rule_type', '=', False)]}" />
</form>
</field>
</record>
<record id="account_bank_statement_import_auto_reconcile_rule_tree" model="ir.ui.view">
<field name="model">account.bank.statement.import.auto.reconcile.rule</field>
<field name="arch" type="xml">
<tree>
<field name="display_name" />
</tree>
</field>
</record>
</data>
</openerp>
<odoo>
<record id="account_bank_statement_import_auto_reconcile_rule_form" model="ir.ui.view">
<field name="model">account.bank.statement.import.auto.reconcile.rule</field>
<field name="arch" type="xml">
<form>
<group>
<field name="rule_type" />
</group>
<div name="rule_options" attrs="{'invisible': [('rule_type', '=', False)]}" />
</form>
</field>
</record>
<record id="account_bank_statement_import_auto_reconcile_rule_tree" model="ir.ui.view">
<field name="model">account.bank.statement.import.auto.reconcile.rule</field>
<field name="arch" type="xml">
<tree>
<field name="display_name" />
</tree>
</field>
</record>
</odoo>

39
account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_reapply_rules.xml

@ -1,18 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="account_bank_statement_import_reapply_rules_form" model="ir.ui.view">
<field name="model">account.bank.statement.import.reapply.rules</field>
<field name="arch" type="xml">
<form>
<div>This wizard will reapply the journal's matching rules on the selected bank statement(s)</div>
<footer>
<button name="action_reapply_rules" string="Reapply rules" type="object" class="oe_highlight" />
or
<button special="cancel" string="Cancel" class="oe_link" />
</footer>
</form>
</field>
</record>
</data>
</openerp>
<odoo>
<record id="account_bank_statement_import_reapply_rules_form" model="ir.ui.view">
<field name="model">account.bank.statement.import.reapply.rules</field>
<field name="arch" type="xml">
<form>
<div>
This wizard will reapply the journal's matching
rules on the selected bank statement(s)
</div>
<footer>
<button
name="action_reapply_rules"
string="Reapply rules"
type="object"
class="oe_highlight" />
or
<button special="cancel" string="Cancel" class="oe_link" />
</footer>
</form>
</field>
</record>
</odoo>

22
account_bank_statement_import_auto_reconcile/views/account_journal.xml

@ -1,14 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="view_account_journal_form" model="ir.ui.view">
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_journal_form" />
<field name="arch" type="xml">
<field name="default_credit_account_id" position="after">
<field name="statement_import_auto_reconcile_rule_ids" widget="one2many_tags" />
</field>
<odoo>
<record id="view_account_journal_form" model="ir.ui.view">
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_journal_form" />
<field name="arch" type="xml">
<field name="default_credit_account_id" position="after">
<field name="statement_import_auto_reconcile_rule_ids"/>
</field>
</record>
</data>
</openerp>
</field>
</record>
</odoo>
Loading…
Cancel
Save