From f87c5fc275e03471af2562893a66224ef2c479d8 Mon Sep 17 00:00:00 2001 From: George Daramouskas Date: Thu, 28 Feb 2019 13:24:06 +0100 Subject: [PATCH] [MIG] Migrate account_bank_statement_import_auto_reconcile --- .../README.rst | 1 + .../__init__.py | 3 +- .../{__openerp__.py => __manifest__.py} | 7 +- ...k_statement_import_auto_reconcile_rule.xml | 26 ++++--- .../models/__init__.py | 3 +- .../models/account_bank_statement_import.py | 69 +++++++++---------- ...nt_bank_statement_import_auto_reconcile.py | 38 +++++----- ...ment_import_auto_reconcile_exact_amount.py | 11 ++- ...nk_statement_import_auto_reconcile_odoo.py | 14 ++-- ...nk_statement_import_auto_reconcile_rule.py | 8 ++- ...unt_bank_statement_import_reapply_rules.py | 8 +-- .../models/account_journal.py | 6 +- .../tests/__init__.py | 3 +- ...nt_bank_statement_import_auto_reconcile.py | 25 +++++-- .../views/account_bank_statement.xml | 22 +++--- .../views/account_bank_statement_import.xml | 24 +++---- ...ent_import_auto_reconcile_exact_amount.xml | 48 +++++++------ ...k_statement_import_auto_reconcile_rule.xml | 44 ++++++------ ...nt_bank_statement_import_reapply_rules.xml | 39 ++++++----- .../views/account_journal.xml | 22 +++--- 20 files changed, 212 insertions(+), 209 deletions(-) rename account_bank_statement_import_auto_reconcile/{__openerp__.py => __manifest__.py} (84%) diff --git a/account_bank_statement_import_auto_reconcile/README.rst b/account_bank_statement_import_auto_reconcile/README.rst index 95870a0..4457412 100644 --- a/account_bank_statement_import_auto_reconcile/README.rst +++ b/account_bank_statement_import_auto_reconcile/README.rst @@ -69,6 +69,7 @@ Contributors ------------ * Holger Brunn +* George Daramouskas Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list `_ or the `appropriate specialized mailinglist `_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues. diff --git a/account_bank_statement_import_auto_reconcile/__init__.py b/account_bank_statement_import_auto_reconcile/__init__.py index 86cb334..9732283 100644 --- a/account_bank_statement_import_auto_reconcile/__init__.py +++ b/account_bank_statement_import_auto_reconcile/__init__.py @@ -1,4 +1,3 @@ # -*- coding: utf-8 -*- -# © 2017 Therp BV -# 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 diff --git a/account_bank_statement_import_auto_reconcile/__openerp__.py b/account_bank_statement_import_auto_reconcile/__manifest__.py similarity index 84% rename from account_bank_statement_import_auto_reconcile/__openerp__.py rename to account_bank_statement_import_auto_reconcile/__manifest__.py index 8e908b2..7d8a7bf 100644 --- a/account_bank_statement_import_auto_reconcile/__openerp__.py +++ b/account_bank_statement_import_auto_reconcile/__manifest__.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- -# © 2017 Therp BV -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# Copyright 2017 Therp BV +# 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": [ diff --git a/account_bank_statement_import_auto_reconcile/demo/account_bank_statement_import_auto_reconcile_rule.xml b/account_bank_statement_import_auto_reconcile/demo/account_bank_statement_import_auto_reconcile_rule.xml index a0ff38e..46c7976 100644 --- a/account_bank_statement_import_auto_reconcile/demo/account_bank_statement_import_auto_reconcile_rule.xml +++ b/account_bank_statement_import_auto_reconcile/demo/account_bank_statement_import_auto_reconcile_rule.xml @@ -1,15 +1,13 @@ - - - - - account.bank.statement.import.auto.reconcile.exact.amount - - - - - - - - - + + + + account.bank.statement.import.auto.reconcile.exact.amount + + + + + + + + diff --git a/account_bank_statement_import_auto_reconcile/models/__init__.py b/account_bank_statement_import_auto_reconcile/models/__init__.py index 233ac10..d79466b 100644 --- a/account_bank_statement_import_auto_reconcile/models/__init__.py +++ b/account_bank_statement_import_auto_reconcile/models/__init__.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -# © 2017 Therp BV -# 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 diff --git a/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import.py b/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import.py index 928c544..eb63cb1 100644 --- a/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import.py +++ b/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -# © 2017 Therp BV -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import _, api, fields, models +# Copyright 2017 Therp BV +# 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 diff --git a/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile.py b/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile.py index f549f80..e4a536d 100644 --- a/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile.py +++ b/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -# © 2017 Therp BV -# 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 +# 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): diff --git a/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile_exact_amount.py b/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile_exact_amount.py index 2458531..ec56376 100644 --- a/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile_exact_amount.py +++ b/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 -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import api, fields, models +# Copyright 2017 Therp BV +# 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)), diff --git a/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile_odoo.py b/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile_odoo.py index 760a829..e642880 100644 --- a/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile_odoo.py +++ b/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 -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import api, models +# Copyright 2017 Therp BV +# 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'], ): diff --git a/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile_rule.py b/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile_rule.py index b37aa19..7ff3ebf 100644 --- a/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_auto_reconcile_rule.py +++ b/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 -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# Copyright 2017 Therp BV +# 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] diff --git a/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_reapply_rules.py b/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_reapply_rules.py index e620fac..fc410f6 100644 --- a/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_reapply_rules.py +++ b/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_reapply_rules.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -# © 2017 Therp BV -# 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 +# 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): diff --git a/account_bank_statement_import_auto_reconcile/models/account_journal.py b/account_bank_statement_import_auto_reconcile/models/account_journal.py index 7b2b921..51c9c7a 100644 --- a/account_bank_statement_import_auto_reconcile/models/account_journal.py +++ b/account_bank_statement_import_auto_reconcile/models/account_journal.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -# © 2017 Therp BV -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import fields, models +# Copyright 2017 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import fields, models class AccountJournal(models.Model): diff --git a/account_bank_statement_import_auto_reconcile/tests/__init__.py b/account_bank_statement_import_auto_reconcile/tests/__init__.py index 785c8f5..773226b 100644 --- a/account_bank_statement_import_auto_reconcile/tests/__init__.py +++ b/account_bank_statement_import_auto_reconcile/tests/__init__.py @@ -1,4 +1,3 @@ # -*- coding: utf-8 -*- -# © 2017 Therp BV -# 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 diff --git a/account_bank_statement_import_auto_reconcile/tests/test_account_bank_statement_import_auto_reconcile.py b/account_bank_statement_import_auto_reconcile/tests/test_account_bank_statement_import_auto_reconcile.py index b374f27..d04cd84 100644 --- a/account_bank_statement_import_auto_reconcile/tests/test_account_bank_statement_import_auto_reconcile.py +++ b/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 -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# Copyright 2017 Therp BV +# 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' ) diff --git a/account_bank_statement_import_auto_reconcile/views/account_bank_statement.xml b/account_bank_statement_import_auto_reconcile/views/account_bank_statement.xml index d2980f2..6ec011d 100644 --- a/account_bank_statement_import_auto_reconcile/views/account_bank_statement.xml +++ b/account_bank_statement_import_auto_reconcile/views/account_bank_statement.xml @@ -1,13 +1,11 @@ - - - - - + + + diff --git a/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import.xml b/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import.xml index 290956e..e6b3421 100644 --- a/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import.xml +++ b/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import.xml @@ -1,15 +1,13 @@ - - - - account.bank.statement.import - - - - - + + + account.bank.statement.import + + + + + - - - + + + diff --git a/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_auto_reconcile_exact_amount.xml b/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_auto_reconcile_exact_amount.xml index e32bb14..b12b599 100644 --- a/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_auto_reconcile_exact_amount.xml +++ b/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_auto_reconcile_exact_amount.xml @@ -1,26 +1,24 @@ - - - - account.bank.statement.import.auto.reconcile.exact.amount - -
- - - - - - - - - - - - - - -
-
-
-
-
+ + + account.bank.statement.import.auto.reconcile.exact.amount + +
+ + + + + + + + + + + + + + +
+
+
+
diff --git a/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_auto_reconcile_rule.xml b/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_auto_reconcile_rule.xml index d782f48..d385774 100644 --- a/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_auto_reconcile_rule.xml +++ b/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_auto_reconcile_rule.xml @@ -1,24 +1,22 @@ - - - - account.bank.statement.import.auto.reconcile.rule - -
- - - -
- - - - - account.bank.statement.import.auto.reconcile.rule - - - - - - - - + + + account.bank.statement.import.auto.reconcile.rule + +
+ + + +
+ + + + + account.bank.statement.import.auto.reconcile.rule + + + + + + + diff --git a/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_reapply_rules.xml b/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_reapply_rules.xml index 021cb43..5dfcccf 100644 --- a/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_reapply_rules.xml +++ b/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_reapply_rules.xml @@ -1,18 +1,23 @@ - - - - account.bank.statement.import.reapply.rules - -
-
This wizard will reapply the journal's matching rules on the selected bank statement(s)
-
-
-
-
-
-
-
+ + + account.bank.statement.import.reapply.rules + +
+
+ This wizard will reapply the journal's matching + rules on the selected bank statement(s) +
+
+
+
+
+
+
diff --git a/account_bank_statement_import_auto_reconcile/views/account_journal.xml b/account_bank_statement_import_auto_reconcile/views/account_journal.xml index 753c3e4..ae5dd08 100644 --- a/account_bank_statement_import_auto_reconcile/views/account_journal.xml +++ b/account_bank_statement_import_auto_reconcile/views/account_journal.xml @@ -1,14 +1,12 @@ - - - - account.journal - - - - - + + + account.journal + + + + - - - + + +