[MIG] account_bank_statement_import_split: Migration to 13.0

This commit is contained in:
Alexey Pelykh
2021-09-23 11:56:29 +02:00
parent d94e9040a5
commit c7bfdfbbce
3 changed files with 82 additions and 46 deletions

View File

@@ -1,17 +1,17 @@
# Copyright 2019-2020 Brainbean Apps (https://brainbeanapps.com) # Copyright 2019-2020 Brainbean Apps (https://brainbeanapps.com)
# Copyright 2020 CorporateHub (https://corporatehub.eu) # Copyright 2020-2021 CorporateHub (https://corporatehub.eu)
# 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": "Account Bank Statement Import: Split by date", "name": "Account Bank Statement Import: Split by date",
"version": "12.0.1.0.1", "version": "13.0.1.0.0",
"author": "CorporateHub, " "Odoo Community Association (OCA)", "author": "CorporateHub, Odoo Community Association (OCA)",
"maintainers": ["alexey-pelykh"], "maintainers": ["alexey-pelykh"],
"website": "https://github.com/OCA/bank-statement-import/", "website": "https://github.com/OCA/bank-statement-import",
"license": "AGPL-3", "license": "AGPL-3",
"category": "Accounting", "category": "Accounting",
"summary": "Split statements by date during import", "summary": "Split statements by date during import",
"depends": ["account_bank_statement_import",], "depends": ["account_bank_statement_import"],
"data": ["views/account_bank_statement_import.xml",], "data": ["views/account_bank_statement_import.xml"],
"installable": True, "installable": True,
} }

View File

