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..5186dbd --- /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": "12.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_camt_oca"], + "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..56b14d3 --- /dev/null +++ b/account_bank_statement_import_transfer_move/models/account_bank_statement_import.py @@ -0,0 +1,33 @@ +# 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_ids, notifications = super()._create_bank_statements(stmts_vals) + statements = self.env['account.bank.statement'].browse(statement_ids) + for statement in statements: + amount = sum(statement.line_ids.mapped("amount")) + if statement.journal_id.transfer_line: + if amount != 0: + amount = -amount + statement.line_ids.create( + { + "name": statement.name, + "amount": amount, + "statement_id": statement.id, + "date": statement.date, + } + ) + statement.balance_end_real = statement.balance_start + else: + statement.balance_end_real = statement.balance_start + amount + return statement_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..f1f970e --- /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="Add balance line", + help="Generate balance 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..d13cbe4 --- /dev/null +++ b/account_bank_statement_import_transfer_move/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ + This module allows you to add generation of additional line in bank statement which will balance your bank statement total to 0. + This line can be consolidated later with different account. + 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..4fa8a54 --- /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): + + # self = self.with_context(journal_id=self.journal.id) + + testfile = get_module_resource( + "account_bank_statement_import_camt_oca", "test_files", "test-camt053" + ) + with open(testfile, 'rb') as datafile: + action = self.env['account.bank.statement.import'].with_context( + journal_id=self.journal.id).create({ + 'data_file': base64.b64encode(datafile.read()) + }).import_file() + + statement_lines = self.env['account.bank.statement'].browse( + action['context']['statement_ids'] + ).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 + + + + + + + + + + +