Skip to content

Commit

Permalink
Merge pull request #37 from JonatasViscaino/pain003_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau authored Jul 28, 2023
2 parents d51e35e + 712469a commit 86a271f
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pain001/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@

"""The Python pain001 module."""
__all__ = ["pain001"]
__version__ = "0.0.21"
__version__ = "0.0.22"
75 changes: 62 additions & 13 deletions pain001/xml/generate_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
# Import the XML libraries
import xml.etree.ElementTree as ET

# Import the datetime library
from datetime import datetime

# Import the functions from the other modules
from .create_xml_element import create_xml_element

Expand Down Expand Up @@ -63,11 +66,31 @@ def create_xml_v3(root, data, mapping):

# Add the MsgId, CreDtTm, and NbOfTxs elements to the GrpHdr element
for xml_tag, csv_column in mapping.items():
if xml_tag in ["MsgId", "CreDtTm", "NbOfTxs"]:
if xml_tag in ["MsgId"]:
create_xml_element(
GrpHdr_element, xml_tag, data[0][csv_column]
)

# Calculate CreDtTm
time_and_date_str = str(datetime.now())
CreDtTm_value = time_and_date_str[0:10] + "T" + time_and_date_str[11:19]
# Add CreDtTm Element in the XML tree
create_xml_element(GrpHdr_element, "CreDtTm", CreDtTm_value)

# Calculate NbOfTxs
NbOfTxs = 0
for row in data:
NbOfTxs = NbOfTxs + 1
# Add NbOfTxs to the XML tree
create_xml_element(GrpHdr_element, "NbOfTxs", str(NbOfTxs))

# Calculate CtrlSum Element from the CSV file
totalSum = 0
for row in data:
totalSum += float(row["payment_amount"])
# Add CtrlSum Element in the XML tree
create_xml_element(GrpHdr_element, "CtrlSum", str(round(totalSum, 2)))

# Create new "InitgPty" element in the XML tree using data from the
# CSV file
InitgPty_element = ET.Element("InitgPty")
Expand All @@ -80,7 +103,6 @@ def create_xml_v3(root, data, mapping):
# Create new "PmtInf" element in the XML tree using data from
# the CSV file
PmtInf_element = ET.Element("PmtInf")
cstmr_cdt_trf_initn_element.append(PmtInf_element)

create_common_elements(PmtInf_element, row, mapping)

Expand All @@ -92,13 +114,12 @@ def create_xml_v3(root, data, mapping):

# Create new "NbOfTxs" element in the XML tree using data from
# the Data file
create_xml_element(PmtInf_element, "NbOfTxs", row["nb_of_txs"])
# create_xml_element(PmtInf_element, "NbOfTxs", row["nb_of_txs"])

# Create new "CtrlSum" element in the XML tree using data from
# the Data file
create_xml_element(
PmtInf_element, "CtrlSum", f"{row['control_sum']}"
)
# create_xml_element(
# PmtInf_element, "CtrlSum", f"{row['control_sum']}")

# Create new "PmtTpInf" element in the XML tree using data from
# the Data file
Expand Down Expand Up @@ -134,7 +155,12 @@ def create_xml_v3(root, data, mapping):
# replace with the appropriate value
child_element2.text = row["debtor_account_IBAN"]
child_element.append(child_element2)
# Create CCy Element
CCy_element = ET.Element("Ccy")
CCy_element.text = row["currency"]
# Add Both Elements to Parents
DbtrAcct_element.append(child_element)
DbtrAcct_element.append(CCy_element)
PmtInf_element.append(DbtrAcct_element)

# Create new "DbtrAgt" element in the XML tree using data
Expand All @@ -148,22 +174,18 @@ def create_xml_v3(root, data, mapping):
DbtrAgt_element.append(child_element)
PmtInf_element.append(DbtrAgt_element)

# Create new "ChrgBr" element in the XML tree using data
# from the Data file
child_element = ET.Element("ChrgBr")
# replace with the appropriate value
child_element.text = row["charge_bearer"]
PmtInf_element.append(child_element)

# Create new "CdtTrfTxInf" element in the XML tree using data
# from the Data file
CdtTrfTxInf_element = ET.Element("CdtTrfTxInf")

# Create new "PmtId" element in the XML tree using data
# from the Data file
PmtId_element = ET.Element("PmtId")
InstrId_element = ET.Element("InstrId")
child_element = ET.Element("EndToEndId")
InstrId_element.text = row["payment_id"]
child_element.text = row["payment_id"]
PmtId_element.append(InstrId_element)
PmtId_element.append(child_element)
CdtTrfTxInf_element.append(PmtId_element)

Expand All @@ -176,6 +198,13 @@ def create_xml_v3(root, data, mapping):
Amt_element.append(child_element)
CdtTrfTxInf_element.append(Amt_element)

# Create new "ChrgBr" element in the XML tree using data
# from the Data file
ChrgBr_element = ET.Element("ChrgBr")
# replace with the appropriate value
ChrgBr_element.text = row["charge_bearer"]
PmtInf_element.append(ChrgBr_element)

# Create new "CdtrAgt" element in the XML tree using data
# from the Data file
CdtrAgt_element = ET.Element("CdtrAgt")
Expand All @@ -194,6 +223,16 @@ def create_xml_v3(root, data, mapping):
Cdtr_element.append(child_element)
CdtTrfTxInf_element.append(Cdtr_element)

# Create new "CdtrAcct" element in the XML tree using data
# from the CSV file
CdtrAcct_element = ET.Element("CdtrAcct")
Id_element = ET.Element("Id")
IBAN_element = ET.Element("IBAN")
IBAN_element.text = row["creditor_account_IBAN"]
Id_element.append(IBAN_element)
CdtrAcct_element.append(Id_element)
CdtTrfTxInf_element.append(CdtrAcct_element)

# Create new "RmtInf" element in the XML tree using data
# from the Data file
RmtInf_element = ET.Element("RmtInf")
Expand Down Expand Up @@ -476,6 +515,16 @@ def create_xml_v9(root, data, mapping):
Cdtr_element.append(child_element)
CdtTrfTxInf_element.append(Cdtr_element)

# Create new "CdtrAcct" element in the XML tree using data
# from the CSV file
CdtrAcct_element = ET.Element("CdtrAcct")
child_element = ET.Element("Id")
child_element2 = ET.Element("IBAN")
child_element2.text = row["creditor_agent_BIC"]
child_element.append(child_element2)
CdtrAcct_element.append(child_element)
CdtTrfTxInf_element.append(CdtrAcct_element)

# Create new "RmtInf" element in the XML tree using data
# from the Data file
RmtInf_element = ET.Element("RmtInf")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pain001"
version = "0.0.21"
version = "0.0.22"
description = "Pain001 is a Python Library for Automating ISO 20022-Compliant Payment Files Using CSV Data."
authors = ["Sebastien Rousseau <sebastian.rousseau@gmail.com>"]
license = "Apache Software License"
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

[metadata]
name = pain001
version = 0.0.21
version = 0.0.22
description = Pain001, A Python Library for Automating ISO 20022-Compliant Payment Files Using CSV Or SQlite Data Files.
keywords = pain001,iso20022,payment-processing,automate-payments,sepa,financial,banking-payments,csv,sqlite
author = Sebastian Rousseau
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

NAME = "pain001"
URL = "https://github.com/sebastienrousseau/pain001"
VERSION = "0.0.21"
VERSION = "0.0.22"

setup(
name=NAME,
Expand Down
1 change: 1 addition & 0 deletions tests/test_generate_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def setUp(self):
"currency": "EUR",
"creditor_agent_BIC": "NOLADE21KIE",
"creditor_name": "Creditor",
"creditor_account_IBAN": "DE26500700100096773701",
"remittance_information": "Invoice 123",
}
self.mapping = {
Expand Down

0 comments on commit 86a271f

Please sign in to comment.