mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[17.0][MIG] account_statement_import_file: Migration to 17.0
This commit is contained in:
@@ -100,6 +100,7 @@ Contributors
|
||||
- Odoo S.A.
|
||||
- Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
- Tecnativa - Pedro M. Baeza
|
||||
- Sygel - Manuel Regidor
|
||||
|
||||
Maintainers
|
||||
-----------
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
{
|
||||
"name": "Import Statement Files",
|
||||
"category": "Accounting",
|
||||
"version": "16.0.1.0.2",
|
||||
"version": "17.0.1.0.0",
|
||||
"license": "LGPL-3",
|
||||
"depends": ["account_statement_import_base"],
|
||||
"author": "Odoo SA, Akretion, Odoo Community Association (OCA)",
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
Copyright 2022 Moduon Team <edu@moduon.team>
|
||||
Licence LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
|
||||
-->
|
||||
<odoo>
|
||||
<odoo noupdate="1">
|
||||
|
||||
<record id="ofx_partner_bank_1" model="res.partner.bank">
|
||||
<field name="acc_number">BE02631118262640</field>
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
# Copyright 2023 Landoo Sistemas de Informacion SL
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from openupgradelib import openupgrade
|
||||
|
||||
|
||||
@openupgrade.migrate()
|
||||
def migrate(env, version):
|
||||
openupgrade.logged_query(
|
||||
env.cr,
|
||||
"""
|
||||
UPDATE account_journal
|
||||
SET bank_statements_source = 'file_import_oca'
|
||||
WHERE bank_statements_source = 'file_import'
|
||||
""",
|
||||
)
|
||||
@@ -1,3 +1,4 @@
|
||||
- Odoo S.A.
|
||||
- Alexis de Lattre \<<alexis.delattre@akretion.com>\>
|
||||
- Tecnativa - Pedro M. Baeza
|
||||
- Sygel - Manuel Regidor
|
||||
|
||||
@@ -442,6 +442,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
|
||||
<li>Odoo S.A.</li>
|
||||
<li>Alexis de Lattre <<a class="reference external" href="mailto:alexis.delattre@akretion.com">alexis.delattre@akretion.com</a>></li>
|
||||
<li>Tecnativa - Pedro M. Baeza</li>
|
||||
<li>Sygel - Manuel Regidor</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
|
||||
4
account_statement_import_file/tests/__init__.py
Normal file
4
account_statement_import_file/tests/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# Copyright 2024 Sygel - Manuel Regidor
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
|
||||
from . import test_account_statement_import_file
|
||||
@@ -0,0 +1,148 @@
|
||||
# Copyright 2024 Sygel - Manuel Regidor
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
|
||||
import base64
|
||||
|
||||
import odoo.tests.common as common
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tools.misc import file_path
|
||||
|
||||
|
||||
class TestAccountStatementImportFile(common.TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.eur_currency = cls.env["res.currency"].search(
|
||||
[("name", "=", "EUR"), ("active", "=", False)], limit=1
|
||||
)
|
||||
cls.eur_currency.write({"active": True})
|
||||
cls.bank_account = cls.env["res.partner.bank"].create(
|
||||
{"acc_number": "1111111111", "partner_id": cls.env.company.partner_id.id}
|
||||
)
|
||||
cls.bank_account_2 = cls.env["res.partner.bank"].create(
|
||||
{"acc_number": "3333333333", "partner_id": cls.env.company.partner_id.id}
|
||||
)
|
||||
cls.journal_1 = cls.env["account.journal"].create(
|
||||
{
|
||||
"name": "Test asset journal-1",
|
||||
"code": "AST-1",
|
||||
"type": "bank",
|
||||
"bank_account_id": cls.bank_account.id,
|
||||
}
|
||||
)
|
||||
cls.journal_2 = cls.env["account.journal"].create(
|
||||
{
|
||||
"name": "Test asset journal-2",
|
||||
"code": "AST-2",
|
||||
"type": "bank",
|
||||
"bank_account_id": cls.bank_account.id,
|
||||
}
|
||||
)
|
||||
f_path = file_path("account_statement_import_file/tests/test_file.txt")
|
||||
file = base64.b64encode(open(f_path, "rb").read())
|
||||
cls.import_wizard = (
|
||||
cls.env["account.statement.import"]
|
||||
.with_context(journal_id=cls.journal_1.id)
|
||||
.create({"statement_file": file, "statement_filename": "Test"})
|
||||
)
|
||||
|
||||
def test_complete_stmts_vals(self):
|
||||
# ERROR: Missing payment_ref on a transaction.
|
||||
import_wizard = self.import_wizard
|
||||
stmts_vals = [{"transactions": [{"payment_ref": ""}]}]
|
||||
with self.assertRaises(UserError):
|
||||
import_wizard._complete_stmts_vals(stmts_vals, self.journal_1, "1111111111")
|
||||
|
||||
def test_match_journal(self):
|
||||
import_wizard = self.import_wizard
|
||||
|
||||
# ERROR: The format of this bank statement file doesn't "
|
||||
# contain the bank account number, so you must
|
||||
# start the wizard from the right bank journal
|
||||
# in the dashboard.
|
||||
with self.assertRaises(UserError):
|
||||
import_wizard.with_context(journal_id=False)._match_journal(
|
||||
False, self.eur_currency
|
||||
)
|
||||
|
||||
# ERROR: The journal found for the file (%(journal_match)s) is "
|
||||
# "different from the selected journal (%(journal_selected)s).
|
||||
with self.assertRaises(UserError):
|
||||
import_wizard.with_context(journal_id=self.journal_2.id)._match_journal(
|
||||
"1111111111", self.eur_currency
|
||||
)
|
||||
|
||||
# ERROR: The bank account with number '%(account_number)s' exists in Odoo
|
||||
# but it is not set on any bank journal. You should
|
||||
# set it on the related bank journal. If the related
|
||||
# bank journal doesn't exist yet, you should create
|
||||
# a new one.
|
||||
self.journal_1.write({"type": "general"})
|
||||
self.journal_2.write({"type": "general"})
|
||||
with self.assertRaises(UserError):
|
||||
import_wizard.with_context(journal_id=self.journal_2.id)._match_journal(
|
||||
"1111111111", self.eur_currency
|
||||
)
|
||||
|
||||
# ERROR: Could not find any bank account with number '%(account_number)s'
|
||||
# linked to partner '%(partner_name)s'. You should create the bank
|
||||
# account and set it on the related bank journal.
|
||||
# If the related bank journal doesn't exist yet, you
|
||||
# should create a new one."
|
||||
with self.assertRaises(UserError):
|
||||
import_wizard.with_context(journal_id=self.journal_2.id)._match_journal(
|
||||
"2222222222", self.eur_currency
|
||||
)
|
||||
|
||||
def test_import_single_statement(self):
|
||||
import_wizard = self.import_wizard
|
||||
# ERROR: The parsing of the statement file returned an invalid result.
|
||||
vals = [1, 1, {"val1: 1"}]
|
||||
result = {"statement_ids": [], "notifications": []}
|
||||
with self.assertRaises(UserError):
|
||||
import_wizard.import_single_statement(vals, result)
|
||||
|
||||
# ERROR: Missing currency code in the bank statement file.
|
||||
vals = (
|
||||
False,
|
||||
"2910907154",
|
||||
[
|
||||
{
|
||||
"transactions": [
|
||||
{
|
||||
"payment_ref": "PAYMENT REF",
|
||||
"ref": "REF",
|
||||
"amount": -1,
|
||||
"partner_name": "PARTNER",
|
||||
},
|
||||
],
|
||||
"balance_start": 10,
|
||||
"balance_end_real": 9,
|
||||
}
|
||||
],
|
||||
)
|
||||
with self.assertRaises(UserError):
|
||||
import_wizard.import_single_statement(vals, result)
|
||||
|
||||
# ERROR: The bank statement file uses currency '%s' but there is no
|
||||
# such currency in Odoo."
|
||||
vals = (
|
||||
"NOK",
|
||||
"2910907154",
|
||||
[
|
||||
{
|
||||
"transactions": [
|
||||
{
|
||||
"payment_ref": "PAYMENT REF",
|
||||
"ref": "REF",
|
||||
"amount": -1,
|
||||
"partner_name": "PARTNER",
|
||||
},
|
||||
],
|
||||
"balance_start": 10,
|
||||
"balance_end_real": 9,
|
||||
}
|
||||
],
|
||||
)
|
||||
with self.assertRaises(UserError):
|
||||
import_wizard.import_single_statement(vals, result)
|
||||
1
account_statement_import_file/tests/test_file.txt
Normal file
1
account_statement_import_file/tests/test_file.txt
Normal file
@@ -0,0 +1 @@
|
||||
TEST_STATEMENT_IMPORT
|
||||
@@ -12,7 +12,7 @@
|
||||
<field name="inherit_id" ref="account.account_journal_dashboard_kanban_view" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath
|
||||
expr='//a[@name="action_configure_bank_journal"]/..'
|
||||
expr='//button[@name="action_configure_bank_journal"]/..'
|
||||
position='before'
|
||||
>
|
||||
<t t-if="dashboard.bank_statements_source == 'file_import_oca'">
|
||||
|
||||
@@ -230,13 +230,13 @@ class AccountStatementImport(models.TransientModel):
|
||||
ctx_journal = journal_obj.browse(ctx_journal_id)
|
||||
raise UserError(
|
||||
_(
|
||||
"The journal found for the file (%(journal_match)s) is "
|
||||
"different from the selected journal (%(journal_selected)s).",
|
||||
"The journal found for the file (%(journal_match)s) is"
|
||||
" different from the selected journal "
|
||||
"(%(journal_selected)s).",
|
||||
journal_match=journal.display_name,
|
||||
journal_selected=ctx_journal.display_name,
|
||||
)
|
||||
)
|
||||
|
||||
if not journal:
|
||||
bank_accounts = self.env["res.partner.bank"].search(
|
||||
[
|
||||
@@ -248,22 +248,23 @@ class AccountStatementImport(models.TransientModel):
|
||||
if bank_accounts:
|
||||
raise UserError(
|
||||
_(
|
||||
"The bank account with number '%(account_number)s' exists in Odoo "
|
||||
"but it is not set on any bank journal. You should "
|
||||
"set it on the related bank journal. If the related "
|
||||
"bank journal doesn't exist yet, you should create "
|
||||
"a new one.",
|
||||
"The bank account with number '%(account_number)s'"
|
||||
" exists in Odoo but it is not set on any bank "
|
||||
"journal. You should set it on the related bank "
|
||||
"journal. If the related bank journal doesn't "
|
||||
" exist yet, you should create a new one.",
|
||||
account_number=account_number,
|
||||
)
|
||||
)
|
||||
else:
|
||||
raise UserError(
|
||||
_(
|
||||
"Could not find any bank account with number '%(account_number)s' "
|
||||
"linked to partner '%(partner_name)s'. You should create the bank "
|
||||
"Could not find any bank account with number "
|
||||
"'%(account_number)s' linked to partner '"
|
||||
"%(partner_name)s'. You should create the bank "
|
||||
"account and set it on the related bank journal. "
|
||||
"If the related bank journal doesn't exist yet, you "
|
||||
"should create a new one.",
|
||||
"If the related bank journal doesn't exist yet, "
|
||||
"you should create a new one.",
|
||||
account_number=account_number,
|
||||
partner_name=company.partner_id.display_name,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user