From 58f27058f13949296f5629a50e700cb58d1b7f1a Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Fri, 7 Apr 2017 10:22:58 +0200 Subject: [PATCH] [ADD] wizard to reapply matching rules --- .../__openerp__.py | 2 + .../models/__init__.py | 1 + .../models/account_bank_statement_import.py | 1 + ...unt_bank_statement_import_reapply_rules.py | 40 +++++++++++++++++++ .../views/account_bank_statement.xml | 13 ++++++ ...nt_bank_statement_import_reapply_rules.xml | 18 +++++++++ 6 files changed, 75 insertions(+) create mode 100644 account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_reapply_rules.py create mode 100644 account_bank_statement_import_auto_reconcile/views/account_bank_statement.xml create mode 100644 account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_reapply_rules.xml diff --git a/account_bank_statement_import_auto_reconcile/__openerp__.py b/account_bank_statement_import_auto_reconcile/__openerp__.py index c993fb3..8e908b2 100644 --- a/account_bank_statement_import_auto_reconcile/__openerp__.py +++ b/account_bank_statement_import_auto_reconcile/__openerp__.py @@ -18,6 +18,8 @@ "demo/account_bank_statement_import_auto_reconcile_rule.xml", ], "data": [ + "views/account_bank_statement_import_reapply_rules.xml", + "views/account_bank_statement.xml", "views/account_bank_statement_import_auto_reconcile_exact_amount.xml", "views/account_bank_statement_import.xml", "views/account_journal.xml", diff --git a/account_bank_statement_import_auto_reconcile/models/__init__.py b/account_bank_statement_import_auto_reconcile/models/__init__.py index dd35274..233ac10 100644 --- a/account_bank_statement_import_auto_reconcile/models/__init__.py +++ b/account_bank_statement_import_auto_reconcile/models/__init__.py @@ -7,3 +7,4 @@ from . import account_journal from . import account_bank_statement_import_auto_reconcile_odoo from . import account_bank_statement_import from . import account_bank_statement_import_auto_reconcile_exact_amount +from . import account_bank_statement_import_reapply_rules 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 ad990ed..f54f1e9 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 @@ -4,6 +4,7 @@ from openerp import _, api, fields, models +# pylint: disable=R7980 class AccountBankStatementImport(models.TransientModel): _inherit = 'account.bank.statement.import' 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 new file mode 100644 index 0000000..0ab88a4 --- /dev/null +++ b/account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_reapply_rules.py @@ -0,0 +1,40 @@ +# -*- 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 + + +class AccountBankStatementImportReapplyRules(models.TransientModel): + _inherit = 'account.bank.statement.import' + _name = 'account.bank.statement.import.reapply.rules' + + data_file = fields.Binary(required=False) + + @api.multi + def action_reapply_rules(self): + statements = self.env['account.bank.statement'].browse( + self.env.context.get('active_ids', []) + ) + journal = statements.mapped('journal_id') + if len(journal) != 1: + raise UserError(_( + 'You can only reapply rules on statements with the same ' + 'journal!' + )) + + self.write({'journal_id': journal.id}) + reconcile_rules = journal.statement_import_auto_reconcile_rule_ids\ + .mapped(lambda x: self.env[x.rule_type].new({ + 'wizard_id': self.id, + 'options': x.options + })) + + for line in self.env['account.bank.statement.line'].search([ + ('statement_id', 'in', statements.ids), + ('journal_entry_id', '=', False), + ]): + for rule in reconcile_rules: + if rule.reconcile(line): + break + return {'type': 'ir.actions.act_window_close'} 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 new file mode 100644 index 0000000..d2980f2 --- /dev/null +++ b/account_bank_statement_import_auto_reconcile/views/account_bank_statement.xml @@ -0,0 +1,13 @@ + + + + + + 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 new file mode 100644 index 0000000..021cb43 --- /dev/null +++ b/account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_reapply_rules.xml @@ -0,0 +1,18 @@ + + + + + account.bank.statement.import.reapply.rules + +
+
This wizard will reapply the journal's matching rules on the selected bank statement(s)
+ +
+
+
+
+