Browse Source

[ADD] wizard to reapply matching rules

pull/99/head
Holger Brunn 8 years ago
parent
commit
58f27058f1
No known key found for this signature in database GPG Key ID: 1C9760FECA3AE18
  1. 2
      account_bank_statement_import_auto_reconcile/__openerp__.py
  2. 1
      account_bank_statement_import_auto_reconcile/models/__init__.py
  3. 1
      account_bank_statement_import_auto_reconcile/models/account_bank_statement_import.py
  4. 40
      account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_reapply_rules.py
  5. 13
      account_bank_statement_import_auto_reconcile/views/account_bank_statement.xml
  6. 18
      account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_reapply_rules.xml

2
account_bank_statement_import_auto_reconcile/__openerp__.py

@ -18,6 +18,8 @@
"demo/account_bank_statement_import_auto_reconcile_rule.xml", "demo/account_bank_statement_import_auto_reconcile_rule.xml",
], ],
"data": [ "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_auto_reconcile_exact_amount.xml",
"views/account_bank_statement_import.xml", "views/account_bank_statement_import.xml",
"views/account_journal.xml", "views/account_journal.xml",

1
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_auto_reconcile_odoo
from . import account_bank_statement_import from . import account_bank_statement_import
from . import account_bank_statement_import_auto_reconcile_exact_amount from . import account_bank_statement_import_auto_reconcile_exact_amount
from . import account_bank_statement_import_reapply_rules

1
account_bank_statement_import_auto_reconcile/models/account_bank_statement_import.py

@ -4,6 +4,7 @@
from openerp import _, api, fields, models from openerp import _, api, fields, models
# pylint: disable=R7980
class AccountBankStatementImport(models.TransientModel): class AccountBankStatementImport(models.TransientModel):
_inherit = 'account.bank.statement.import' _inherit = 'account.bank.statement.import'

40
account_bank_statement_import_auto_reconcile/models/account_bank_statement_import_reapply_rules.py

@ -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
account_bank_statement_import_auto_reconcile/views/account_bank_statement.xml

@ -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
account_bank_statement_import_auto_reconcile/views/account_bank_statement_import_reapply_rules.xml

@ -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>
Loading…
Cancel
Save