mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[IMP] account_bank_statement_import_camt_oca: support DtTm
This commit is contained in:
@@ -4,9 +4,11 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
import re
|
||||
|
||||
import pytz
|
||||
from dateutil.parser import isoparse
|
||||
from lxml import etree
|
||||
|
||||
from odoo import models
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class CamtParser(models.AbstractModel):
|
||||
@@ -130,6 +132,19 @@ class CamtParser(models.AbstractModel):
|
||||
"""Parse an Ntry node and yield transactions"""
|
||||
transaction = {"name": "/", "amount": 0} # fallback defaults
|
||||
self.add_value_from_node(ns, node, "./ns:BookgDt/ns:Dt", transaction, "date")
|
||||
# Check `DtTm` if date was not found in `Dt`.
|
||||
if "date" not in transaction:
|
||||
self.add_value_from_node(
|
||||
ns, node, "./ns:BookgDt/ns:DtTm", transaction, "date"
|
||||
)
|
||||
date_val = transaction.get("date")
|
||||
if date_val:
|
||||
# Get the date respectful of the timezone. Credit to @StefanRijnhart.
|
||||
dt_no_tz = isoparse(date_val).astimezone(pytz.utc).replace(tzinfo=None)
|
||||
transaction["date"] = fields.Date.to_string(
|
||||
fields.Date.context_today(self, timestamp=dt_no_tz)
|
||||
)
|
||||
|
||||
amount = self.parse_amount(ns, node)
|
||||
if amount != 0.0:
|
||||
transaction["amount"] = amount
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02">
|
||||
<BkToCstmrStmt>
|
||||
<GrpHdr>
|
||||
<MsgId>TESTBANK/NL/1420561226673</MsgId>
|
||||
<CreDtTm>2014-01-06T16:20:26.673Z</CreDtTm>
|
||||
</GrpHdr>
|
||||
<Stmt>
|
||||
<Id>1234Test/1</Id>
|
||||
<LglSeqNb>2</LglSeqNb>
|
||||
<CreDtTm>2014-01-06T16:20:26.673Z</CreDtTm>
|
||||
<FrToDt>
|
||||
<FrDtTm>2014-01-05T00:00:00.000Z</FrDtTm>
|
||||
<ToDtTm>2014-01-05T23:59:59.999Z</ToDtTm>
|
||||
</FrToDt>
|
||||
<Acct>
|
||||
<Id>
|
||||
<IBAN>NL77ABNA0574908765</IBAN>
|
||||
</Id>
|
||||
<Nm>Example company</Nm>
|
||||
<Svcr>
|
||||
<FinInstnId>
|
||||
<BIC>ABNANL2A</BIC>
|
||||
</FinInstnId>
|
||||
</Svcr>
|
||||
</Acct>
|
||||
<Bal>
|
||||
<Tp>
|
||||
<CdOrPrtry>
|
||||
<Cd>OPBD</Cd>
|
||||
</CdOrPrtry>
|
||||
</Tp>
|
||||
<Amt Ccy="EUR">15568.27</Amt>
|
||||
<CdtDbtInd>CRDT</CdtDbtInd>
|
||||
<Dt>
|
||||
<Dt>2014-01-05</Dt>
|
||||
</Dt>
|
||||
</Bal>
|
||||
<Bal>
|
||||
<Tp>
|
||||
<CdOrPrtry>
|
||||
<Cd>CLBD</Cd>
|
||||
</CdOrPrtry>
|
||||
</Tp>
|
||||
<Amt Ccy="EUR">15121.12</Amt>
|
||||
<CdtDbtInd>CRDT</CdtDbtInd>
|
||||
<Dt>
|
||||
<Dt>2014-01-05</Dt>
|
||||
</Dt>
|
||||
</Bal>
|
||||
<Ntry>
|
||||
<Amt Ccy="EUR">754.25</Amt>
|
||||
<CdtDbtInd>DBIT</CdtDbtInd>
|
||||
<Sts>BOOK</Sts>
|
||||
<BookgDt>
|
||||
<DtTm>2014-01-04T23:00:00.000Z</DtTm>
|
||||
</BookgDt>
|
||||
<ValDt>
|
||||
<Dt>2014-01-05</Dt>
|
||||
</ValDt>
|
||||
<BkTxCd>
|
||||
<Domn>
|
||||
<Cd>PMNT</Cd>
|
||||
<Fmly>
|
||||
<Cd>RDDT</Cd>
|
||||
<SubFmlyCd>ESDD</SubFmlyCd>
|
||||
</Fmly>
|
||||
</Domn>
|
||||
<Prtry>
|
||||
<Cd>EI</Cd>
|
||||
</Prtry>
|
||||
</BkTxCd>
|
||||
<NtryDtls>
|
||||
<TxDtls>
|
||||
<Refs>
|
||||
<InstrId>INNDNL2U20141231000142300002844</InstrId>
|
||||
<EndToEndId>435005714488-ABNO33052620</EndToEndId>
|
||||
<MndtId>1880000341866</MndtId>
|
||||
</Refs>
|
||||
<AmtDtls>
|
||||
<TxAmt>
|
||||
<Amt Ccy="EUR">754.25</Amt>
|
||||
</TxAmt>
|
||||
</AmtDtls>
|
||||
<RltdPties>
|
||||
<Cdtr>
|
||||
<Nm>INSURANCE COMPANY TESTX</Nm>
|
||||
<PstlAdr>
|
||||
<StrtNm>TEST STREET 20</StrtNm>
|
||||
<TwnNm>1234 AB TESTCITY</TwnNm>
|
||||
<Ctry>NL</Ctry>
|
||||
</PstlAdr>
|
||||
</Cdtr>
|
||||
<CdtrAcct>
|
||||
<Id>
|
||||
<IBAN>NL46ABNA0499998748</IBAN>
|
||||
</Id>
|
||||
</CdtrAcct>
|
||||
</RltdPties>
|
||||
<RltdAgts>
|
||||
<CdtrAgt>
|
||||
<FinInstnId>
|
||||
<BIC>ABNANL2A</BIC>
|
||||
</FinInstnId>
|
||||
</CdtrAgt>
|
||||
</RltdAgts>
|
||||
<RmtInf>
|
||||
<Ustrd>Insurance policy 857239PERIOD 01.01.2014 - 31.12.2014</Ustrd>
|
||||
</RmtInf>
|
||||
<AddtlTxInf>MKB Insurance 859239PERIOD 01.01.2014 - 31.12.2014</AddtlTxInf>
|
||||
</TxDtls>
|
||||
</NtryDtls>
|
||||
</Ntry>
|
||||
</Stmt>
|
||||
</BkToCstmrStmt>
|
||||
</Document>
|
||||
@@ -152,3 +152,23 @@ class TestImport(TransactionCase):
|
||||
)
|
||||
|
||||
self.assertTrue(all([st.line_ids for st in bank_st_record]))
|
||||
|
||||
def test_import_transaction_bookgdt_datetime(self):
|
||||
"""Test correct date is set when `BookgDt` is a datetime (`DtTm`)."""
|
||||
testfile = get_module_resource(
|
||||
"account_bank_statement_import_camt_oca",
|
||||
"test_files",
|
||||
"test-camt053-bookgdt-dttm",
|
||||
)
|
||||
with open(testfile, "rb") as datafile:
|
||||
camt_file = base64.b64encode(datafile.read())
|
||||
|
||||
self.env["account.bank.statement.import"].create(
|
||||
{"attachment_ids": [(0, 0, {"name": "test file", "datas": camt_file})]}
|
||||
).import_file()
|
||||
|
||||
bank_st_record = self.env["account.bank.statement"].search(
|
||||
[("name", "=", "1234Test/1")], limit=1
|
||||
)
|
||||
statement_lines = bank_st_record.line_ids
|
||||
self.assertEqual(statement_lines.mapped("date"), [date(2014, 1, 5)])
|
||||
|
||||
Reference in New Issue
Block a user