mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[MIG] account_statement_import_sheet_file: Migration to 17.0
This commit is contained in:
@@ -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)",
|
||||
|
||||
@@ -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
|
||||
""",
|
||||
)
|
||||
@@ -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 (
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -5,10 +5,7 @@
|
||||
<field name="inherit_id" ref="account.view_account_journal_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//page[@name='advanced_settings']/group" position="inside">
|
||||
<group
|
||||
string="Statement Import Map"
|
||||
attrs="{'invisible': [('type','!=','bank')]}"
|
||||
>
|
||||
<group string="Statement Import Map" invisible="type != 'bank'">
|
||||
<field name="default_sheet_mapping_id" />
|
||||
</group>
|
||||
</xpath>
|
||||
|
||||
@@ -44,24 +44,16 @@
|
||||
<div
|
||||
class="alert alert-warning"
|
||||
role="alert"
|
||||
attrs="{'invisible': [('no_header', '=', False)]}"
|
||||
invisible="not no_header"
|
||||
>
|
||||
<span
|
||||
class="fa fa-info-circle"
|
||||
/> indicate the column number in the Columns section. The first column is 0.
|
||||
</div>
|
||||
</group>
|
||||
<group
|
||||
attrs="{'invisible': [('debit_credit_column', '=', False)]}"
|
||||
>
|
||||
<field
|
||||
name="debit_value"
|
||||
attrs="{'required': [('debit_credit_column', '!=', False)]}"
|
||||
/>
|
||||
<field
|
||||
name="credit_value"
|
||||
attrs="{'required': [('debit_credit_column', '!=', False)]}"
|
||||
/>
|
||||
<group invisible="not debit_credit_column">
|
||||
<field name="debit_value" required="debit_credit_column" />
|
||||
<field name="credit_value" required="debit_credit_column" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="header_lines_skip_count" />
|
||||
@@ -84,25 +76,19 @@
|
||||
<field name="amount_type" />
|
||||
<field
|
||||
name="amount_column"
|
||||
attrs="{
|
||||
'required': [('amount_type', '!=', 'distinct_credit_debit'),],
|
||||
'invisible': [('amount_type', '=', 'distinct_credit_debit')],
|
||||
}"
|
||||
invisible="amount_type == 'distinct_credit_debit'"
|
||||
required="amount_type != 'distinct_credit_debit'"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="amount_debit_column"
|
||||
attrs="{
|
||||
'required': [('amount_type', '=', 'distinct_credit_debit')],
|
||||
'invisible': [('amount_type', '!=', 'distinct_credit_debit')],
|
||||
}"
|
||||
invisible="amount_type != 'distinct_credit_debit'"
|
||||
required="amount_type == 'distinct_credit_debit'"
|
||||
/>
|
||||
<field
|
||||
name="amount_credit_column"
|
||||
attrs="{
|
||||
'required': [('amount_type', '=', 'distinct_credit_debit')],
|
||||
'invisible': [('amount_type', '!=', 'distinct_credit_debit')],
|
||||
}"
|
||||
invisible="amount_type != 'distinct_credit_debit'"
|
||||
required="amount_type == 'distinct_credit_debit'"
|
||||
/>
|
||||
<field name="amount_inverse_sign" />
|
||||
<field name="balance_column" />
|
||||
@@ -110,10 +96,8 @@
|
||||
<field name="original_amount_column" />
|
||||
<field
|
||||
name="debit_credit_column"
|
||||
attrs="{
|
||||
'required': [('amount_type', '=', 'absolute_value')],
|
||||
'invisible': [('amount_type', '!=', 'absolute_value')],
|
||||
}"
|
||||
invisible="amount_type != 'absolute_value'"
|
||||
required="amount_type == 'absolute_value'"
|
||||
/>
|
||||
<field name="transaction_id_column" />
|
||||
<field name="description_column" />
|
||||
|
||||
Reference in New Issue
Block a user