[MIG] account_bank_statement_import_qif: Migration to 16.0 and rename to account_statement_import_qif

TT46557
This commit is contained in:
Víctor Martínez
2024-04-04 09:00:51 +02:00
parent cc87171aad
commit 8866dd4b60
10 changed files with 50 additions and 44 deletions

View File

@@ -7,7 +7,7 @@ Import QIF Bank Statements
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:926bb5e821cd71d9a5bdaee546ce3b8f25a00825ff69c291da88820e8e53ae62 !! source digest: sha256:46da85f209ed418623ef45de4757c7ceb32bedf65df4d336d7f8a8473da6c1d0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -17,13 +17,13 @@ Import QIF Bank Statements
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github .. |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/13.0/account_bank_statement_import_qif :target: https://github.com/OCA/bank-statement-import/tree/16.0/account_statement_import_qif
:alt: OCA/bank-statement-import :alt: OCA/bank-statement-import
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/bank-statement-import-13-0/bank-statement-import-13-0-account_bank_statement_import_qif :target: https://translation.odoo-community.org/projects/bank-statement-import-16-0/bank-statement-import-16-0-account_statement_import_qif
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png .. |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=13.0 :target: https://runboat.odoo-community.org/builds?repo=OCA/bank-statement-import&target_branch=16.0
:alt: Try me on Runboat :alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@@ -64,7 +64,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/bank-statement-import/issues>`_. 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. 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 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_bank_statement_import_qif%0Aversion:%2013.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_qif%0Aversion:%2016.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. Do not contact contributors directly about support or help with technical issues.
@@ -107,6 +107,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/bank-statement-import <https://github.com/OCA/bank-statement-import/tree/13.0/account_bank_statement_import_qif>`_ project on GitHub. This module is part of the `OCA/bank-statement-import <https://github.com/OCA/bank-statement-import/tree/16.0/account_statement_import_qif>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -7,11 +7,11 @@
{ {
"name": "Import QIF Bank Statements", "name": "Import QIF Bank Statements",
"category": "Accounting", "category": "Accounting",
"version": "13.0.1.0.0", "version": "16.0.1.0.0",
"author": "OpenERP SA," "Tecnativa," "Odoo Community Association (OCA)", "author": "OpenERP SA," "Tecnativa," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/bank-statement-import", "website": "https://github.com/OCA/bank-statement-import",
"depends": ["account_bank_statement_import"], "depends": ["account_statement_import_file"],
"data": ["wizards/account_bank_statement_import_qif_view.xml"], "data": ["wizards/account_statement_import_qif_view.xml"],
"installable": True, "installable": True,
"license": "AGPL-3", "license": "AGPL-3",
} }

View File

@@ -367,9 +367,9 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:926bb5e821cd71d9a5bdaee546ce3b8f25a00825ff69c291da88820e8e53ae62 !! source digest: sha256:46da85f209ed418623ef45de4757c7ceb32bedf65df4d336d7f8a8473da6c1d0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/bank-statement-import/tree/13.0/account_bank_statement_import_qif"><img alt="OCA/bank-statement-import" src="https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/bank-statement-import-13-0/bank-statement-import-13-0-account_bank_statement_import_qif"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/bank-statement-import&amp;target_branch=13.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p> <p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/bank-statement-import/tree/16.0/account_statement_import_qif"><img alt="OCA/bank-statement-import" src="https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/bank-statement-import-16-0/bank-statement-import-16-0-account_statement_import_qif"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/bank-statement-import&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows you to import the machine readable QIF Files in Odoo: they <p>This module allows you to import the machine readable QIF Files in Odoo: they
are parsed and stored in human readable format in are parsed and stored in human readable format in
Accounting Bank and Cash Bank Statements.</p> Accounting Bank and Cash Bank Statements.</p>
@@ -405,7 +405,7 @@ original AGPL code.</p>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/bank-statement-import/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/bank-statement-import/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_bank_statement_import_qif%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_statement_import_qif%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@@ -448,7 +448,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/bank-statement-import/tree/13.0/account_bank_statement_import_qif">OCA/bank-statement-import</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/bank-statement-import/tree/16.0/account_statement_import_qif">OCA/bank-statement-import</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View File

@@ -2,6 +2,7 @@
# Copyright 2015 Laurent Mignon <laurent.mignon@acsone.eu> # Copyright 2015 Laurent Mignon <laurent.mignon@acsone.eu>
# Copyright 2015 Ronald Portier <rportier@therp.nl> # Copyright 2015 Ronald Portier <rportier@therp.nl>
# Copyright 2016-2017 Tecnativa - Pedro M. Baeza # Copyright 2016-2017 Tecnativa - Pedro M. Baeza
# Copyright 2024 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import base64 import base64
@@ -15,14 +16,20 @@ class TestQifFile(TransactionCase):
(account.bank.statement.import) (account.bank.statement.import)
""" """
def setUp(self): @classmethod
super().setUp() def setUpClass(cls):
self.statement_import_model = self.env["account.bank.statement.import"] super().setUpClass()
self.statement_line_model = self.env["account.bank.statement.line"] cls.statement_import_model = cls.env["account.statement.import"]
self.journal = self.env["account.journal"].create( cls.statement_line_model = cls.env["account.bank.statement.line"]
{"name": "Test bank journal", "code": "TEST", "type": "bank"} cls.journal = cls.env["account.journal"].create(
{
"name": "Test bank journal",
"code": "TEST",
"type": "bank",
"currency_id": cls.env.company.currency_id.id,
}
) )
self.partner = self.env["res.partner"].create( cls.partner = cls.env["res.partner"].create(
{ {
# Different case for trying insensitive case search # Different case for trying insensitive case search
"name": "EPIC Technologies", "name": "EPIC Technologies",
@@ -31,22 +38,22 @@ class TestQifFile(TransactionCase):
def test_qif_file_import(self): def test_qif_file_import(self):
qif_file_path = get_module_resource( qif_file_path = get_module_resource(
"account_bank_statement_import_qif", "account_statement_import_qif",
"tests", "tests",
"test_qif.qif", "test_qif.qif",
) )
qif_file = base64.b64encode(open(qif_file_path, "rb").read()) qif_file = base64.b64encode(open(qif_file_path, "rb").read())
wizard = self.statement_import_model.with_context( wizard = self.statement_import_model.with_context(
journal_id=self.journal.id journal_id=self.journal.id
).create({"attachment_ids": [(0, 0, {"name": "test file", "datas": qif_file})]}) ).create({"statement_file": qif_file, "statement_filename": "test_qif.qif"})
wizard.import_file() wizard.import_file_button()
statement = self.statement_line_model.search( statement = self.statement_line_model.search(
[("name", "=", "YOUR LOCAL SUPERMARKET")], [("payment_ref", "=", "YOUR LOCAL SUPERMARKET")],
limit=1, limit=1,
)[0].statement_id ).statement_id
self.assertAlmostEqual(statement.balance_end_real, -1896.09, 2) self.assertAlmostEqual(statement.balance_end_real, -1896.09, 2)
line = self.statement_line_model.search( line = self.statement_line_model.search(
[("name", "=", "Epic Technologies")], [("payment_ref", "=", "Epic Technologies")],
limit=1, limit=1,
) )
self.assertEqual(line.partner_id, self.partner) self.assertEqual(line.partner_id, self.partner)

View File

@@ -1,3 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import account_bank_statement_import_qif from . import account_statement_import_qif

View File

@@ -13,8 +13,8 @@ from odoo.exceptions import UserError
from odoo.tools.translate import _ from odoo.tools.translate import _
class AccountBankStatementImport(models.TransientModel): class AccountStatementImport(models.TransientModel):
_inherit = "account.bank.statement.import" _inherit = "account.statement.import"
@api.model @api.model
def _check_qif(self, data_file): def _check_qif(self, data_file):
@@ -31,8 +31,8 @@ class AccountBankStatementImport(models.TransientModel):
data_list = file_data.split("\n") data_list = file_data.split("\n")
header = data_list[0].strip() header = data_list[0].strip()
header = header.split(":")[1] header = header.split(":")[1]
except Exception: except Exception as e:
raise UserError(_("Could not decipher the QIF file.")) raise UserError(_("Could not decipher the QIF file.")) from e
transactions = [] transactions = []
vals_line = {} vals_line = {}
total = 0 total = 0
@@ -52,13 +52,13 @@ class AccountBankStatementImport(models.TransientModel):
elif line[0] == "N": # Check number elif line[0] == "N": # Check number
vals_line["ref"] = line[1:] vals_line["ref"] = line[1:]
elif line[0] == "P": # Payee elif line[0] == "P": # Payee
vals_line["name"] = ( vals_line["payment_ref"] = (
"name" in vals_line "name" in vals_line
and line[1:] + ": " + vals_line["name"] and line[1:] + ": " + vals_line["name"]
or line[1:] or line[1:]
) )
elif line[0] == "M": # Memo elif line[0] == "M": # Memo
vals_line["name"] = ( vals_line["payment_ref"] = (
"name" in vals_line "name" in vals_line
and vals_line["name"] + ": " + line[1:] and vals_line["name"] + ": " + line[1:]
or line[1:] or line[1:]
@@ -80,7 +80,8 @@ class AccountBankStatementImport(models.TransientModel):
vals_bank_statement.update( vals_bank_statement.update(
{"balance_end_real": total, "transactions": transactions} {"balance_end_real": total, "transactions": transactions}
) )
return None, None, [vals_bank_statement] journal = self.env["account.journal"].browse(self.env.context.get("journal_id"))
return journal.currency_id.name, None, [vals_bank_statement]
def _complete_stmts_vals(self, stmt_vals, journal_id, account_number): def _complete_stmts_vals(self, stmt_vals, journal_id, account_number):
"""Match partner_id if hasn't been deducted yet.""" """Match partner_id if hasn't been deducted yet."""
@@ -88,16 +89,16 @@ class AccountBankStatementImport(models.TransientModel):
# Since QIF doesn't provide account numbers (normal behaviour is to # Since QIF doesn't provide account numbers (normal behaviour is to
# provide 'account_number', which the generic module uses to find # provide 'account_number', which the generic module uses to find
# the partner), we have to find res.partner through the name # the partner), we have to find res.partner through the name
if not self.attachment_ids or not self._check_qif( if not self.statement_file or not self._check_qif(
base64.b64decode(self.attachment_ids[0].datas) base64.b64decode(self.statement_file)
): ):
return res return res
partner_obj = self.env["res.partner"] partner_obj = self.env["res.partner"]
for statement in res: for statement in res:
for line_vals in statement["transactions"]: for line_vals in statement["transactions"]:
if not line_vals.get("partner_id") and line_vals.get("name"): if not line_vals.get("partner_id") and line_vals.get("payment_ref"):
partner = partner_obj.search( partner = partner_obj.search(
[("name", "ilike", line_vals["name"])], [("name", "ilike", line_vals["payment_ref"])],
limit=1, limit=1,
) )
line_vals["partner_id"] = partner.id line_vals["partner_id"] = partner.id

View File

@@ -1,11 +1,10 @@
<?xml version="1.0" ?> <?xml version="1.0" ?>
<odoo> <odoo>
<record id="account_statement_import_form" model="ir.ui.view">
<record id="account_bank_statement_import_view" model="ir.ui.view"> <field name="model">account.statement.import</field>
<field name="model">account.bank.statement.import</field>
<field <field
name="inherit_id" name="inherit_id"
ref="account_bank_statement_import.account_bank_statement_import_view" ref="account_statement_import_file.account_statement_import_form"
/> />
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//ul[@id='statement_format']" position="inside"> <xpath expr="//ul[@id='statement_format']" position="inside">
@@ -13,5 +12,4 @@
</xpath> </xpath>
</field> </field>
</record> </record>
</odoo> </odoo>

View File

@@ -1 +0,0 @@
../../../../account_bank_statement_import_qif

View File

@@ -0,0 +1 @@
../../../../account_statement_import_qif