From 3bcd2df330cdccf0acd7e07d2d89235d01f5d22f Mon Sep 17 00:00:00 2001 From: Abraham Anes Date: Fri, 16 Oct 2020 09:31:45 +0200 Subject: [PATCH] [MIG] account_bank_statement_import_qif: Migration to 13.0 TT26069 --- account_bank_statement_import_qif/README.rst | 77 ++- .../__manifest__.py | 2 +- .../models/account_journal.py | 8 +- .../readme/CONTRIBUTORS.rst | 13 + .../readme/DESCRIPTION.rst | 14 + .../readme/USAGE.rst | 6 + .../static/description/index.html | 454 ++++++++++++++++++ .../tests/test_import_bank_statement.py | 6 +- .../account_bank_statement_import_qif.py | 14 +- 9 files changed, 558 insertions(+), 36 deletions(-) create mode 100644 account_bank_statement_import_qif/readme/CONTRIBUTORS.rst create mode 100644 account_bank_statement_import_qif/readme/DESCRIPTION.rst create mode 100644 account_bank_statement_import_qif/readme/USAGE.rst create mode 100644 account_bank_statement_import_qif/static/description/index.html diff --git a/account_bank_statement_import_qif/README.rst b/account_bank_statement_import_qif/README.rst index f971f706..37c6a3cf 100644 --- a/account_bank_statement_import_qif/README.rst +++ b/account_bank_statement_import_qif/README.rst @@ -1,17 +1,36 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html - :alt: License: AGPL-3 +========================== +Import QIF Bank Statements +========================== -========================== -Import QIF bank statements -========================== +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :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/13.0/account_bank_statement_import_qif + :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-13-0/bank-statement-import-13-0-account_bank_statement_import_qif + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/174/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| This module allows you to import the machine readable QIF Files in Odoo: they are parsed and stored in human readable format in Accounting \ Bank and Cash \ Bank Statements. Important Note --------------- +~~~~~~~~~~~~~~ Because of the QIF format limitation, we cannot ensure the same transactions aren't imported several times or handle multicurrency. Whenever possible, you should use a more appropriate file format like OFX. @@ -21,6 +40,11 @@ by Odoo for V9 at its early stage. As Odoo has relicensed this module as private inside its Odoo enterprise layer, now this one is maintained from the original AGPL code. +**Table of contents** + +.. contents:: + :local: + Usage ===== @@ -31,46 +55,55 @@ To use this module, you need to: #. Select a QIF file. #. Press *Import*. -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/174/11.0 - Bug Tracker =========== -Bugs are tracked on -`GitHub Issues `_. +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 smashing it by providing a detailed and -welcomed feedback. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. Credits ======= +Authors +~~~~~~~ + +* OpenERP SA +* Tecnativa + Contributors ------------- +~~~~~~~~~~~~ * Odoo SA * Akretion + * Alexis de Lattre * ACSONE A/V + * Laurent Mignon * Therp + * Ronald Portier * Tecnativa (https://www.tecnativa.com) - * Pedro M. Baeza -Maintainer ----------- + * Pedro M. Baeza + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association :target: https://odoo-community.org -This module is maintained by the OCA. - 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. -To contribute to this module, please visit https://odoo-community.org. +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_bank_statement_import_qif/__manifest__.py b/account_bank_statement_import_qif/__manifest__.py index 30c786e1..7f61a54c 100644 --- a/account_bank_statement_import_qif/__manifest__.py +++ b/account_bank_statement_import_qif/__manifest__.py @@ -7,7 +7,7 @@ { "name": "Import QIF Bank Statements", "category": "Accounting", - "version": "12.0.1.0.0", + "version": "13.0.1.0.0", "author": "OpenERP SA," "Tecnativa," "Odoo Community Association (OCA)", "website": "https://github.com/OCA/bank-statement-import", "depends": ["account_bank_statement_import"], diff --git a/account_bank_statement_import_qif/models/account_journal.py b/account_bank_statement_import_qif/models/account_journal.py index 2d5cbb62..f4893820 100644 --- a/account_bank_statement_import_qif/models/account_journal.py +++ b/account_bank_statement_import_qif/models/account_journal.py @@ -1,14 +1,12 @@ # 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): - res = super( - AccountJournal, self - )._get_bank_statements_available_import_formats() - res.extend([_(".qif")]) + res = super()._get_bank_statements_available_import_formats() + res.append("qif") return res diff --git a/account_bank_statement_import_qif/readme/CONTRIBUTORS.rst b/account_bank_statement_import_qif/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..f6e06768 --- /dev/null +++ b/account_bank_statement_import_qif/readme/CONTRIBUTORS.rst @@ -0,0 +1,13 @@ +* Odoo SA +* Akretion + + * Alexis de Lattre +* ACSONE A/V + + * Laurent Mignon +* Therp + + * Ronald Portier +* Tecnativa (https://www.tecnativa.com) + + * Pedro M. Baeza diff --git a/account_bank_statement_import_qif/readme/DESCRIPTION.rst b/account_bank_statement_import_qif/readme/DESCRIPTION.rst new file mode 100644 index 00000000..6aa52010 --- /dev/null +++ b/account_bank_statement_import_qif/readme/DESCRIPTION.rst @@ -0,0 +1,14 @@ +This module allows you to import the machine readable QIF Files in Odoo: they +are parsed and stored in human readable format in +Accounting \ Bank and Cash \ Bank Statements. + +Important Note +~~~~~~~~~~~~~~ +Because of the QIF format limitation, we cannot ensure the same transactions +aren't imported several times or handle multicurrency. Whenever possible, you +should use a more appropriate file format like OFX. + +The module was initiated as a backport of the new framework developed +by Odoo for V9 at its early stage. As Odoo has relicensed this module as +private inside its Odoo enterprise layer, now this one is maintained from the +original AGPL code. diff --git a/account_bank_statement_import_qif/readme/USAGE.rst b/account_bank_statement_import_qif/readme/USAGE.rst new file mode 100644 index 00000000..15f6f8fd --- /dev/null +++ b/account_bank_statement_import_qif/readme/USAGE.rst @@ -0,0 +1,6 @@ +To use this module, you need to: + +#. Go to *Invoicing / Accounting* dashboard. +#. Click on *Import statement* from any of the bank journals. +#. Select a QIF file. +#. Press *Import*. diff --git a/account_bank_statement_import_qif/static/description/index.html b/account_bank_statement_import_qif/static/description/index.html new file mode 100644 index 00000000..13bb5e61 --- /dev/null +++ b/account_bank_statement_import_qif/static/description/index.html @@ -0,0 +1,454 @@ + + + + + + +Import QIF Bank Statements + + + +
+

