[IMP] add option to create addtional final line

This commit is contained in:
Iryna Vyshnevska
2021-01-14 13:38:05 +02:00
committed by Maksym Yankin
parent 66f5316dfd
commit 47968a866b
7 changed files with 115 additions and 9 deletions

View File

@@ -1,2 +1,3 @@
from . import account_statement_import
from . import account_journal
from . import parser

View File

@@ -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 statement import",
)

View File

@@ -12,18 +12,29 @@ class AccountStatementImport(models.TransientModel):
_inherit = "account.statement.import"
def _create_bank_statements(self, stmts_vals):
""" Set balance_end_real if not already provided by the file."""
def _create_bank_statements(self, stmts_vals, result):
"""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)]
)
super()._create_bank_statements(stmts_vals, result)
statements = self.env["account.bank.statement"].browse(result["statement_ids"])
for statement in statements:
if not statement.balance_end_real:
amount = sum(statement.line_ids.mapped("amount"))
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,
"payment_ref": "/",
}
)
statement.balance_end_real = statement.balance_start
else:
statement.balance_end_real = statement.balance_start + amount
return statement_line_ids, notifications
def _complete_stmts_vals(self, stmts_vals, journal, account_number):
"""Search partner from partner reference"""

View File

@@ -0,0 +1 @@
* Digital4efficiency.ch

View File

@@ -4,6 +4,11 @@ Customer invoices will be reconciled/Paid. Payment entries will be posted into a
After this first step, import normally your CAMT.053 (full bank statement) into the bank journal. You will be able to clear the internal transfer account to end up the accounting flow.
Optionally we can activate 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 option of final statement line you need properly set flag on Account Journal
Configuration -> Journals -> tab Advanced Settings -> Bank statement configuration
Switzerland localisation
------------------------

View File

@@ -1 +1,2 @@
from . import test_get_partner_ref
from . import test_statement

View File

@@ -0,0 +1,73 @@
# Copyright 2020 Camptocamp SA
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import base64
import mock
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,
"currency_id": cls.env.ref("base.EUR").id,
}
)
@mock.patch(
"odoo.addons.account.models.sequence_mixin."
"SequenceMixin._constrains_date_sequence",
side_effect=False,
)
def _load_statement(self, constraint):
testfile = get_module_resource(
"account_statement_import_camt", "test_files", "test-camt053"
)
with open(testfile, "rb") as datafile:
camt_file = base64.b64encode(datafile.read())
self.env["account.statement.import"].create(
{
"statement_filename": "test import",
"statement_file": camt_file,
}
).import_file_button()
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)