From 49de24c95381f5c1a12345185f64a3beabb2c4f3 Mon Sep 17 00:00:00 2001 From: Iryna Vushnevska Date: Thu, 6 Feb 2020 16:40:46 +0200 Subject: [PATCH] [ADD] account_bank_statement_import_transfer_move --- .../README.rst | 0 .../__init__.py | 1 + .../__manifest__.py | 13 ++++ .../models/__init__.py | 2 + .../models/account_bank_statement_import.py | 36 ++++++++++ .../models/account_journal.py | 14 ++++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 3 + .../tests/__init__.py | 1 + .../tests/test_statement.py | 67 +++++++++++++++++++ .../view/account_journal.xml | 17 +++++ 11 files changed, 155 insertions(+) create mode 100644 account_bank_statement_import_transfer_move/README.rst create mode 100644 account_bank_statement_import_transfer_move/__init__.py create mode 100644 account_bank_statement_import_transfer_move/__manifest__.py create mode 100644 account_bank_statement_import_transfer_move/models/__init__.py create mode 100644 account_bank_statement_import_transfer_move/models/account_bank_statement_import.py create mode 100644 account_bank_statement_import_transfer_move/models/account_journal.py create mode 100644 account_bank_statement_import_transfer_move/readme/CONTRIBUTORS.rst create mode 100644 account_bank_statement_import_transfer_move/readme/DESCRIPTION.rst create mode 100644 account_bank_statement_import_transfer_move/tests/__init__.py create mode 100644 account_bank_statement_import_transfer_move/tests/test_statement.py create mode 100644 account_bank_statement_import_transfer_move/view/account_journal.xml diff --git a/account_bank_statement_import_transfer_move/README.rst b/account_bank_statement_import_transfer_move/README.rst new file mode 100644 index 0000000..e69de29 diff --git a/account_bank_statement_import_transfer_move/__init__.py b/account_bank_statement_import_transfer_move/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/account_bank_statement_import_transfer_move/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_bank_statement_import_transfer_move/__manifest__.py b/account_bank_statement_import_transfer_move/__manifest__.py new file mode 100644 index 0000000..b4710f1 --- /dev/null +++ b/account_bank_statement_import_transfer_move/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Bank Account Transfer Line", + "version": "13.0.1.0.0", + "category": "Account", + "website": "https://github.com/OCA/bank-statement-import", + "author": "Camptocamp, " "Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": ["account_bank_statement_import"], + "data": ["view/account_journal.xml"], +} diff --git a/account_bank_statement_import_transfer_move/models/__init__.py b/account_bank_statement_import_transfer_move/models/__init__.py new file mode 100644 index 0000000..ba1f493 --- /dev/null +++ b/account_bank_statement_import_transfer_move/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_bank_statement_import +from . import account_journal diff --git a/account_bank_statement_import_transfer_move/models/account_bank_statement_import.py b/account_bank_statement_import_transfer_move/models/account_bank_statement_import.py new file mode 100644 index 0000000..af145c4 --- /dev/null +++ b/account_bank_statement_import_transfer_move/models/account_bank_statement_import.py @@ -0,0 +1,36 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class AccountBankStatementImport(models.TransientModel): + + _inherit = "account.bank.statement.import" + + def _create_bank_statements(self, stmts_vals): + """ Create additional line in statement to set bank statement statement + to 0 balance""" + + statement_line_ids, notifications = super()._create_bank_statements(stmts_vals) + statements = self.env["account.bank.statement"].search( + [("line_ids", "in", statement_line_ids)] + ) + for statement in statements: + amount = sum(statement.line_ids.mapped("amount")) + if statement.journal_id.transfer_line: + if amount != 0: + amount = -amount + line = statement.line_ids.create( + { + "name": statement.name, + "amount": amount, + "statement_id": statement.id, + "date": statement.date, + } + ) + statement_line_ids.append(line.id) + statement.balance_end_real = statement.balance_start + else: + statement.balance_end_real = statement.balance_start + amount + return statement_line_ids, notifications diff --git a/account_bank_statement_import_transfer_move/models/account_journal.py b/account_bank_statement_import_transfer_move/models/account_journal.py new file mode 100644 index 0000000..fa05c64 --- /dev/null +++ b/account_bank_statement_import_transfer_move/models/account_journal.py @@ -0,0 +1,14 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class AccountBankStatementImport(models.Model): + + _inherit = "account.journal" + + transfer_line = fields.Boolean( + string="Generate line", + help="Generate transfer line on total of bank statemen import", + ) diff --git a/account_bank_statement_import_transfer_move/readme/CONTRIBUTORS.rst b/account_bank_statement_import_transfer_move/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..a682730 --- /dev/null +++ b/account_bank_statement_import_transfer_move/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Iryna Vyshnevska diff --git a/account_bank_statement_import_transfer_move/readme/DESCRIPTION.rst b/account_bank_statement_import_transfer_move/readme/DESCRIPTION.rst new file mode 100644 index 0000000..80541a1 --- /dev/null +++ b/account_bank_statement_import_transfer_move/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ + This module allows you to add generation of additional line in bank statement. + To enable this option you need properly set flag on Account Journal + Configuration -> Journals -> tab Advanced Settings -> Bank statement configuration diff --git a/account_bank_statement_import_transfer_move/tests/__init__.py b/account_bank_statement_import_transfer_move/tests/__init__.py new file mode 100644 index 0000000..db9f018 --- /dev/null +++ b/account_bank_statement_import_transfer_move/tests/__init__.py @@ -0,0 +1 @@ +from . import test_statement diff --git a/account_bank_statement_import_transfer_move/tests/test_statement.py b/account_bank_statement_import_transfer_move/tests/test_statement.py new file mode 100644 index 0000000..53a6220 --- /dev/null +++ b/account_bank_statement_import_transfer_move/tests/test_statement.py @@ -0,0 +1,67 @@ +# Copyright 2020 Camptocamp SA +# 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 + + +class TestGenerateBankStatement(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + bank = cls.env["res.partner.bank"].create( + { + "acc_number": "NL77ABNA0574908765", + "partner_id": cls.env.ref("base.main_partner").id, + "company_id": cls.env.ref("base.main_company").id, + "bank_id": cls.env.ref("base.res_bank_1").id, + } + ) + cls.env["res.partner.bank"].create( + { + "acc_number": "NL46ABNA0499998748", + "partner_id": cls.env.ref("base.main_partner").id, + "company_id": cls.env.ref("base.main_company").id, + "bank_id": cls.env.ref("base.res_bank_1").id, + } + ) + cls.journal = cls.env["account.journal"].create( + { + "name": "Bank Journal - (test camt)", + "code": "TBNKCAMT", + "type": "bank", + "bank_account_id": bank.id, + } + ) + + def _load_statement(self): + + testfile = get_module_resource( + "account_bank_statement_import_camt_oca", "test_files", "test-camt053" + ) + with open(testfile, "rb") as datafile: + camt_file = base64.b64encode(datafile.read()) + + self.env["account.bank.statement.import"].create( + {"attachment_ids": [(0, 0, {"name": "test file", "datas": camt_file})]} + ).import_file() + + bank_st_record = self.env["account.bank.statement"].search( + [("name", "=", "1234Test/1")], limit=1 + ) + statement_lines = bank_st_record.line_ids + + return statement_lines + + def test_statement_import(self): + + self.journal.transfer_line = True + lines = self._load_statement() + self.assertEqual(len(lines), 5) + self.assertAlmostEqual(sum(lines.mapped("amount")), 0) + + self.journal.transfer_line = False + lines = self._load_statement() + self.assertEqual(len(lines), 4) + self.assertAlmostEqual(sum(lines.mapped("amount")), -12.99) diff --git a/account_bank_statement_import_transfer_move/view/account_journal.xml b/account_bank_statement_import_transfer_move/view/account_journal.xml new file mode 100644 index 0000000..b868be0 --- /dev/null +++ b/account_bank_statement_import_transfer_move/view/account_journal.xml @@ -0,0 +1,17 @@ + + + + + account.journal + account.journal.form + + + + + + + + + + +