From c7bfdfbbce4316743f9e34b107815ecda78ddd12 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Thu, 23 Sep 2021 11:56:29 +0200 Subject: [PATCH] [MIG] account_bank_statement_import_split: Migration to 13.0 --- .../__manifest__.py | 12 +-- .../models/account_bank_statement_import.py | 18 +--- ...est_account_bank_statement_import_split.py | 98 ++++++++++++++----- 3 files changed, 82 insertions(+), 46 deletions(-) diff --git a/account_bank_statement_import_split/__manifest__.py b/account_bank_statement_import_split/__manifest__.py index 434819e3..a3ada7b8 100644 --- a/account_bank_statement_import_split/__manifest__.py +++ b/account_bank_statement_import_split/__manifest__.py @@ -1,17 +1,17 @@ # 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). { "name": "Account Bank Statement Import: Split by date", - "version": "12.0.1.0.1", - "author": "CorporateHub, " "Odoo Community Association (OCA)", + "version": "13.0.1.0.0", + "author": "CorporateHub, Odoo Community Association (OCA)", "maintainers": ["alexey-pelykh"], - "website": "https://github.com/OCA/bank-statement-import/", + "website": "https://github.com/OCA/bank-statement-import", "license": "AGPL-3", "category": "Accounting", "summary": "Split statements by date during import", - "depends": ["account_bank_statement_import",], - "data": ["views/account_bank_statement_import.xml",], + "depends": ["account_bank_statement_import"], + "data": ["views/account_bank_statement_import.xml"], "installable": True, } diff --git a/account_bank_statement_import_split/models/account_bank_statement_import.py b/account_bank_statement_import_split/models/account_bank_statement_import.py index a73adac0..7263a6d3 100644 --- a/account_bank_statement_import_split/models/account_bank_statement_import.py +++ b/account_bank_statement_import_split/models/account_bank_statement_import.py @@ -1,11 +1,12 @@ # 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). from decimal import Decimal from dateutil.relativedelta import MO, relativedelta -from odoo import api, fields, models +from odoo import fields, models class AccountBankStatementImport(models.TransientModel): @@ -84,9 +85,7 @@ class AccountBankStatementImport(models.TransientModel): } ) if balance_start is not None: - statement_values.update( - {"balance_start": float(balance_start),} - ) + statement_values.update({"balance_start": float(balance_start)}) for transaction in statement_transactions: balance_start += Decimal(transaction["amount"]) if balance_end is not None: @@ -94,21 +93,17 @@ class AccountBankStatementImport(models.TransientModel): for transaction in transactions: statement_balance_end -= Decimal(transaction["amount"]) statement_values.update( - {"balance_end_real": float(statement_balance_end),} + {"balance_end_real": float(statement_balance_end)} ) statements.append(statement_values) statement_date_since = statement_date_until return statements - @api.multi def _prepare_transaction(self, transaction): - transaction.update( - {"date": fields.Date.from_string(transaction["date"]),} - ) + transaction.update({"date": fields.Date.from_string(transaction["date"])}) return transaction - @api.multi def _get_statement_date_since(self, date): self.ensure_one() if self.import_mode == "daily": @@ -118,7 +113,6 @@ class AccountBankStatementImport(models.TransientModel): elif self.import_mode == "monthly": return date.replace(day=1,) - @api.multi def _get_statement_date_step(self): self.ensure_one() if self.import_mode == "daily": @@ -128,7 +122,6 @@ class AccountBankStatementImport(models.TransientModel): elif self.import_mode == "monthly": return relativedelta(months=1, day=1,) - @api.multi def _get_statement_date(self, date_since, date_until): self.ensure_one() # 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() return date_since - @api.multi def _get_statement_name(self, journal, date_since, date_until): self.ensure_one() return journal.sequence_id.with_context( diff --git a/account_bank_statement_import_split/tests/test_account_bank_statement_import_split.py b/account_bank_statement_import_split/tests/test_account_bank_statement_import_split.py index 5b167998..7a49cf35 100644 --- a/account_bank_statement_import_split/tests/test_account_bank_statement_import_split.py +++ b/account_bank_statement_import_split/tests/test_account_bank_statement_import_split.py @@ -1,4 +1,5 @@ # 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). from base64 import b64encode @@ -19,9 +20,7 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase): self.now = fields.Datetime.now() self.currency_usd = self.env.ref("base.USD") - self.empty_data_file = b64encode( - b"TestAccountBankAccountStatementImportSplit" - ) + self.empty_data_file = b64encode(b"TestAccountBankAccountStatementImportSplit") self.AccountJournal = self.env["account.journal"] self.AccountBankStatement = self.env["account.bank.statement"] self.AccountBankStatementImport = self.env["account.bank.statement.import"] @@ -36,8 +35,21 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase): } ) wizard = self.AccountBankStatementImport.with_context( - {"journal_id": journal.id,} - ).create({"filename": "file.ext", "data_file": self.empty_data_file,}) + {"journal_id": journal.id} + ).create( + { + "attachment_ids": [ + ( + 0, + 0, + { + "name": "fixtures/statement_en.csv", + "datas": self.empty_data_file, + }, + ) + ], + } + ) data = ( journal.currency_id.name, journal.bank_account_id.acc_number, @@ -60,8 +72,8 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase): ], ) with mock.patch(_parse_file_method, return_value=data): - wizard.with_context({"journal_id": journal.id,}).import_file() - statement = self.AccountBankStatement.search([("journal_id", "=", journal.id),]) + wizard.with_context({"journal_id": journal.id}).import_file() + statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)]) self.assertEqual(len(statement), 1) self.assertEqual(len(statement.line_ids), 1) @@ -75,11 +87,19 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase): } ) wizard = self.AccountBankStatementImport.with_context( - {"journal_id": journal.id,} + {"journal_id": journal.id} ).create( { - "filename": "file.ext", - "data_file": self.empty_data_file, + "attachment_ids": [ + ( + 0, + 0, + { + "name": "fixtures/statement_en.csv", + "datas": self.empty_data_file, + }, + ) + ], "import_mode": "single", } ) @@ -105,8 +125,8 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase): ], ) with mock.patch(_parse_file_method, return_value=data): - wizard.with_context({"journal_id": journal.id,}).import_file() - statement = self.AccountBankStatement.search([("journal_id", "=", journal.id),]) + wizard.with_context({"journal_id": journal.id}).import_file() + statement = self.AccountBankStatement.search([("journal_id", "=", journal.id)]) self.assertEqual(len(statement), 1) self.assertEqual(len(statement.line_ids), 1) @@ -120,11 +140,19 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase): } ) wizard = self.AccountBankStatementImport.with_context( - {"journal_id": journal.id,} + {"journal_id": journal.id} ).create( { - "filename": "file.ext", - "data_file": self.empty_data_file, + "attachment_ids": [ + ( + 0, + 0, + { + "name": "fixtures/statement_en.csv", + "datas": self.empty_data_file, + }, + ) + ], "import_mode": "daily", } ) @@ -157,9 +185,9 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase): ], ) 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( - [("journal_id", "=", journal.id),] + [("journal_id", "=", journal.id)] ).sorted(key=lambda statement: statement.date) self.assertEqual(len(statements), 2) self.assertEqual(len(statements[0].line_ids), 1) @@ -179,11 +207,19 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase): } ) wizard = self.AccountBankStatementImport.with_context( - {"journal_id": journal.id,} + {"journal_id": journal.id} ).create( { - "filename": "file.ext", - "data_file": self.empty_data_file, + "attachment_ids": [ + ( + 0, + 0, + { + "name": "fixtures/statement_en.csv", + "datas": self.empty_data_file, + }, + ) + ], "import_mode": "weekly", } ) @@ -216,9 +252,9 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase): ], ) 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( - [("journal_id", "=", journal.id),] + [("journal_id", "=", journal.id)] ).sorted(key=lambda statement: statement.date) self.assertEqual(len(statements), 2) self.assertEqual(len(statements[0].line_ids), 1) @@ -238,11 +274,19 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase): } ) wizard = self.AccountBankStatementImport.with_context( - {"journal_id": journal.id,} + {"journal_id": journal.id} ).create( { - "filename": "file.ext", - "data_file": self.empty_data_file, + "attachment_ids": [ + ( + 0, + 0, + { + "name": "fixtures/statement_en.csv", + "datas": self.empty_data_file, + }, + ) + ], "import_mode": "monthly", } ) @@ -275,9 +319,9 @@ class TestAccountBankAccountStatementImportSplit(common.TransactionCase): ], ) 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( - [("journal_id", "=", journal.id),] + [("journal_id", "=", journal.id)] ).sorted(key=lambda statement: statement.date) self.assertEqual(len(statements), 2) self.assertEqual(len(statements[0].line_ids), 1)