From 4812b2d508d8fc4cd9560bd3e3c7e0ae6c88a048 Mon Sep 17 00:00:00 2001
From: sonhd91
Date: Fri, 17 May 2024 15:23:47 +0700
Subject: [PATCH] [MIG] account_statement_import_camt54: Migration to 17.0
---
account_statement_import_camt54/README.rst | 10 ++++----
.../__manifest__.py | 2 +-
.../migrations/17.0.1.0.0/pre-migrate.py | 8 +++++++
.../models/account_statement_import.py | 3 ++-
.../models/parser.py | 23 ++++++++++---------
.../readme/CREDITS.md | 2 ++
.../readme/DESCRIPTION.md | 10 ++++----
.../static/description/index.html | 10 ++++----
.../tests/test_get_partner_ref.py | 18 +++++++--------
.../tests/test_statement.py | 10 ++++----
10 files changed, 55 insertions(+), 41 deletions(-)
create mode 100644 account_statement_import_camt54/migrations/17.0.1.0.0/pre-migrate.py
diff --git a/account_statement_import_camt54/README.rst b/account_statement_import_camt54/README.rst
index fe5bd6c86..2d6ae2cd2 100644
--- a/account_statement_import_camt54/README.rst
+++ b/account_statement_import_camt54/README.rst
@@ -50,12 +50,12 @@ configuration
Switzerland localisation
------------------------
-For ISR containing a partner reference, uses the config parameter key
-isr_partner_ref. Doing so will fill the partners on bank statement lines
+For QRR containing a partner reference, uses the config parameter key
+qrr_partner_ref. Doing so will fill the partners on bank statement lines
and speed up the matches in the reconciliation process.
-Value to set in isr_partner_ref defines the position of the partner
-reference inside the ISR. The format is i[,n] For instance 13,6 to start
+Value to set in qrr_partner_ref defines the position of the partner
+reference inside the QRR. The format is i[,n] For instance 13,6 to start
on position 13 with a 6 digit long reference. n is optional and it's
default value is 6.
@@ -92,6 +92,8 @@ Other credits
-------------
- Digital4efficiency.ch
+- The migration of this module from 16.0 to 17.0 was financially
+ supported by Camptocamp
Maintainers
-----------
diff --git a/account_statement_import_camt54/__manifest__.py b/account_statement_import_camt54/__manifest__.py
index a5d82d49c..187bff053 100644
--- a/account_statement_import_camt54/__manifest__.py
+++ b/account_statement_import_camt54/__manifest__.py
@@ -2,7 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Bank Account Camt54 Import",
- "version": "14.0.1.1.0",
+ "version": "17.0.1.0.0",
"category": "Account",
"website": "https://github.com/OCA/bank-statement-import",
"author": "camptocamp, " "Odoo Community Association (OCA)",
diff --git a/account_statement_import_camt54/migrations/17.0.1.0.0/pre-migrate.py b/account_statement_import_camt54/migrations/17.0.1.0.0/pre-migrate.py
new file mode 100644
index 000000000..e2f0f3e12
--- /dev/null
+++ b/account_statement_import_camt54/migrations/17.0.1.0.0/pre-migrate.py
@@ -0,0 +1,8 @@
+def migrate(cr, version):
+ cr.execute(
+ """
+ UPDATE ir_config_parameter
+ SET key = 'qrr_partner_ref'
+ WHERE key = 'isr_partner_ref'
+ """
+ )
diff --git a/account_statement_import_camt54/models/account_statement_import.py b/account_statement_import_camt54/models/account_statement_import.py
index 40b6dbf59..536345cbf 100644
--- a/account_statement_import_camt54/models/account_statement_import.py
+++ b/account_statement_import_camt54/models/account_statement_import.py
@@ -16,7 +16,7 @@ def _create_bank_statements(self, stmts_vals, result):
"""Create additional line in statement to set bank statement statement
to 0 balance"""
- super()._create_bank_statements(stmts_vals, result)
+ res = super()._create_bank_statements(stmts_vals, result)
statements = self.env["account.bank.statement"].browse(result["statement_ids"])
for statement in statements:
amount = sum(statement.line_ids.mapped("amount"))
@@ -34,6 +34,7 @@ def _create_bank_statements(self, stmts_vals, result):
statement.balance_end_real = statement.balance_start
else:
statement.balance_end_real = statement.balance_start + amount
+ return res
def _complete_stmts_vals(self, stmts_vals, journal, account_number):
"""Search partner from partner reference"""
diff --git a/account_statement_import_camt54/models/parser.py b/account_statement_import_camt54/models/parser.py
index a64072161..1e6e72cf3 100644
--- a/account_statement_import_camt54/models/parser.py
+++ b/account_statement_import_camt54/models/parser.py
@@ -1,7 +1,8 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo import _, exceptions, models
+from odoo import _, models
+from odoo.exceptions import UserError
class CamtParser(models.AbstractModel):
@@ -11,7 +12,7 @@ class CamtParser(models.AbstractModel):
def _get_partner_ref(self, isr):
ICP = self.env["ir.config_parameter"]
- ref_format = ICP.sudo().get_param("isr_partner_ref")
+ ref_format = ICP.sudo().get_param("qrr_partner_ref")
if not ref_format:
return
config = ref_format.split(",")
@@ -21,9 +22,9 @@ def _get_partner_ref(self, isr):
start = config[0]
size = 6
else:
- raise exceptions.UserError(
+ raise UserError(
_(
- "Config parameter `isr_partner_ref` is wrong.\n"
+ "Config parameter `qrr_partner_ref` is wrong.\n"
"It must be in format `i[,n]` \n"
"where `i` is the position of the first digit and\n"
"`n` the number of digit in the reference,"
@@ -36,14 +37,14 @@ def _get_partner_ref(self, isr):
size = int(size)
end = start + size
except ValueError:
- raise exceptions.UserError(
+ raise UserError(
_(
- "Config parameter `isr_partner_ref` is wrong.\n"
+ "Config parameter `qrr_partner_ref` is wrong.\n"
"It must be in format `i[,n]` \n"
"`i` and `n` must be integers.\n"
'e.g. "13,6"'
)
- )
+ ) from None
return isr[start:end].lstrip("0")
def parse_transaction_details(self, ns, node, transaction):
@@ -54,12 +55,12 @@ def parse_transaction_details(self, ns, node, transaction):
# put the esr in the label. odoo reconciles based on the label,
# if there is no esr it tries to use the information textfield
- isr_number = node.xpath(
+ qrr_number = node.xpath(
"./ns:RmtInf/ns:Strd/ns:CdtrRefInf/ns:Ref", namespaces={"ns": ns}
)
- if len(isr_number):
- transaction["payment_ref"] = isr_number[0].text
- partner_ref = self._get_partner_ref(isr_number[0].text)
+ if len(qrr_number):
+ transaction["payment_ref"] = qrr_number[0].text
+ partner_ref = self._get_partner_ref(qrr_number[0].text)
if partner_ref:
transaction["partner_ref"] = partner_ref
else:
diff --git a/account_statement_import_camt54/readme/CREDITS.md b/account_statement_import_camt54/readme/CREDITS.md
index 71b6051c3..24ea0b7eb 100644
--- a/account_statement_import_camt54/readme/CREDITS.md
+++ b/account_statement_import_camt54/readme/CREDITS.md
@@ -1 +1,3 @@
- Digital4efficiency.ch
+- The migration of this module from 16.0 to 17.0 was financially
+ supported by Camptocamp
diff --git a/account_statement_import_camt54/readme/DESCRIPTION.md b/account_statement_import_camt54/readme/DESCRIPTION.md
index 65be7ad18..3073dc446 100644
--- a/account_statement_import_camt54/readme/DESCRIPTION.md
+++ b/account_statement_import_camt54/readme/DESCRIPTION.md
@@ -19,11 +19,11 @@ configuration
## Switzerland localisation
-For ISR containing a partner reference, uses the config parameter key
-isr_partner_ref. Doing so will fill the partners on bank statement lines
+For QRR containing a partner reference, uses the config parameter key
+qrr_partner_ref. Doing so will fill the partners on bank statement lines
and speed up the matches in the reconciliation process.
-Value to set in isr_partner_ref defines the position of the partner
-reference inside the ISR. The format is i\[,n\] For instance 13,6 to
+Value to set in qrr_partner_ref defines the position of the partner
+reference inside the QRR. The format is i\[,n\] For instance 13,6 to
start on position 13 with a 6 digit long reference. n is optional and
-it's default value is 6.
+it's default value is 6.
\ No newline at end of file
diff --git a/account_statement_import_camt54/static/description/index.html b/account_statement_import_camt54/static/description/index.html
index b7daacf1a..aa1bd1647 100644
--- a/account_statement_import_camt54/static/description/index.html
+++ b/account_statement_import_camt54/static/description/index.html
@@ -388,11 +388,11 @@ Bank Account Camt54 Import
configuration
Switzerland localisation
-
For ISR containing a partner reference, uses the config parameter key
-isr_partner_ref. Doing so will fill the partners on bank statement lines
+
For QRR containing a partner reference, uses the config parameter key
+qrr_partner_ref. Doing so will fill the partners on bank statement lines
and speed up the matches in the reconciliation process.
-
Value to set in isr_partner_ref defines the position of the partner
-reference inside the ISR. The format is i[,n] For instance 13,6 to start
+
Value to set in qrr_partner_ref defines the position of the partner
+reference inside the QRR. The format is i[,n] For instance 13,6 to start
on position 13 with a 6 digit long reference. n is optional and it’s
default value is 6.
Table of contents
@@ -431,6 +431,8 @@
Contributors
Other credits
- Digital4efficiency.ch
+- The migration of this module from 16.0 to 17.0 was financially
+supported by Camptocamp
diff --git a/account_statement_import_camt54/tests/test_get_partner_ref.py b/account_statement_import_camt54/tests/test_get_partner_ref.py
index f42b039e8..ffa490d5c 100644
--- a/account_statement_import_camt54/tests/test_get_partner_ref.py
+++ b/account_statement_import_camt54/tests/test_get_partner_ref.py
@@ -17,49 +17,49 @@ def test_no_ICP(self):
self.assertFalse(partner_ref)
def test_ICP_empty(self):
- self.ICP.set_param("isr_partner_ref", "")
+ self.ICP.set_param("qrr_partner_ref", "")
ref = "11 11111 11111 11111 11111 11111".replace(" ", "")
partner_ref = self.Parser._get_partner_ref(ref)
self.assertFalse(partner_ref)
def test_ICP_no_len(self):
"""Test a default len of 6 is set if not provided"""
- self.ICP.set_param("isr_partner_ref", "12")
+ self.ICP.set_param("qrr_partner_ref", "12")
ref = "11 11111 11112 34567 11111 11111".replace(" ", "")
partner_ref = self.Parser._get_partner_ref(ref)
self.assertEqual(partner_ref, "234567")
def test_ICP_full(self):
"""Test full format of partner ref definition"""
- self.ICP.set_param("isr_partner_ref", "12,6")
+ self.ICP.set_param("qrr_partner_ref", "12,6")
ref = "11 11111 11112 34567 11111 11111".replace(" ", "")
partner_ref = self.Parser._get_partner_ref(ref)
self.assertEqual(partner_ref, "234567")
def test_zero_stripped(self):
"""Test full format of partner ref definition"""
- self.ICP.set_param("isr_partner_ref", "12,6")
+ self.ICP.set_param("qrr_partner_ref", "12,6")
ref = "11 11111 11110 00560 11111 11111".replace(" ", "")
partner_ref = self.Parser._get_partner_ref(ref)
self.assertEqual(partner_ref, "560")
def test_bad_ICP(self):
"""Test ir config parameter validation"""
- self.ICP.set_param("isr_partner_ref", "")
+ self.ICP.set_param("qrr_partner_ref", "")
ref = "11 11111 11111 11111 11111 11111".replace(" ", "")
- self.ICP.set_param("isr_partner_ref", "A")
+ self.ICP.set_param("qrr_partner_ref", "A")
with self.assertRaises(UserError):
self.Parser._get_partner_ref(ref)
- self.ICP.set_param("isr_partner_ref", "A,B")
+ self.ICP.set_param("qrr_partner_ref", "A,B")
with self.assertRaises(UserError):
self.Parser._get_partner_ref(ref)
- self.ICP.set_param("isr_partner_ref", "1,X")
+ self.ICP.set_param("qrr_partner_ref", "1,X")
with self.assertRaises(UserError):
self.Parser._get_partner_ref(ref)
- self.ICP.set_param("isr_partner_ref", "A,8")
+ self.ICP.set_param("qrr_partner_ref", "A,8")
with self.assertRaises(UserError):
self.Parser._get_partner_ref(ref)
diff --git a/account_statement_import_camt54/tests/test_statement.py b/account_statement_import_camt54/tests/test_statement.py
index aa59318f2..f457c419c 100644
--- a/account_statement_import_camt54/tests/test_statement.py
+++ b/account_statement_import_camt54/tests/test_statement.py
@@ -3,11 +3,11 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import base64
-from odoo.modules.module import get_module_resource
-from odoo.tests.common import SavepointCase
+from odoo.tests.common import TransactionCase
+from odoo.tools.misc import file_path
-class TestGenerateBankStatement(SavepointCase):
+class TestGenerateBankStatement(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
@@ -38,9 +38,7 @@ def setUpClass(cls):
)
def _load_statement(self):
- testfile = get_module_resource(
- "account_statement_import_camt", "test_files", "test-camt053"
- )
+ testfile = file_path("account_statement_import_camt/test_files/test-camt054")
with open(testfile, "rb") as datafile:
camt_file = base64.b64encode(datafile.read())
self.env["account.statement.import"].create(