mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
@@ -332,6 +332,9 @@ class AccountStatementImport(models.TransientModel):
|
||||
st_lines_to_create.append(lvals)
|
||||
|
||||
if len(st_lines_to_create) > 0:
|
||||
if not st_lines_to_create[0].get("sequence"):
|
||||
for seq, vals in enumerate(st_lines_to_create, start=1):
|
||||
vals["sequence"] = seq
|
||||
# Remove values that won't be used to create records
|
||||
st_vals.pop("transactions", None)
|
||||
# Create the statement with lines
|
||||
|
||||
@@ -65,7 +65,7 @@ class CamtParser(models.AbstractModel):
|
||||
"./ns:Refs/ns:InstrId",
|
||||
],
|
||||
transaction,
|
||||
"name",
|
||||
"payment_ref",
|
||||
join_str="\n",
|
||||
)
|
||||
# name
|
||||
@@ -130,12 +130,14 @@ class CamtParser(models.AbstractModel):
|
||||
|
||||
def parse_entry(self, ns, node):
|
||||
"""Parse an Ntry node and yield transactions"""
|
||||
transaction = {"name": "/", "amount": 0} # fallback defaults
|
||||
transaction = {"payment_ref": "/", "amount": 0} # fallback defaults
|
||||
self.add_value_from_node(ns, node, "./ns:BookgDt/ns:Dt", transaction, "date")
|
||||
amount = self.parse_amount(ns, node)
|
||||
if amount != 0.0:
|
||||
transaction["amount"] = amount
|
||||
self.add_value_from_node(ns, node, "./ns:AddtlNtryInf", transaction, "name")
|
||||
self.add_value_from_node(
|
||||
ns, node, "./ns:AddtlNtryInf", transaction, "narration"
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
|
||||
@@ -7,12 +7,14 @@
|
||||
'transactions': [{'account_number': 'CH2222000000123456789',
|
||||
'amount': 2187.0,
|
||||
'date': '2017-03-22',
|
||||
'name': 'CRÉDIT GROUPÉ BVR TRAITEMENT DU 22.03.2017 NUMÉRO CLIENT 01-70884-3 PAQUET ID: 123456CHCAFEBABE',
|
||||
'narration': 'CRÉDIT GROUPÉ BVR TRAITEMENT DU 22.03.2017 NUMÉRO CLIENT 01-70884-3 PAQUET ID: 123456CHCAFEBABE',
|
||||
'partner_name': 'Banque Cantonale Vaudoise',
|
||||
'payment_ref': '/',
|
||||
'ref': '302388292000011111111111111'},
|
||||
{'account_number': 'CH3333000000123456789',
|
||||
'amount': 1296.0,
|
||||
'date': '2017-03-22',
|
||||
'name': 'CRÉDIT GROUPÉ BVR TRAITEMENT DU 22.03.2017 NUMÉRO CLIENT 01-70884-3 PAQUET ID: 123456CHCAFEBABE',
|
||||
'narration': 'CRÉDIT GROUPÉ BVR TRAITEMENT DU 22.03.2017 NUMÉRO CLIENT 01-70884-3 PAQUET ID: 123456CHCAFEBABE',
|
||||
'partner_name': 'Banque Cantonale Vaudoise',
|
||||
'payment_ref': '/',
|
||||
'ref': '302388292000022222222222222'}]}])
|
||||
|
||||
@@ -7,28 +7,24 @@
|
||||
'transactions': [{'account_number': 'NL46ABNA0499998748',
|
||||
'amount': -754.25,
|
||||
'date': '2014-01-05',
|
||||
'name': 'Insurance policy 857239PERIOD 01.01.2014 - 31.12.2014',
|
||||
'partner_name': 'INSURANCE COMPANY TESTX',
|
||||
'payment_ref': 'MKB Insurance 859239PERIOD 01.01.2014 - 31.12.2014',
|
||||
'ref': '435005714488-ABNO33052620'},
|
||||
{'account_number': 'NL46ABNA0499998748',
|
||||
'amount': -564.05,
|
||||
'date': '2014-01-05',
|
||||
'name': 'Direct Debit S14 0410',
|
||||
'partner_name': 'Test Customer',
|
||||
'payment_ref': 'Direct debit S14 0410 AC07 Rek.nummer blokkade TESTBANK/NL/20141229/01206408',
|
||||
'ref': 'TESTBANK/NL/20141229/01206408'},
|
||||
{'account_number': 'NL46ABNA0499998748',
|
||||
'amount': -100.0,
|
||||
'date': '2014-01-05',
|
||||
'name': 'Direct Debit S14 0410',
|
||||
'partner_name': 'Test Customer',
|
||||
'payment_ref': 'Direct debit S14 0410 AC07 Rek.nummer blokkade TESTBANK/NL/20141229/01206408',
|
||||
'ref': 'TESTBANK/NL/20141229/01206407'},
|
||||
{'account_number': 'NL69ABNA0522123643',
|
||||
'amount': 1405.31,
|
||||
'date': '2014-01-05',
|
||||
'name': 'INNDNL2U20140105000217200000708',
|
||||
'partner_name': '3rd party Media',
|
||||
'payment_ref': '#RD PARTY MEDIA CUSNO 90782 4210773',
|
||||
'ref': '115'}]}])
|
||||
|
||||
@@ -8,8 +8,6 @@ import pprint
|
||||
import tempfile
|
||||
from datetime import date
|
||||
|
||||
import mock
|
||||
|
||||
from odoo.modules.module import get_module_resource
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
@@ -113,12 +111,7 @@ class TestImport(TransactionCase):
|
||||
}
|
||||
)
|
||||
|
||||
@mock.patch(
|
||||
"odoo.addons.account.models.sequence_mixin."
|
||||
"SequenceMixin._constrains_date_sequence",
|
||||
side_effect=False,
|
||||
)
|
||||
def test_statement_import(self, constraint):
|
||||
def test_statement_import(self):
|
||||
"""Test correct creation of single statement."""
|
||||
testfile = get_module_resource(
|
||||
"account_statement_import_camt", "test_files", "test-camt053"
|
||||
@@ -150,12 +143,7 @@ class TestImport(TransactionCase):
|
||||
)
|
||||
)
|
||||
|
||||
@mock.patch(
|
||||
"odoo.addons.account.models.sequence_mixin."
|
||||
"SequenceMixin._constrains_date_sequence",
|
||||
side_effect=False,
|
||||
)
|
||||
def test_zip_import(self, constraint):
|
||||
def test_zip_import(self):
|
||||
"""Test import of multiple statements from zip file."""
|
||||
testfile = get_module_resource(
|
||||
"account_statement_import_camt", "test_files", "test-camt053.zip"
|
||||
@@ -169,4 +157,5 @@ class TestImport(TransactionCase):
|
||||
[("name", "in", ["1234Test/2", "1234Test/3"])]
|
||||
)
|
||||
|
||||
self.assertTrue(all([st.line_ids for st in bank_st_record]))
|
||||
self.assertTrue(all([st.line_ids for st in bank_st_record]))
|
||||
self.assertEqual(bank_st_record[0].line_ids.mapped("sequence"), [1, 2, 3])
|
||||
|
||||
@@ -25,11 +25,10 @@ class AccountStatementImport(models.TransientModel):
|
||||
amount = -amount
|
||||
statement.line_ids.create(
|
||||
{
|
||||
"name": statement.name,
|
||||
"amount": amount,
|
||||
"statement_id": statement.id,
|
||||
"date": statement.date,
|
||||
"payment_ref": "/",
|
||||
"payment_ref": statement.name,
|
||||
}
|
||||
)
|
||||
statement.balance_end_real = statement.balance_start
|
||||
|
||||
@@ -58,7 +58,7 @@ class CamtParser(models.AbstractModel):
|
||||
"./ns:RmtInf/ns:Strd/ns:CdtrRefInf/ns:Ref", namespaces={"ns": ns}
|
||||
)
|
||||
if len(isr_number):
|
||||
transaction["name"] = isr_number[0].text
|
||||
transaction["payment_ref"] = isr_number[0].text
|
||||
partner_ref = self._get_partner_ref(isr_number[0].text)
|
||||
if partner_ref:
|
||||
transaction["partner_ref"] = partner_ref
|
||||
@@ -68,11 +68,11 @@ class CamtParser(models.AbstractModel):
|
||||
"./ns:AddtlNtryInf",
|
||||
"/ns:Refs/ns:InstrId",
|
||||
]
|
||||
name = transaction["name"]
|
||||
payment_ref = transaction["payment_ref"]
|
||||
for xpath_expr in xpath_exprs:
|
||||
found_node = node.xpath(xpath_expr, namespaces={"ns": ns})
|
||||
if found_node:
|
||||
name = found_node[0].text
|
||||
payment_ref = found_node[0].text
|
||||
break
|
||||
trans_id_node = (
|
||||
node.getparent()
|
||||
@@ -80,9 +80,9 @@ class CamtParser(models.AbstractModel):
|
||||
.xpath("./ns:AcctSvcrRef", namespaces={"ns": ns})
|
||||
)
|
||||
if trans_id_node:
|
||||
name = "{} ({})".format(name, trans_id_node[0].text)
|
||||
if name:
|
||||
transaction["name"] = name
|
||||
payment_ref = "{} ({})".format(payment_ref, trans_id_node[0].text)
|
||||
if payment_ref:
|
||||
transaction["payment_ref"] = payment_ref
|
||||
# End add esr to the label.
|
||||
|
||||
# add transaction id to ref
|
||||
|
||||
@@ -27,21 +27,21 @@ class TestGetPartnerRef(common.TransactionCase):
|
||||
self.ICP.set_param("isr_partner_ref", "12")
|
||||
ref = "11 11111 11112 34567 11111 11111".replace(" ", "")
|
||||
partner_ref = self.Parser._get_partner_ref(ref)
|
||||
self.assertEquals(partner_ref, "234567")
|
||||
self.assertEqual(partner_ref, "234567")
|
||||
|
||||
def test_ICP_full(self):
|
||||
"""Test full format of partner ref definition"""
|
||||
self.ICP.set_param("isr_partner_ref", "12,6")
|
||||
ref = "11 11111 11112 34567 11111 11111".replace(" ", "")
|
||||
partner_ref = self.Parser._get_partner_ref(ref)
|
||||
self.assertEquals(partner_ref, "234567")
|
||||
self.assertEqual(partner_ref, "234567")
|
||||
|
||||
def test_zero_stripped(self):
|
||||
"""Test full format of partner ref definition"""
|
||||
self.ICP.set_param("isr_partner_ref", "12,6")
|
||||
ref = "11 11111 11110 00560 11111 11111".replace(" ", "")
|
||||
partner_ref = self.Parser._get_partner_ref(ref)
|
||||
self.assertEquals(partner_ref, "560")
|
||||
self.assertEqual(partner_ref, "560")
|
||||
|
||||
def test_bad_ICP(self):
|
||||
"""Test ir config parameter validation"""
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
import base64
|
||||
|
||||
import mock
|
||||
|
||||
from odoo.modules.module import get_module_resource
|
||||
from odoo.tests.common import SavepointCase
|
||||
|
||||
@@ -39,12 +37,7 @@ class TestGenerateBankStatement(SavepointCase):
|
||||
}
|
||||
)
|
||||
|
||||
@mock.patch(
|
||||
"odoo.addons.account.models.sequence_mixin."
|
||||
"SequenceMixin._constrains_date_sequence",
|
||||
side_effect=False,
|
||||
)
|
||||
def _load_statement(self, constraint):
|
||||
def _load_statement(self):
|
||||
testfile = get_module_resource(
|
||||
"account_statement_import_camt", "test_files", "test-camt053"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user