From b6860791ee30f089f7520e67a4a5fe92874cef0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Duy=20=28=C4=90=E1=BB=97=20Anh=29?= Date: Thu, 7 Nov 2024 17:00:58 +0700 Subject: [PATCH] [MIG] account_statement_import_camt: Migration to 18.0 --- account_statement_import_camt/README.rst | 14 ++--- account_statement_import_camt/__manifest__.py | 2 +- .../models/account_journal.py | 3 +- .../models/account_statement_import.py | 2 +- .../account_statement_import_camt_parser.py | 47 +++++++++-------- .../readme/CONTRIBUTORS.md | 1 + .../readme/CREDITS.md | 1 + .../static/description/index.html | 49 ++++++++++-------- .../samples}/golden-camt053-no-ntry.pydata | 0 .../samples}/golden-camt053-txdtls.pydata | 0 .../samples}/golden-camt053.pydata | 0 .../samples}/golden-camt054.pydata | 0 .../samples}/test-camt053 | 0 .../samples}/test-camt053-no-ntry | 0 .../samples}/test-camt053-txdtls | 0 .../samples}/test-camt053.zip | Bin .../samples}/test-camt054 | 0 .../tests/test_import_bank_statement.py | 6 +-- 18 files changed, 69 insertions(+), 56 deletions(-) rename account_statement_import_camt/{test_files => tests/samples}/golden-camt053-no-ntry.pydata (100%) rename account_statement_import_camt/{test_files => tests/samples}/golden-camt053-txdtls.pydata (100%) rename account_statement_import_camt/{test_files => tests/samples}/golden-camt053.pydata (100%) rename account_statement_import_camt/{test_files => tests/samples}/golden-camt054.pydata (100%) rename account_statement_import_camt/{test_files => tests/samples}/test-camt053 (100%) rename account_statement_import_camt/{test_files => tests/samples}/test-camt053-no-ntry (100%) rename account_statement_import_camt/{test_files => tests/samples}/test-camt053-txdtls (100%) rename account_statement_import_camt/{test_files => tests/samples}/test-camt053.zip (100%) rename account_statement_import_camt/{test_files => tests/samples}/test-camt054 (100%) diff --git a/account_statement_import_camt/README.rst b/account_statement_import_camt/README.rst index cd66c79dc..608318734 100644 --- a/account_statement_import_camt/README.rst +++ b/account_statement_import_camt/README.rst @@ -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| @@ -41,7 +41,7 @@ Bug Tracker Bugs are tracked on `GitHub 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -71,12 +71,14 @@ Contributors - `Trobz `__: - Son Ho + - Do Anh Duy 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 ----------- @@ -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 `_ project on GitHub. +This module is part of the `OCA/bank-statement-import `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_statement_import_camt/__manifest__.py b/account_statement_import_camt/__manifest__.py index cf2187a49..3da1fcba8 100644 --- a/account_statement_import_camt/__manifest__.py +++ b/account_statement_import_camt/__manifest__.py @@ -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", diff --git a/account_statement_import_camt/models/account_journal.py b/account_statement_import_camt/models/account_journal.py index 86f7910e6..b8cf5e361 100644 --- a/account_statement_import_camt/models/account_journal.py +++ b/account_statement_import_camt/models/account_journal.py @@ -1,13 +1,14 @@ # Copyright 2019 ACSONE SA/NV # 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 diff --git a/account_statement_import_camt/models/account_statement_import.py b/account_statement_import_camt/models/account_statement_import.py index 289a71a8f..032934afe 100644 --- a/account_statement_import_camt/models/account_statement_import.py +++ b/account_statement_import_camt/models/account_statement_import.py @@ -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) diff --git a/account_statement_import_camt/models/account_statement_import_camt_parser.py b/account_statement_import_camt/models/account_statement_import_camt_parser.py index ab4276d4e..3dd4b284d 100644 --- a/account_statement_import_camt/models/account_statement_import_camt_parser.py +++ b/account_statement_import_camt/models/account_statement_import_camt_parser.py @@ -7,7 +7,7 @@ from lxml import etree -from odoo import _, models +from odoo import models class AccountStatementImportCamtParser(models.AbstractModel): @@ -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, @@ -75,7 +76,7 @@ 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( @@ -83,7 +84,7 @@ def parse_transaction_details(self, ns, node, transaction): 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( @@ -91,7 +92,7 @@ def parse_transaction_details(self, ns, node, transaction): node, ["./ns:AddtlTxInf"], transaction["narration"], - "%s (AddtlTxInf)" % _("Additional Transaction Information"), + f"{_('Additional Transaction Information')} (AddtlTxInf)", join_str=" ", ) self.add_value_from_node( @@ -99,21 +100,21 @@ def parse_transaction_details(self, ns, node, transaction): 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( @@ -121,49 +122,49 @@ def parse_transaction_details(self, ns, node, transaction): 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( @@ -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( @@ -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}) @@ -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", "" @@ -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, @@ -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( @@ -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: @@ -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.""" diff --git a/account_statement_import_camt/readme/CONTRIBUTORS.md b/account_statement_import_camt/readme/CONTRIBUTORS.md index 18ea84604..d6ecd9f8e 100644 --- a/account_statement_import_camt/readme/CONTRIBUTORS.md +++ b/account_statement_import_camt/readme/CONTRIBUTORS.md @@ -13,3 +13,4 @@ - [Trobz](https://trobz.com): > - Son Ho \<\> + > - Do Anh Duy \<\> diff --git a/account_statement_import_camt/readme/CREDITS.md b/account_statement_import_camt/readme/CREDITS.md index 291e14c81..2ccfbd22f 100644 --- a/account_statement_import_camt/readme/CREDITS.md +++ b/account_statement_import_camt/readme/CREDITS.md @@ -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 diff --git a/account_statement_import_camt/static/description/index.html b/account_statement_import_camt/static/description/index.html index 8c3f0ea36..b2d913194 100644 --- a/account_statement_import_camt/static/description/index.html +++ b/account_statement_import_camt/static/description/index.html @@ -2,18 +2,19 @@ - + CAMT Format Bank Statements Import