Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] wizard to reapply matching rules
- Loading branch information
Showing
6 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ank_statement_import_auto_reconcile/models/account_bank_statement_import_reapply_rules.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'} |
13 changes: 13 additions & 0 deletions
13
account_bank_statement_import_auto_reconcile/views/account_bank_statement.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
18 changes: 18 additions & 0 deletions
18
...ank_statement_import_auto_reconcile/views/account_bank_statement_import_reapply_rules.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |