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: more infos in narration
with this commit, the narration field is filled with infos find in the camt file such as reversal indicator, return reason, cheque number, ... before only a banking ref was present. The transaction type field is also filled.
This commit is contained in:
@@ -6,7 +6,7 @@ import re
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from odoo import models
|
||||
from odoo import _, models
|
||||
|
||||
|
||||
class CamtParser(models.AbstractModel):
|
||||
@@ -68,7 +68,103 @@ class CamtParser(models.AbstractModel):
|
||||
"payment_ref",
|
||||
join_str="\n",
|
||||
)
|
||||
# name
|
||||
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
["./ns:RmtInf/ns:Ustrd"],
|
||||
transaction["narration"],
|
||||
"%s (RmtInf/Ustrd)" % _("Unstructured Reference"),
|
||||
join_str=" ",
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
["./ns:RmtInf/ns:Strd/ns:CdtrRefInf/ns:Ref"],
|
||||
transaction["narration"],
|
||||
"%s (RmtInf/Strd/CdtrRefInf/Ref)" % _("Structured Reference"),
|
||||
join_str=" ",
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
["./ns:AddtlTxInf"],
|
||||
transaction["narration"],
|
||||
"%s (AddtlTxInf)" % _("Additional Transaction Information"),
|
||||
join_str=" ",
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
["./ns:RtrInf/ns:Rsn/ns:Cd"],
|
||||
transaction["narration"],
|
||||
"%s (RtrInf/Rsn/Cd)" % _("Return Reason Code"),
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
["./ns:RtrInf/ns:Rsn/ns:Cd"],
|
||||
transaction["narration"],
|
||||
"%s (RtrInf/Rsn/Prtry)" % _("Return Reason Code (Proprietary)"),
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
["./ns:RtrInf/ns:AddtlInf"],
|
||||
transaction["narration"],
|
||||
"%s (RtrInf/AddtlInf)" % _("Return Reason Additional Information"),
|
||||
join_str=" ",
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
["./ns:Refs/ns:MsgId"],
|
||||
transaction["narration"],
|
||||
"%s (Refs/MsgId)" % _("Msg Id"),
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
["./ns:Refs/ns:AcctSvcrRef"],
|
||||
transaction["narration"],
|
||||
"%s (Refs/AcctSvcrRef)" % _("Account Servicer Reference"),
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
["./ns:Refs/ns:EndToEndId"],
|
||||
transaction["narration"],
|
||||
"%s (Refs/EndToEndId)" % _("End To End Id"),
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
["./ns:Refs/ns:InstrId"],
|
||||
transaction["narration"],
|
||||
"%s (Refs/InstrId)" % _("Instructed Id"),
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
["./ns:Refs/ns:TxId"],
|
||||
transaction["narration"],
|
||||
"%s (Refs/TxId)" % _("Transaction Identification"),
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
["./ns:Refs/ns:MntId"],
|
||||
transaction["narration"],
|
||||
"%s (Refs/MntId)" % _("Mandate Id"),
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
["./ns:Refs/ns:ChqNb"],
|
||||
transaction["narration"],
|
||||
"%s (Refs/ChqNb)" % _("Cheque Number"),
|
||||
)
|
||||
|
||||
self.add_value_from_node(
|
||||
ns, node, ["./ns:AddtlTxInf"], transaction, "payment_ref", join_str="\n"
|
||||
)
|
||||
@@ -111,6 +207,24 @@ class CamtParser(models.AbstractModel):
|
||||
transaction,
|
||||
"partner_name",
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
party_node[0],
|
||||
"./ns:PstlAdr/ns:StrtNm|"
|
||||
"./ns:PstlAdr/ns:BldgNb|"
|
||||
"./ns:PstlAdr/ns:BldgNm|"
|
||||
"./ns:PstlAdr/ns:PstBx|"
|
||||
"./ns:PstlAdr/ns:PstCd|"
|
||||
"./ns:PstlAdr/ns:TwnNm|"
|
||||
"./ns:PstlAdr/ns:TwnLctnNm|"
|
||||
"./ns:PstlAdr/ns:DstrctNm|"
|
||||
"./ns:PstlAdr/ns:CtrySubDvsn|"
|
||||
"./ns:PstlAdr/ns:Ctry|"
|
||||
"./ns:PstlAdr/ns:AdrLine",
|
||||
transaction["narration"],
|
||||
"%s (PstlAdr)" % _("Postal Address"),
|
||||
join_str=" | ",
|
||||
)
|
||||
# Get remote_account from iban or from domestic account:
|
||||
account_node = node.xpath(
|
||||
"./ns:RltdPties/ns:%sAcct/ns:Id" % party_type, namespaces={"ns": ns}
|
||||
@@ -128,16 +242,37 @@ class CamtParser(models.AbstractModel):
|
||||
"account_number",
|
||||
)
|
||||
|
||||
def generate_narration(self, transaction):
|
||||
# this block ensure compatibility with v13
|
||||
transaction["narration"] = {
|
||||
"%s (RltdPties/Nm)"
|
||||
% _("Partner Name"): transaction.get("partner_name", ""),
|
||||
"%s (RltdPties/Acct)"
|
||||
% _("Partner Account Number"): transaction.get("partner_name", ""),
|
||||
"%s (BookgDt)" % _("Transaction Date"): transaction.get("date", ""),
|
||||
_("Reference"): transaction.get("ref", ""),
|
||||
_("Communication"): transaction.get("name", ""),
|
||||
"%s (BkTxCd)"
|
||||
% _("Transaction Type"): transaction.get("transaction_type", ""),
|
||||
**transaction["narration"],
|
||||
}
|
||||
|
||||
transaction["narration"] = "\n".join(
|
||||
["%s: %s" % (key, val) for key, val in transaction["narration"].items()]
|
||||
)
|
||||
|
||||
def parse_entry(self, ns, node):
|
||||
"""Parse an Ntry node and yield transactions"""
|
||||
transaction = {"payment_ref": "/", "amount": 0} # fallback defaults
|
||||
transaction = {
|
||||
"payment_ref": "/",
|
||||
"amount": 0,
|
||||
"narration": {},
|
||||
"transaction_type": {},
|
||||
} # 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, "narration"
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
@@ -150,14 +285,57 @@ class CamtParser(models.AbstractModel):
|
||||
"ref",
|
||||
)
|
||||
|
||||
# enrich the notes with some more infos when they are available
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
"./ns:AddtlNtryInf",
|
||||
transaction["narration"],
|
||||
"%s (AddtlNtryInf)" % _("Additional Entry Information"),
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
"./ns:RvslInd",
|
||||
transaction["narration"],
|
||||
"%s (RvslInd)" % _("Reversal Indicator"),
|
||||
)
|
||||
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
"./ns:BkTxCd/ns:Domn/ns:Cd",
|
||||
transaction["transaction_type"],
|
||||
"Code",
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
"./ns:BkTxCd/ns:Domn/ns:Fmly/ns:Cd",
|
||||
transaction["transaction_type"],
|
||||
"FmlyCd",
|
||||
)
|
||||
self.add_value_from_node(
|
||||
ns,
|
||||
node,
|
||||
"./ns:BkTxCd/ns:Domn/ns:Fmly/ns:SubFmlyCd",
|
||||
transaction["transaction_type"],
|
||||
"SubFmlyCd",
|
||||
)
|
||||
transaction["transaction_type"] = (
|
||||
"-".join(transaction["transaction_type"].values()) or ""
|
||||
)
|
||||
|
||||
details_nodes = node.xpath("./ns:NtryDtls/ns:TxDtls", namespaces={"ns": ns})
|
||||
if len(details_nodes) == 0:
|
||||
self.generate_narration(transaction)
|
||||
yield transaction
|
||||
return
|
||||
transaction_base = transaction
|
||||
for node in details_nodes:
|
||||
transaction = transaction_base.copy()
|
||||
self.parse_transaction_details(ns, node, transaction)
|
||||
self.generate_narration(transaction)
|
||||
yield transaction
|
||||
|
||||
def get_balance_amounts(self, ns, node):
|
||||
|
||||
Reference in New Issue
Block a user