kedder / ofxstatement-iso20022

ISO20022 plugin for ofxstatement
9 stars 15 forks source link

Support for SPS camt.053 #13

Closed exu-g closed 1 year ago

exu-g commented 1 year ago

Swiss banks use a subset of iso20022 and created a spec around that.
camt.053.001.08 specifically is used for bank to customer statements.

Trying to convert a statement with this plugin resulted in the error below:

Traceback (most recent call last):
  File "/usr/bin/ofxstatement", line 33, in <module>
    sys.exit(load_entry_point('ofxstatement==0.8.0', 'console_scripts', 'ofxstatement')())
  File "/usr/lib/python3.10/site-packages/ofxstatement/tool.py", line 205, in run
    return args.func(args)
  File "/usr/lib/python3.10/site-packages/ofxstatement/tool.py", line 176, in convert
    statement = parser.parse()
  File "/home/marc/.local/lib/python3.10/site-packages/ofxstatement/plugins/iso20022.py", line 55, in parse
    self._parse_statement_properties(tree)
  File "/home/marc/.local/lib/python3.10/site-packages/ofxstatement/plugins/iso20022.py", line 88, in _parse_statement_properties
    assert iban is not None
AssertionError

I've gone ahead and fixed the issues I could see on my own fork. (branch "rs-master")
Conversion is working and as far as I can tell correct.
https://github.com/RealStickman/ofxstatement-iso20022/tree/rs-master

I'd like to make a PR here to get these changes upstream, if that's ok with you.
The tests in this repo passed for me.

Specification:
Swiss Payment Standards 2022 Chapter 4.1 discusses the schema and field mappings for camt.053

