[MIG][12.0] account_bank_statement_import_transfer_move: backport to v12

This commit is contained in:
Iryna Vushnevska
2020-02-07 00:42:51 +02:00
parent 49de24c953
commit fa93e9fb59
5 changed files with 20 additions and 22 deletions

View File

@@ -2,12 +2,12 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Bank Account Transfer Line",
"version": "13.0.1.0.0",
"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"],
"depends": ["account_bank_statement_import_camt_oca"],
"data": ["view/account_journal.xml"],
}

View File

@@ -12,16 +12,14 @@ class AccountBankStatementImport(models.TransientModel):
""" 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)]
)
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
line = statement.line_ids.create(
statement.line_ids.create(
{
"name": statement.name,
"amount": amount,
@@ -29,8 +27,7 @@ class AccountBankStatementImport(models.TransientModel):
"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
return statement_ids, notifications

View File

@@ -9,6 +9,6 @@ class AccountBankStatementImport(models.Model):
_inherit = "account.journal"
transfer_line = fields.Boolean(
string="Generate line",
help="Generate transfer line on total of bank statemen import",
string="Add balance line",
help="Generate balance line on total of bank statemen import",
)

View File

@@ -1,3 +1,4 @@
This module allows you to add generation of additional line in bank statement.
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

@@ -37,20 +37,20 @@ class TestGenerateBankStatement(SavepointCase):
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:
camt_file = base64.b64encode(datafile.read())
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()
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
statement_lines = self.env['account.bank.statement'].browse(
action['context']['statement_ids']
).line_ids
return statement_lines