Import QIF Bank Statements

+ + +

Beta License: AGPL-3 OCA/bank-statement-import Translate me on Weblate Try me on Runbot

+

This module allows you to import the machine readable QIF Files in Odoo: they +are parsed and stored in human readable format in +Accounting Bank and Cash Bank Statements.

+
+

Important Note

+

Because of the QIF format limitation, we cannot ensure the same transactions +aren’t imported several times or handle multicurrency. Whenever possible, you +should use a more appropriate file format like OFX.

+

The module was initiated as a backport of the new framework developed +by Odoo for V9 at its early stage. As Odoo has relicensed this module as +private inside its Odoo enterprise layer, now this one is maintained from the +original AGPL code.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Invoicing / Accounting dashboard.
  2. +
  3. Click on Import statement from any of the bank journals.
  4. +
  5. Select a QIF file.
  6. +
  7. Press Import.
  8. +
+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+ +
+
+

Authors

+
    +
  • OpenERP SA
  • +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+ + diff --git a/account_bank_statement_import_qif/tests/test_import_bank_statement.py b/account_bank_statement_import_qif/tests/test_import_bank_statement.py index 052fc038..0c6c598c 100644 --- a/account_bank_statement_import_qif/tests/test_import_bank_statement.py +++ b/account_bank_statement_import_qif/tests/test_import_bank_statement.py @@ -16,11 +16,11 @@ class TestQifFile(TransactionCase): """ def setUp(self): - super(TestQifFile, self).setUp() + super().setUp() self.statement_import_model = self.env["account.bank.statement.import"] self.statement_line_model = self.env["account.bank.statement.line"] self.journal = self.env["account.journal"].create( - {"name": "Test bank journal", "code": "TEST", "type": "bank",} + {"name": "Test bank journal", "code": "TEST", "type": "bank"} ) self.partner = self.env["res.partner"].create( { @@ -36,7 +36,7 @@ class TestQifFile(TransactionCase): qif_file = base64.b64encode(open(qif_file_path, "rb").read()) wizard = self.statement_import_model.with_context( journal_id=self.journal.id - ).create(dict(data_file=qif_file)) + ).create({"attachment_ids": [(0, 0, {"name": "test file", "datas": qif_file})]}) wizard.import_file() statement = self.statement_line_model.search( [("name", "=", "YOUR LOCAL SUPERMARKET")], limit=1, diff --git a/account_bank_statement_import_qif/wizards/account_bank_statement_import_qif.py b/account_bank_statement_import_qif/wizards/account_bank_statement_import_qif.py index 39c6c7fa..cb83716d 100644 --- a/account_bank_statement_import_qif/wizards/account_bank_statement_import_qif.py +++ b/account_bank_statement_import_qif/wizards/account_bank_statement_import_qif.py @@ -4,6 +4,8 @@ # Copyright 2016-2017 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import base64 + import dateutil.parser from odoo import api, models @@ -20,7 +22,7 @@ class AccountBankStatementImport(models.TransientModel): def _parse_file(self, data_file): if not self._check_qif(data_file): - return super(AccountBankStatementImport, self)._parse_file(data_file) + return super()._parse_file(data_file) try: file_data = data_file.decode() if "\r" in file_data: @@ -29,7 +31,7 @@ class AccountBankStatementImport(models.TransientModel): data_list = file_data.split("\n") header = data_list[0].strip() header = header.split(":")[1] - except: + except Exception: raise UserError(_("Could not decipher the QIF file.")) transactions = [] vals_line = {} @@ -82,12 +84,14 @@ class AccountBankStatementImport(models.TransientModel): def _complete_stmts_vals(self, stmt_vals, journal_id, account_number): """Match partner_id if hasn't been deducted yet.""" - res = super(AccountBankStatementImport, self)._complete_stmts_vals( - stmt_vals, journal_id, account_number, - ) + res = super()._complete_stmts_vals(stmt_vals, journal_id, account_number) # Since QIF doesn't provide account numbers (normal behaviour is to # provide 'account_number', which the generic module uses to find # the partner), we have to find res.partner through the name + if not self.attachment_ids or not self._check_qif( + base64.b64decode(self.attachment_ids[0].datas) + ): + return res partner_obj = self.env["res.partner"] for statement in res: for line_vals in statement["transactions"]: