mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[ADD] account_bank_statement_import_transfer_move
This commit is contained in:
1
account_bank_statement_import_transfer_move/__init__.py
Normal file
1
account_bank_statement_import_transfer_move/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
13
account_bank_statement_import_transfer_move/__manifest__.py
Normal file
13
account_bank_statement_import_transfer_move/__manifest__.py
Normal 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": "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"],
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
from . import account_bank_statement_import
|
||||
from . import account_journal
|
||||
@@ -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
|
||||
@@ -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",
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
* Iryna Vyshnevska <i.vyshnevska@mobilunity.com>
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
from . import test_statement
|
||||
@@ -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)
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user