@@ -1,11 +1,12 @@
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com) # Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# Copyright 2021 CorporateHub (https://corporatehub.eu)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from decimal import Decimal from decimal import Decimal
from dateutil.relativedelta import MO, relativedelta from dateutil.relativedelta import MO, relativedelta
from odoo import api, fields, models from odoo import fields, models
class AccountBankStatementImport(models.TransientModel): class AccountBankStatementImport(models.TransientModel):
@@ -84,9 +85,7 @@ class AccountBankStatementImport(models.TransientModel):
} }
) )
if balance_start is not None: if balance_start is not None:
statement_values.update( statement_values.update({"balance_start": float(balance_start)})
{"balance_start": float(balance_start),}
)
for transaction in statement_transactions: for transaction in statement_transactions:
balance_start += Decimal(transaction["amount"]) balance_start += Decimal(transaction["amount"])
if balance_end is not None: if balance_end is not None:
@@ -94,21 +93,17 @@ class AccountBankStatementImport(models.TransientModel):
for transaction in transactions: for transaction in transactions:
statement_balance_end -= Decimal(transaction["amount"]) statement_balance_end -= Decimal(transaction["amount"])
statement_values.update( statement_values.update(
{"balance_end_real": float(statement_balance_end),} {"balance_end_real": float(statement_balance_end)}
) )
statements.append(statement_values) statements.append(statement_values)
statement_date_since = statement_date_until statement_date_since = statement_date_until
return statements return statements
@api.multi
def _prepare_transaction(self, transaction): def _prepare_transaction(self, transaction):
transaction.update( transaction.update({"date": fields.Date.from_string(transaction["date"])})
{"date": fields.Date.from_string(transaction["date"]),}
)
return transaction return transaction
@api.multi
def _get_statement_date_since(self, date): def _get_statement_date_since(self, date):
self.ensure_one() self.ensure_one()
if self.import_mode == "daily": if self.import_mode == "daily":
@@ -118,7 +113,6 @@ class AccountBankStatementImport(models.TransientModel):
elif self.import_mode == "monthly": elif self.import_mode == "monthly":
return date.replace(day=1,) return date.replace(day=1,)
@api.multi
def _get_statement_date_step(self): def _get_statement_date_step(self):
self.ensure_one() self.ensure_one()
if self.import_mode == "daily": if self.import_mode == "daily":
@@ -128,7 +122,6 @@ class AccountBankStatementImport(models.TransientModel):
elif self.import_mode == "monthly": elif self.import_mode == "monthly":
return relativedelta(months=1, day=1,) return relativedelta(months=1, day=1,)
@api.multi
def _get_statement_date(self, date_since, date_until): def _get_statement_date(self, date_since, date_until):
self.ensure_one() self.ensure_one()
# NOTE: Statement date is treated by Odoo as start of period. Details # NOTE: Statement date is treated by Odoo as start of period. Details
@@ -136,7 +129,6 @@ class AccountBankStatementImport(models.TransientModel):
# - def get_line_graph_datas() # - def get_line_graph_datas()
return date_since return date_since
@api.multi
def _get_statement_name(self, journal, date_since, date_until): def _get_statement_name(self, journal, date_since, date_until):
self.ensure_one() self.ensure_one()
return journal.sequence_id.with_context( return journal.sequence_id.with_context(

View File

@@ -1,4 +1,5 @@
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com) # Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# Copyright 2021 CorporateHub (https://corporatehub.eu)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from base64 import b64encode from base64 import b64encode
@@ -19,9 +20,7 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase):
self.now = fields.Datetime.now() self.now = fields.Datetime.now()
self.currency_usd = self.env.ref("base.USD") self.currency_usd = self.env.ref("base.USD")
self.empty_data_file = b64encode( self.empty_data_file = b64encode(b"TestAccountBankAccountStatementImportSplit")
b"TestAccountBankAccountStatementImportSplit"
)
self.AccountJournal = self.env["account.journal"] self.AccountJournal = self.env["account.journal"]
self.AccountBankStatement = self.env["account.bank.statement"] self.AccountBankStatement = self.env["account.bank.statement"]
self.AccountBankStatementImport = self.env["account.bank.statement.import"] self.AccountBankStatementImport = self.env["account.bank.statement.import"]
@@ -36,8 +35,21 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase):
} }
) )
wizard = self.AccountBankStatementImport.with_context( wizard = self.AccountBankStatementImport.with_context(
{"journal_id": journal.id,} {"journal_id": journal.id}
).create({"filename": "file.ext", "data_file": self.empty_data_file,}) ).create(
{
"attachment_ids": [
(
0,
0,
{
"name": "fixtures/statement_en.csv",
"datas": self.empty_data_file,
},
)
],
}
)
data = ( data = (
journal.currency_id.name, journal.currency_id.name,
journal.bank_account_id.acc_number, journal.bank_account_id.acc_number,
@@ -60,8 +72,8 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase):
], ],
) )
with mock.patch(_parse_file_method, return_value=data): with mock.patch(_parse_file_method, return_value=data):
wizard.with_context({"journal_id": journal.id,}).import_file() wizard.with_context({"journal_id": journal.id}).import_file()
statement = self.AccountBankStatement.search([("journal_id", "=", journal.id),]) statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
self.assertEqual(len(statement), 1) self.assertEqual(len(statement), 1)
self.assertEqual(len(statement.line_ids), 1) self.assertEqual(len(statement.line_ids), 1)
@@ -75,11 +87,19 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase):
} }
) )
wizard = self.AccountBankStatementImport.with_context( wizard = self.AccountBankStatementImport.with_context(
{"journal_id": journal.id,} {"journal_id": journal.id}
).create( ).create(
{ {
"filename": "file.ext", "attachment_ids": [
"data_file": self.empty_data_file, (
0,
0,
{
"name": "fixtures/statement_en.csv",
"datas": self.empty_data_file,
},
)
],
"import_mode": "single", "import_mode": "single",
} }
) )
@@ -105,8 +125,8 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase):
], ],
) )
with mock.patch(_parse_file_method, return_value=data): with mock.patch(_parse_file_method, return_value=data):
wizard.with_context({"journal_id": journal.id,}).import_file() wizard.with_context({"journal_id": journal.id}).import_file()
statement = self.AccountBankStatement.search([("journal_id", "=", journal.id),]) statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)])
self.assertEqual(len(statement), 1) self.assertEqual(len(statement), 1)
self.assertEqual(len(statement.line_ids), 1) self.assertEqual(len(statement.line_ids), 1)
@@ -120,11 +140,19 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase):
} }
) )
wizard = self.AccountBankStatementImport.with_context( wizard = self.AccountBankStatementImport.with_context(
{"journal_id": journal.id,} {"journal_id": journal.id}
).create( ).create(
{ {
"filename": "file.ext", "attachment_ids": [
"data_file": self.empty_data_file, (
0,
0,
{
"name": "fixtures/statement_en.csv",
"datas": self.empty_data_file,
},
)
],
"import_mode": "daily", "import_mode": "daily",
} }
) )
@@ -157,9 +185,9 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase):
], ],
) )
with mock.patch(_parse_file_method, return_value=data): with mock.patch(_parse_file_method, return_value=data):
wizard.with_context({"journal_id": journal.id,}).import_file() wizard.with_context({"journal_id": journal.id}).import_file()
statements = self.AccountBankStatement.search( statements = self.AccountBankStatement.search(
[("journal_id", "=", journal.id),] [("journal_id", "=", journal.id)]
).sorted(key=lambda statement: statement.date) ).sorted(key=lambda statement: statement.date)
self.assertEqual(len(statements), 2) self.assertEqual(len(statements), 2)
self.assertEqual(len(statements[0].line_ids), 1) self.assertEqual(len(statements[0].line_ids), 1)
@@ -179,11 +207,19 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase):
} }
) )
wizard = self.AccountBankStatementImport.with_context( wizard = self.AccountBankStatementImport.with_context(
{"journal_id": journal.id,} {"journal_id": journal.id}
).create( ).create(
{ {
"filename": "file.ext", "attachment_ids": [
"data_file": self.empty_data_file, (
0,
0,
{
"name": "fixtures/statement_en.csv",
"datas": self.empty_data_file,
},
)
],
"import_mode": "weekly", "import_mode": "weekly",
} }
) )
@@ -216,9 +252,9 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase):
], ],
) )
with mock.patch(_parse_file_method, return_value=data): with mock.patch(_parse_file_method, return_value=data):
wizard.with_context({"journal_id": journal.id,}).import_file() wizard.with_context({"journal_id": journal.id}).import_file()
statements = self.AccountBankStatement.search( statements = self.AccountBankStatement.search(
[("journal_id", "=", journal.id),] [("journal_id", "=", journal.id)]
).sorted(key=lambda statement: statement.date) ).sorted(key=lambda statement: statement.date)
self.assertEqual(len(statements), 2) self.assertEqual(len(statements), 2)
self.assertEqual(len(statements[0].line_ids), 1) self.assertEqual(len(statements[0].line_ids), 1)
@@ -238,11 +274,19 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase):
} }
) )
wizard = self.AccountBankStatementImport.with_context( wizard = self.AccountBankStatementImport.with_context(
{"journal_id": journal.id,} {"journal_id": journal.id}
).create( ).create(
{ {
"filename": "file.ext", "attachment_ids": [
"data_file": self.empty_data_file, (
0,
0,
{
"name": "fixtures/statement_en.csv",
"datas": self.empty_data_file,
},
)
],
"import_mode": "monthly", "import_mode": "monthly",
} }
) )
@@ -275,9 +319,9 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase):
], ],
) )
with mock.patch(_parse_file_method, return_value=data): with mock.patch(_parse_file_method, return_value=data):
wizard.with_context({"journal_id": journal.id,}).import_file() wizard.with_context({"journal_id": journal.id}).import_file()
statements = self.AccountBankStatement.search( statements = self.AccountBankStatement.search(
[("journal_id", "=", journal.id),] [("journal_id", "=", journal.id)]
).sorted(key=lambda statement: statement.date) ).sorted(key=lambda statement: statement.date)
self.assertEqual(len(statements), 2) self.assertEqual(len(statements), 2)
self.assertEqual(len(statements[0].line_ids), 1) self.assertEqual(len(statements[0].line_ids), 1)