Merge PR #250 into 12.0

Signed-off-by dreispt
This commit is contained in:
OCA-git-bot
2021-12-02 13:01:29 +00:00
11 changed files with 153 additions and 0 deletions

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -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"],
}

View File

@@ -0,0 +1,2 @@
from . import account_bank_statement_import
from . import account_journal

View File

@@ -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

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

View File

@@ -0,0 +1 @@
* Iryna Vyshnevska <i.vyshnevska@mobilunity.com>

View File

@@ -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

View File

@@ -0,0 +1 @@
from . import test_statement

View File

@@ -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)

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_account_journal_form" model="ir.ui.view">
<field name="model">account.journal</field>
<field name="name">account.journal.form</field>
<field name="inherit_id" ref="account.view_account_journal_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='advanced_settings']/group" position="inside">
<group string="Bank statement configuration" groups="account.group_account_manager">
<field name="transfer_line"/>
</group>
</xpath>
</field>
</record>
</odoo>