Skip to content

Commit

Permalink
[MIG] account_statement_import_camt54: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sonhd91 authored and xaviedoanhduy committed Nov 7, 2024
1 parent 38a4afe commit 4812b2d
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 41 deletions.
10 changes: 6 additions & 4 deletions account_statement_import_camt54/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
-----------
Expand Down
2 changes: 1 addition & 1 deletion account_statement_import_camt54/__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).
{
"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)",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def migrate(cr, version):
cr.execute(
"""
UPDATE ir_config_parameter
SET key = 'qrr_partner_ref'
WHERE key = 'isr_partner_ref'
"""
)
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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"""
Expand Down
23 changes: 12 additions & 11 deletions account_statement_import_camt54/models/parser.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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(",")
Expand All @@ -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,"
Expand All @@ -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):
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions account_statement_import_camt54/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
- Digital4efficiency.ch
- The migration of this module from 16.0 to 17.0 was financially
supported by Camptocamp
10 changes: 5 additions & 5 deletions account_statement_import_camt54/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
10 changes: 6 additions & 4 deletions account_statement_import_camt54/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,11 @@ <h1 class="title">Bank Account Camt54 Import</h1>
configuration</p>
<div class="section" id="switzerland-localisation">
<h1>Switzerland localisation</h1>
<p>For ISR containing a partner reference, uses the config parameter key
isr_partner_ref. Doing so will fill the partners on bank statement lines
<p>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.</p>
<p>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
<p>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.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -431,6 +431,8 @@ <h1>Contributors</h1>
<h1>Other credits</h1>
<ul class="simple">
<li>Digital4efficiency.ch</li>
<li>The migration of this module from 16.0 to 17.0 was financially
supported by Camptocamp</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
18 changes: 9 additions & 9 deletions account_statement_import_camt54/tests/test_get_partner_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 4 additions & 6 deletions account_statement_import_camt54/tests/test_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 4812b2d

Please sign in to comment.