raphaelm / python-sepaxml

SEPA Direct Debit XML generation in python
MIT License
110 stars 41 forks source link

KeyError on address "PstlAdr_Dbtr_Node" #63

Open halbow opened 1 month ago

halbow commented 1 month ago

Hi,

When generating a transfer SEPA with batch mode and not specifying all the address type, I get a KeyError:

        if PmtInf_nodes['PstlAdr_Dbtr_Node']:
>           PmtInf_nodes['DbtrNode'].append(TX_nodes['PstlAdr_Dbtr_Node'])
E           KeyError: 'PstlAdr_Dbtr_Node'

Seeing the Error, I'm wondering if there's a copy/paste error between PmtInf_nodes and TX_nodes?

Here's a test to reproduce the issue:

def test_sepa_repro() -> None:
    sepa_receiver = {
        "name": "Test von Testenstein",
        "IBAN": "NL50BANK1234567890",
        "BIC": "BANKNL2A",
        "batch": False,
        "currency": "EUR",  # ISO 4217
        "address": {
            "country": "DE",
            "lines": ["Line 1", "Line 2"],
        },
    }
    sepa_sender = {
        "name": "Test von Testenstein",
        "IBAN": "NL50BANK1234567890",
        "BIC": "BANKNL2A",
        "amount": 5000,  # in cents
        "execution_date": date(2025, 1, 1),
        "description": "Test transaction",
        # "endtoend_id": str(uuid.uuid1()).replace("-", "")
        "address": {
            "country": "DE",
            "lines": ["Line 1", "Line 2"],
        },
    }

    sepa = SepaTransfer(sepa_receiver, clean=True)

    sepa.add_payment(sepa_sender)
    result = sepa.export(validate=True)
    assert result is not None

I opened this PR to attempt to fix the issue https://github.com/raphaelm/python-sepaxml/pull/64