Sample:
I've already redacted sensitive information in the file, hopefully well enough.

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.08">
  <BkToCstmrStmt>
    <GrpHdr>
      <MsgId>CAMT053v08REDACTED</MsgId>
      <CreDtTm>2023-01-26T00:49:36.906+01:00</CreDtTm>
      <MsgPgntn>
        <PgNb>1</PgNb>
        <LastPgInd>true</LastPgInd>
      </MsgPgntn>
      <AddtlInf>SPS/2.0/PROD</AddtlInf>
    </GrpHdr>
    <Stmt>
      <Id>bc8b8e304a825671937ffa86f49ab6f1</Id>
      <ElctrncSeqNb>12</ElctrncSeqNb>
      <CreDtTm>2023-01-26T00:49:36.906+01:00</CreDtTm>
      <FrToDt>
        <FrDtTm>2023-01-25T00:00:00+01:00</FrDtTm>
        <ToDtTm>2023-01-25T23:59:00+01:00</ToDtTm>
      </FrToDt>
      <Acct>
        <Id>
          <Othr>
            <Id>0035-2915203-10-000</Id>
          </Othr>
        </Id>
        <Ccy>CHF</Ccy>
        <Ownr>
          <Nm>NAME REDACTED</Nm>
          <PstlAdr>
            <AdrLine>CITYREDACTED</AdrLine>
          </PstlAdr>
        </Ownr>
        <Svcr>
          <FinInstnId>
            <BICFI>BANK BIC</BICFI>
            <Nm>BANK NAME</Nm>
            <Othr>
              <Id>ID</Id>
              <Issr>VAT-ID</Issr>
            </Othr>
          </FinInstnId>
        </Svcr>
      </Acct>
      <Bal>
        <Tp>
          <CdOrPrtry>
            <Cd>OPBD</Cd>
          </CdOrPrtry>
        </Tp>
        <Amt Ccy="CHF">832.01</Amt>
        <CdtDbtInd>CRDT</CdtDbtInd>
        <Dt>
          <Dt>2023-01-25</Dt>
        </Dt>
      </Bal>
      <Bal>
        <Tp>
          <CdOrPrtry>
            <Cd>CLAV</Cd>
          </CdOrPrtry>
        </Tp>
        <Amt Ccy="CHF">2116.31</Amt>
        <CdtDbtInd>CRDT</CdtDbtInd>
        <Dt>
          <Dt>2023-01-25</Dt>
        </Dt>
      </Bal>
      <Bal>
        <Tp>
          <CdOrPrtry>
            <Cd>CLBD</Cd>
          </CdOrPrtry>
        </Tp>
        <Amt Ccy="CHF">2116.31</Amt>
        <CdtDbtInd>CRDT</CdtDbtInd>
        <Dt>
          <Dt>2023-01-25</Dt>
        </Dt>
      </Bal>
      <TxsSummry>
        <TtlNtries>
          <NbOfNtries>1</NbOfNtries>
          <Sum>1284.30</Sum>
          <TtlNetNtry>
            <Amt>1284.30</Amt>
            <CdtDbtInd>CRDT</CdtDbtInd>
          </TtlNetNtry>
        </TtlNtries>
        <TtlCdtNtries>
          <NbOfNtries>1</NbOfNtries>
          <Sum>1284.30</Sum>
        </TtlCdtNtries>
        <TtlDbtNtries>
          <NbOfNtries>0</NbOfNtries>
          <Sum>0.00</Sum>
        </TtlDbtNtries>
      </TxsSummry>
      <Ntry>
        <Amt Ccy="CHF">1284.30</Amt>
        <CdtDbtInd>CRDT</CdtDbtInd>
        <RvslInd>false</RvslInd>
        <Sts>
          <Cd>BOOK</Cd>
        </Sts>
        <BookgDt>
          <Dt>2023-01-25</Dt>
        </BookgDt>
        <ValDt>
          <Dt>2023-01-25</Dt>
        </ValDt>
        <AcctSvcrRef>8082230156M02SJ62/1010</AcctSvcrRef>
        <BkTxCd>
          <Domn>
            <Cd>PMNT</Cd>
            <Fmly>
              <Cd>RCDT</Cd>
              <SubFmlyCd>DMCT</SubFmlyCd>
            </Fmly>
          </Domn>
        </BkTxCd>
        <AmtDtls>
          <TxAmt>
            <Amt Ccy="CHF">1284.30</Amt>
          </TxAmt>
        </AmtDtls>
        <NtryDtls>
          <TxDtls>
            <Refs>
              <MsgId>4223-F023401-02-M03920</MsgId>
              <AcctSvcrRef>A032-J30K20-03-JF021</AcctSvcrRef>
              <PmtInfId>F213-402451-MS-10432</PmtInfId>
              <EndToEndId>9502830971</EndToEndId>
              <UETR>75e77105-a09f-4f9e-bfa8-e82e91ab209b</UETR>
            </Refs>
            <Amt Ccy="CHF">1284.30</Amt>
            <CdtDbtInd>CRDT</CdtDbtInd>
            <AmtDtls>
              <TxAmt>
                <Amt Ccy="CHF">1284.30</Amt>
              </TxAmt>
            </AmtDtls>
            <RltdPties>
              <Dbtr>
                <Pty>
                  <Nm>PAYEE</Nm>
                  <PstlAdr>
                    <AdrLine>PAYEE ADDRESS</AdrLine>
                  </PstlAdr>
                </Pty>
              </Dbtr>
            </RltdPties>
            <RmtInf>
              <Ustrd>PAYMENT INFO</Ustrd>
            </RmtInf>
          </TxDtls>
        </NtryDtls>
      </Ntry>
    </Stmt>
  </BkToCstmrStmt>
</Document>
sschueller commented 1 year ago

FYI, wise (wise.com) also offers an export in the format of CAMT.053 and those exports have the same error regarding IBAN.

henk84 commented 1 year ago

Just FYI: I have made #14 which also incorporates your changes.

exu-g commented 1 year ago

Thanks @henk84 for making the PR and with #17 merged I can confirm camt.053 files to be working.