[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). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{ {
"name": "Bank Account Transfer Line", "name": "Bank Account Transfer Line",
"version": "13.0.1.0.0", "version": "12.0.1.0.0",
"category": "Account", "category": "Account",
"website": "https://github.com/OCA/bank-statement-import", "website": "https://github.com/OCA/bank-statement-import",
"author": "Camptocamp, " "Odoo Community Association (OCA)", "author": "Camptocamp, " "Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"installable": True, "installable": True,
"depends": ["account_bank_statement_import"], "depends": ["account_bank_statement_import_camt_oca"],
"data": ["view/account_journal.xml"], "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 """ Create additional line in statement to set bank statement statement
to 0 balance""" to 0 balance"""
statement_line_ids, notifications = super()._create_bank_statements(stmts_vals) statement_ids, notifications = super()._create_bank_statements(stmts_vals)
statements = self.env["account.bank.statement"].search( statements = self.env['account.bank.statement'].browse(statement_ids)
[("line_ids", "in", statement_line_ids)]
)
for statement in statements: for statement in statements:
amount = sum(statement.line_ids.mapped("amount")) amount = sum(statement.line_ids.mapped("amount"))
if statement.journal_id.transfer_line: if statement.journal_id.transfer_line:
if amount != 0: if amount != 0:
amount = -amount amount = -amount
line = statement.line_ids.create( statement.line_ids.create(
{ {
"name": statement.name, "name": statement.name,
"amount": amount, "amount": amount,
@@ -29,8 +27,7 @@ class AccountBankStatementImport(models.TransientModel):
"date": statement.date, "date": statement.date,
} }
) )
statement_line_ids.append(line.id)
statement.balance_end_real = statement.balance_start statement.balance_end_real = statement.balance_start
else: else:
statement.balance_end_real = statement.balance_start + amount 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" _inherit = "account.journal"
transfer_line = fields.Boolean( transfer_line = fields.Boolean(
string="Generate line", string="Add balance line",
help="Generate transfer line on total of bank statemen import", 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 To enable this option you need properly set flag on Account Journal
Configuration -> Journals -> tab Advanced Settings -> Bank statement configuration Configuration -> Journals -> tab Advanced Settings -> Bank statement configuration

View File

@@ -37,20 +37,20 @@ class TestGenerateBankStatement(SavepointCase):
def _load_statement(self): def _load_statement(self):
# self = self.with_context(journal_id=self.journal.id)
testfile = get_module_resource( testfile = get_module_resource(
"account_bank_statement_import_camt_oca", "test_files", "test-camt053" "account_bank_statement_import_camt_oca", "test_files", "test-camt053"
) )
with open(testfile, "rb") as datafile: with open(testfile, 'rb') as datafile:
camt_file = base64.b64encode(datafile.read()) 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( statement_lines = self.env['account.bank.statement'].browse(
{"attachment_ids": [(0, 0, {"name": "test file", "datas": camt_file})]} action['context']['statement_ids']
).import_file() ).line_ids
bank_st_record = self.env["account.bank.statement"].search(
[("name", "=", "1234Test/1")], limit=1
)
statement_lines = bank_st_record.line_ids
return statement_lines return statement_lines