Skip to content

Commit

Permalink
[MIG] account_statement_import_camt: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviedoanhduy committed Nov 7, 2024
1 parent 8101dab commit fc18bcc
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 53 deletions.
14 changes: 8 additions & 6 deletions account_statement_import_camt/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ CAMT Format Bank Statements Import
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github
:target: https://github.com/OCA/bank-statement-import/tree/17.0/account_statement_import_camt
:target: https://github.com/OCA/bank-statement-import/tree/18.0/account_statement_import_camt
:alt: OCA/bank-statement-import
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/bank-statement-import-17-0/bank-statement-import-17-0-account_statement_import_camt
:target: https://translation.odoo-community.org/projects/bank-statement-import-18-0/bank-statement-import-18-0-account_statement_import_camt
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/bank-statement-import&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/bank-statement-import&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -41,7 +41,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/bank-statement-import/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_statement_import_camt%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_statement_import_camt%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -71,12 +71,14 @@ Contributors
- `Trobz <https://trobz.com>`__:

- Son Ho <[email protected]>
- Do Anh Duy <[email protected]>

Other credits
-------------

The migration of this module from 15.0 to 16.0 was financially supported
by Camptocamp
by Camptocamp The migration of this module from 17.0 to 18.0 was
financially supported by Camptocamp

Maintainers
-----------
Expand All @@ -91,6 +93,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/bank-statement-import <https://github.com/OCA/bank-statement-import/tree/17.0/account_statement_import_camt>`_ project on GitHub.
This module is part of the `OCA/bank-statement-import <https://github.com/OCA/bank-statement-import/tree/18.0/account_statement_import_camt>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion account_statement_import_camt/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "CAMT Format Bank Statements Import",
"version": "17.0.1.0.0",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "Therp BV, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/bank-statement-import",
Expand Down
3 changes: 2 additions & 1 deletion account_statement_import_camt/models/account_journal.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Copyright 2019 ACSONE SA/NV <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, models
from odoo import models


class AccountJournal(models.Model):
_inherit = "account.journal"

def _get_bank_statements_available_import_formats(self):
_ = self.env._
res = super()._get_bank_statements_available_import_formats()
res.extend([_("camt.053.001.02"), _("camt.054.001.02")])
return res
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _parse_file(self, data_file):
return currency, account_number, transactions
# pylint: disable=except-pass
except (zipfile.BadZipFile, ValueError):
pass
_logger.exception("BadZipfile exception")
# Not a camt file, returning super will call next candidate:
_logger.debug("Statement file was not a camt file.", exc_info=True)
return super()._parse_file(data_file)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from lxml import etree

from odoo import _, models
from odoo import models


class AccountStatementImportCamtParser(models.AbstractModel):
Expand Down Expand Up @@ -56,6 +56,7 @@ def add_value_from_node(self, ns, node, xpath_str, obj, attr_name, join_str=None

def parse_transaction_details(self, ns, node, transaction):
"""Parse TxDtls node."""
_ = self.env._
# message
self.add_value_from_node(
ns,
Expand All @@ -75,95 +76,95 @@ def parse_transaction_details(self, ns, node, transaction):
node,
["./ns:RmtInf/ns:Ustrd"],
transaction["narration"],
"%s (RmtInf/Ustrd)" % _("Unstructured Reference"),
f"{_('Unstructured Reference')} (RmtInf/Ustrd)",
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"),
f"{_('Structured Reference')} (RmtInf/Strd/CdtrRefInf/Ref)",
join_str=" ",
)
self.add_value_from_node(
ns,
node,
["./ns:AddtlTxInf"],
transaction["narration"],
"%s (AddtlTxInf)" % _("Additional Transaction Information"),
f"{_('Additional Transaction Information')} (AddtlTxInf)",
join_str=" ",
)
self.add_value_from_node(
ns,
node,
["./ns:RtrInf/ns:Rsn/ns:Cd"],
transaction["narration"],
"%s (RtrInf/Rsn/Cd)" % _("Return Reason Code"),
f"{_('Return Reason Code')} (RtrInf/Rsn/Cd)",
)
self.add_value_from_node(
ns,
node,
["./ns:RtrInf/ns:Rsn/ns:Cd"],
transaction["narration"],
"%s (RtrInf/Rsn/Prtry)" % _("Return Reason Code (Proprietary)"),
f"{_('Return Reason Code (Proprietary)')} (RtrInf/Rsn/Prtry)",
)
self.add_value_from_node(
ns,
node,
["./ns:RtrInf/ns:AddtlInf"],
transaction["narration"],
"%s (RtrInf/AddtlInf)" % _("Return Reason Additional Information"),
f"{_('Return Reason Additional Information')} (RtrInf/AddtlInf)",
join_str=" ",
)
self.add_value_from_node(
ns,
node,
["./ns:Refs/ns:MsgId"],
transaction["narration"],
"%s (Refs/MsgId)" % _("Msg Id"),
f"{_('Msg Id')} (Refs/MsgId)",
)
self.add_value_from_node(
ns,
node,
["./ns:Refs/ns:AcctSvcrRef"],
transaction["narration"],
"%s (Refs/AcctSvcrRef)" % _("Account Servicer Reference"),
f"{_('Account Servicer Reference')} (Refs/AcctSvcrRef)",
)
self.add_value_from_node(
ns,
node,
["./ns:Refs/ns:EndToEndId"],
transaction["narration"],
"%s (Refs/EndToEndId)" % _("End To End Id"),
f"{_('End To End Id')} (Refs/EndToEndId)",
)
self.add_value_from_node(
ns,
node,
["./ns:Refs/ns:InstrId"],
transaction["narration"],
"%s (Refs/InstrId)" % _("Instructed Id"),
f"{_('Instructed Id')} (Refs/InstrId)",
)
self.add_value_from_node(
ns,
node,
["./ns:Refs/ns:TxId"],
transaction["narration"],
"%s (Refs/TxId)" % _("Transaction Identification"),
f"{_('Transaction Identification')} (Refs/TxId)",
)
self.add_value_from_node(
ns,
node,
["./ns:Refs/ns:MntId"],
transaction["narration"],
"%s (Refs/MntId)" % _("Mandate Id"),
f"{_('Mandate Id')} (Refs/MntId)",
)
self.add_value_from_node(
ns,
node,
["./ns:Refs/ns:ChqNb"],
transaction["narration"],
"%s (Refs/ChqNb)" % _("Cheque Number"),
f"{_('Cheque Number')} (Refs/ChqNb)",
)

self.add_value_from_node(
Expand All @@ -190,7 +191,7 @@ def parse_transaction_details(self, ns, node, transaction):
if party_type_node and party_type_node[0].text != "CRDT":
party_type = "Cdtr"
party_node = node.xpath(
"./ns:RltdPties/ns:%s" % party_type, namespaces={"ns": ns}
f"./ns:RltdPties/ns:{party_type}", namespaces={"ns": ns}
)
if party_node:
name_node = node.xpath(
Expand Down Expand Up @@ -223,12 +224,12 @@ def parse_transaction_details(self, ns, node, transaction):
"./ns:PstlAdr/ns:Ctry|"
"./ns:PstlAdr/ns:AdrLine",
transaction["narration"],
"%s (PstlAdr)" % _("Postal Address"),
f"{_('Postal Address')} (PstlAdr)",
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}
f"./ns:RltdPties/ns:{party_type}Acct/ns:Id", namespaces={"ns": ns}
)
if account_node:
iban_node = account_node[0].xpath("./ns:IBAN", namespaces={"ns": ns})
Expand All @@ -245,6 +246,7 @@ def parse_transaction_details(self, ns, node, transaction):

def generate_narration(self, transaction):
# this block ensure compatibility with v13
_ = self.env._
transaction["narration"] = {
"{} (RltdPties/Nm)".format(_("Partner Name")): transaction.get(
"partner_name", ""
Expand All @@ -267,6 +269,7 @@ def generate_narration(self, transaction):

def parse_entry(self, ns, node):
"""Parse an Ntry node and yield transactions"""
_ = self.env._
transaction = {
"payment_ref": "/",
"amount": 0,
Expand Down Expand Up @@ -295,14 +298,14 @@ def parse_entry(self, ns, node):
node,
"./ns:AddtlNtryInf",
transaction["narration"],
"%s (AddtlNtryInf)" % _("Additional Entry Information"),
f"{_('Additional Entry Information')} (AddtlNtryInf)",
)
self.add_value_from_node(
ns,
node,
"./ns:RvslInd",
transaction["narration"],
"%s (RvslInd)" % _("Reversal Indicator"),
f"{_('Reversal Indicator')} (RvslInd)",
)

self.add_value_from_node(
Expand Down Expand Up @@ -356,7 +359,7 @@ def get_balance_amounts(self, ns, node):
end_balance_node = None
for node_name in ["OPBD", "PRCD", "CLBD", "ITBD"]:
code_expr = (
'./ns:Bal/ns:Tp/ns:CdOrPrtry/ns:Cd[text()="%s"]/../../..' % node_name
f'./ns:Bal/ns:Tp/ns:CdOrPrtry/ns:Cd[text()="{node_name}"]/../../..'
)
balance_node = node.xpath(code_expr, namespaces={"ns": ns})
if balance_node:
Expand Down Expand Up @@ -427,11 +430,11 @@ def check_version(self, ns, root):
r"|^ISO:camt.052.)"
)
if not re_camt_version.search(ns):
raise ValueError("no camt 052 or 053 or 054: " + ns)
raise ValueError("no camt 052 or 053 or 054:", ns)
# Check GrpHdr element:
root_0_0 = root[0][0].tag[len(ns) + 2 :] # strip namespace
if root_0_0 != "GrpHdr":
raise ValueError("expected GrpHdr, got: " + root_0_0)
raise ValueError("expected GrpHdr, got:", root_0_0)

def parse(self, data):
"""Parse a camt.052 or camt.053 or camt.054 file."""
Expand Down
1 change: 1 addition & 0 deletions account_statement_import_camt/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
- [Trobz](https://trobz.com):

> - Son Ho \<<[email protected]>\>
> - Do Anh Duy \<<[email protected]>\>
1 change: 1 addition & 0 deletions account_statement_import_camt/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
The migration of this module from 15.0 to 16.0 was financially supported
by Camptocamp
The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp
Loading

0 comments on commit fc18bcc

Please sign in to comment.