Skip to content

Commit

Permalink
[ADD] wizard to reapply matching rules
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Apr 7, 2017
1 parent 61dd2f4 commit 58f2705
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
2 changes: 2 additions & 0 deletions account_bank_statement_import_auto_reconcile/__openerp__.py
Expand Up @@ -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",
Expand Down
Expand Up @@ -7,3 +7,4 @@
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
Expand Up @@ -4,6 +4,7 @@
from openerp import _, api, fields, models


# pylint: disable=R7980
class AccountBankStatementImport(models.TransientModel):
_inherit = 'account.bank.statement.import'

Expand Down
@@ -0,0 +1,40 @@
# -*- 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


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'}
@@ -0,0 +1,13 @@
<?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>
@@ -0,0 +1,18 @@
<?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>

0 comments on commit 58f2705

Please sign in to comment.