Browse Source

[IMP] CAMT: Add option to aggregate batches

pull/174/head
Andrea 6 years ago
parent
commit
4f5a563705
  1. 14
      account_bank_statement_import_camt_oca/README.rst
  2. 3
      account_bank_statement_import_camt_oca/__manifest__.py
  3. 2
      account_bank_statement_import_camt_oca/models/__init__.py
  4. 6
      account_bank_statement_import_camt_oca/models/parser.py
  5. 10
      account_bank_statement_import_camt_oca/models/res_company.py
  6. 10
      account_bank_statement_import_camt_oca/models/res_config_settings.py
  7. 61
      account_bank_statement_import_camt_oca/tests/test_import_bank_statement.py
  8. 24
      account_bank_statement_import_camt_oca/views/res_config_settings.xml

14
account_bank_statement_import_camt_oca/README.rst

@ -10,6 +10,20 @@ Module to import SEPA CAMT.053 and CAMT.054 Format bank statement files.
Based on the Banking addons framework.
Configuration
=============
The user can configure the way CAMT bank statements are imported:
* Go to *Settings* -> *General Settings* -> *Invoicing*
* Set the *CAMT (OCA) Import Batch* checkbox
If the *CAMT (OCA) Import Batch* checkbox is false, the import will load every single line of the TxDtls details;
instead if it's true, it will load only the total amount of each batch of lines.
To be able to access the configuration settings, the user must belong to *Show Full Accounting Features* group.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/174/11.0

3
account_bank_statement_import_camt_oca/__manifest__.py

@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'CAMT Format Bank Statements Import',
'version': '11.0.1.0.4',
'version': '11.0.1.1.0',
'license': 'AGPL-3',
'author': 'Odoo Community Association (OCA), Therp BV',
'website': 'https://github.com/OCA/bank-statement-import',
@ -12,5 +12,6 @@
],
'data': [
'views/account_bank_statement_import.xml',
'views/res_config_settings.xml',
],
}

2
account_bank_statement_import_camt_oca/models/__init__.py

@ -2,3 +2,5 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import parser
from . import account_bank_statement_import
from . import res_company
from . import res_config_settings

6
account_bank_statement_import_camt_oca/models/parser.py

@ -19,13 +19,13 @@ class CamtParser(models.AbstractModel):
sign = 1
amount = 0.0
sign_node = node.xpath('ns:CdtDbtInd', namespaces={'ns': ns})
if not sign_node:
if not sign_node and not self.env.user.company_id.camt_import_batch:
sign_node = node.xpath(
'../../ns:CdtDbtInd', namespaces={'ns': ns})
if sign_node and sign_node[0].text == 'DBIT':
sign = -1
amount_node = node.xpath('ns:Amt', namespaces={'ns': ns})
if not amount_node:
if not amount_node and not self.env.user.company_id.camt_import_batch:
amount_node = node.xpath(
'./ns:AmtDtls/ns:TxAmt/ns:Amt', namespaces={'ns': ns})
if amount_node:
@ -133,6 +133,8 @@ class CamtParser(models.AbstractModel):
transaction = transaction_base.copy()
self.parse_transaction_details(ns, node, transaction)
yield transaction
if self.env.user.company_id.camt_import_batch:
break
def get_balance_amounts(self, ns, node):
"""Return opening and closing balance.

10
account_bank_statement_import_camt_oca/models/res_company.py

@ -0,0 +1,10 @@
# Copyright 2018 Onestein (<http://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ResCompany(models.Model):
_inherit = 'res.company'
camt_import_batch = fields.Boolean()

10
account_bank_statement_import_camt_oca/models/res_config_settings.py

@ -0,0 +1,10 @@
# Copyright 2018 Onestein (<http://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
camt_import_batch = fields.Boolean(related='company_id.camt_import_batch')

61
account_bank_statement_import_camt_oca/tests/test_import_bank_statement.py

@ -148,3 +148,64 @@ class TestImport(TransactionCase):
action['context']['statement_ids']
):
self.assertTrue(statement.line_ids)
def test_statement_import_batch(self):
"""Test correct creation of single statement."""
transactions = [
{
'account_number': 'NL46ABNA0499998748',
'amount': -754.25,
'date': '2014-01-05',
'ref': '435005714488-ABNO33052620',
},
{
'account_number': 'NL46ABNA0499998748',
'amount': -664.05,
'date': '2014-01-05',
'ref': 'TESTBANK/NL/20141229/01206408',
},
{
'account_number': 'NL69ABNA0522123643',
'amount': 1405.31,
'date': '2014-01-05',
'ref': '115',
},
]
self.env.user.company_id.camt_import_batch = True
testfile = get_module_resource(
'account_bank_statement_import_camt_oca',
'test_files',
'test-camt053',
)
with open(testfile, 'rb') as datafile:
action = self.env['account.bank.statement.import'].create({
'data_file': base64.b64encode(datafile.read())
}).import_file()
for statement in self.env['account.bank.statement'].browse(
action['context']['statement_ids']
):
self.assertTrue(any(
all(
line[key] == transactions[0][key]
for key in ['amount', 'date', 'ref']
) and
line.bank_account_id.acc_number ==
self.transactions[0]['account_number']
for line in statement.line_ids
))
def test_config(self):
"""Test configuration of batch statements."""
self.assertFalse(self.env.user.company_id.camt_import_batch)
conf = self.env['res.config.settings'].create({
'camt_import_batch': True
})
conf.set_values()
self.assertTrue(self.env.user.company_id.camt_import_batch)
conf.write({
'camt_import_batch': False
})
conf.set_values()
self.assertFalse(self.env.user.company_id.camt_import_batch)

24
account_bank_statement_import_camt_oca/views/res_config_settings.xml

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="inherit_id" ref="account.res_config_settings_view_form"/>
<field name="model">res.config.settings</field>
<field name="arch" type="xml">
<xpath expr="//div[@id='bank_cash']" position="inside">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="camt_import_batch"/>
</div>
<div class="o_setting_right_pane">
<label string="CAMT (OCA) Import Batch"/>
<div class="text-muted">
Import batches of CAMT bank statements (do not import single detailed lines).
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save