diff --git a/account_statement_import_sheet_file/__manifest__.py b/account_statement_import_sheet_file/__manifest__.py index 5219c57c..86f6ef0e 100644 --- a/account_statement_import_sheet_file/__manifest__.py +++ b/account_statement_import_sheet_file/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Bank Statement TXT/CSV/XLSX Import", "summary": "Import TXT/CSV or XLSX files as Bank Statements in Odoo", - "version": "16.0.1.1.2", + "version": "17.0.1.0.0", "category": "Accounting", "website": "https://github.com/OCA/bank-statement-import", "author": "ForgeFlow, CorporateHub, Odoo Community Association (OCA)", diff --git a/account_statement_import_sheet_file/migrations/16.0.1.0.0/pre-migration.py b/account_statement_import_sheet_file/migrations/16.0.1.0.0/pre-migration.py deleted file mode 100644 index a3e5abf5..00000000 --- a/account_statement_import_sheet_file/migrations/16.0.1.0.0/pre-migration.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2023 Tecnativa - Víctor Martínez -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from openupgradelib import openupgrade - - -@openupgrade.migrate() -def migrate(env, version): - # Add amount_type column and set values to keep the same functionality as in v15 - if not openupgrade.column_exists( - env.cr, "account_statement_import_sheet_mapping", "amount_type" - ): - openupgrade.logged_query( - env.cr, - """ - ALTER TABLE account_statement_import_sheet_mapping - ADD COLUMN IF NOT EXISTS amount_type VARCHAR; - """, - ) - openupgrade.logged_query( - env.cr, - """ - UPDATE account_statement_import_sheet_mapping - SET amount_type = 'simple_value' - WHERE amount_column IS NOT NULL - """, - ) - openupgrade.logged_query( - env.cr, - """ - UPDATE account_statement_import_sheet_mapping - SET amount_type = 'distinct_credit_debit' - WHERE amount_debit_column != amount_credit_column - AND amount_debit_column IS NOT NULL - AND amount_credit_column IS NOT NULL - """, - ) - openupgrade.logged_query( - env.cr, - """ - UPDATE account_statement_import_sheet_mapping - SET amount_type = 'absolute_value' - WHERE debit_credit_column IS NOT NULL - """, - ) diff --git a/account_statement_import_sheet_file/models/account_statement_import_sheet_mapping.py b/account_statement_import_sheet_file/models/account_statement_import_sheet_mapping.py index 2db12553..acd48e98 100644 --- a/account_statement_import_sheet_file/models/account_statement_import_sheet_mapping.py +++ b/account_statement_import_sheet_file/models/account_statement_import_sheet_mapping.py @@ -63,8 +63,9 @@ class AccountStatementImportSheetMapping(models.Model): timestamp_format = fields.Char(required=True) no_header = fields.Boolean( string="File does not contain header line", - help="When this occurs please indicate the column number in the Columns section " - "instead of the column name, considering that the first column is 0", + help="When this occurs please indicate the column number in " + "the Columns section instead of the column name, considering " + "that the first column is 0", ) timestamp_column = fields.Char(required=True) currency_column = fields.Char( @@ -190,7 +191,8 @@ class AccountStatementImportSheetMapping(models.Model): elif item.amount_type == "absolute_value" and not item.debit_credit_column: raise ValidationError( _( - "Use debit_credit_column if you have set Amount type = 'Absolute value'" + "Use debit_credit_column if you have set " + "Amount type = 'Absolute value'" ) ) elif item.amount_type == "distinct_credit_debit" and ( diff --git a/account_statement_import_sheet_file/models/account_statement_import_sheet_parser.py b/account_statement_import_sheet_file/models/account_statement_import_sheet_parser.py index 7dc44934..e57cdad5 100644 --- a/account_statement_import_sheet_file/models/account_statement_import_sheet_parser.py +++ b/account_statement_import_sheet_file/models/account_statement_import_sheet_parser.py @@ -256,18 +256,18 @@ class AccountStatementImportSheetParser(models.TransientModel): else currency_code ) - def _decimal(column_name): + def _decimal(column_name, values): if columns[column_name]: return self._parse_decimal( self._get_values_from_column(values, columns, column_name), mapping, ) - amount = _decimal("amount_column") + amount = _decimal("amount_column", values) if not amount: - amount = abs(_decimal("amount_debit_column") or 0) + amount = abs(_decimal("amount_debit_column", values) or 0) if not amount: - amount = -abs(_decimal("amount_credit_column") or 0) + amount = -abs(_decimal("amount_credit_column", values) or 0) balance = ( self._get_values_from_column(values, columns, "balance_column") @@ -355,6 +355,13 @@ class AccountStatementImportSheetParser(models.TransientModel): if debit_credit == mapping.debit_value: amount = -amount + if debit_column and credit_column: + debit_amount = self._parse_decimal(debit_column, mapping) + debit_amount = abs(debit_amount) + credit_amount = self._parse_decimal(credit_column, mapping) + credit_amount = abs(credit_amount) + amount = -(credit_amount - debit_amount) + if original_amount: original_amount = math.copysign( self._parse_decimal(original_amount, mapping), amount diff --git a/account_statement_import_sheet_file/views/account_journal_views.xml b/account_statement_import_sheet_file/views/account_journal_views.xml index 92b17a96..3053d13b 100644 --- a/account_statement_import_sheet_file/views/account_journal_views.xml +++ b/account_statement_import_sheet_file/views/account_journal_views.xml @@ -5,10 +5,7 @@ - + diff --git a/account_statement_import_sheet_file/views/account_statement_import_sheet_mapping.xml b/account_statement_import_sheet_file/views/account_statement_import_sheet_mapping.xml index 49f34bc9..7ea2433a 100644 --- a/account_statement_import_sheet_file/views/account_statement_import_sheet_mapping.xml +++ b/account_statement_import_sheet_file/views/account_statement_import_sheet_mapping.xml @@ -44,24 +44,16 @@ - - - + + + @@ -84,25 +76,19 @@ @@ -110,10 +96,8 @@