[MIG] account_statement_import_sheet_file: Migration to 17.0

This commit is contained in:
Rocío Vega
2023-12-27 10:54:17 -03:00
parent 0967843644
commit 3566322c09
6 changed files with 30 additions and 85 deletions

View File

@@ -5,7 +5,7 @@
{ {
"name": "Bank Statement TXT/CSV/XLSX Import", "name": "Bank Statement TXT/CSV/XLSX Import",
"summary": "Import TXT/CSV or XLSX files as Bank Statements in Odoo", "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", "category": "Accounting",
"website": "https://github.com/OCA/bank-statement-import", "website": "https://github.com/OCA/bank-statement-import",
"author": "ForgeFlow, CorporateHub, Odoo Community Association (OCA)", "author": "ForgeFlow, CorporateHub, Odoo Community Association (OCA)",

View File

@@ -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
""",
)

View File

@@ -63,8 +63,9 @@ class AccountStatementImportSheetMapping(models.Model):
timestamp_format = fields.Char(required=True) timestamp_format = fields.Char(required=True)
no_header = fields.Boolean( no_header = fields.Boolean(
string="File does not contain header line", string="File does not contain header line",
help="When this occurs please indicate the column number in the Columns section " help="When this occurs please indicate the column number in "
"instead of the column name, considering that the first column is 0", "the Columns section instead of the column name, considering "
"that the first column is 0",
) )
timestamp_column = fields.Char(required=True) timestamp_column = fields.Char(required=True)
currency_column = fields.Char( currency_column = fields.Char(
@@ -190,7 +191,8 @@ class AccountStatementImportSheetMapping(models.Model):
elif item.amount_type == "absolute_value" and not item.debit_credit_column: elif item.amount_type == "absolute_value" and not item.debit_credit_column:
raise ValidationError( 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 ( elif item.amount_type == "distinct_credit_debit" and (

View File

@@ -256,18 +256,18 @@ class AccountStatementImportSheetParser(models.TransientModel):
else currency_code else currency_code
) )
def _decimal(column_name): def _decimal(column_name, values):
if columns[column_name]: if columns[column_name]:
return self._parse_decimal( return self._parse_decimal(
self._get_values_from_column(values, columns, column_name), self._get_values_from_column(values, columns, column_name),
mapping, mapping,
) )
amount = _decimal("amount_column") amount = _decimal("amount_column", values)
if not amount: if not amount:
amount = abs(_decimal("amount_debit_column") or 0) amount = abs(_decimal("amount_debit_column", values) or 0)
if not amount: if not amount:
amount = -abs(_decimal("amount_credit_column") or 0) amount = -abs(_decimal("amount_credit_column", values) or 0)
balance = ( balance = (
self._get_values_from_column(values, columns, "balance_column") self._get_values_from_column(values, columns, "balance_column")
@@ -355,6 +355,13 @@ class AccountStatementImportSheetParser(models.TransientModel):
if debit_credit == mapping.debit_value: if debit_credit == mapping.debit_value:
amount = -amount 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: if original_amount:
original_amount = math.copysign( original_amount = math.copysign(
self._parse_decimal(original_amount, mapping), amount self._parse_decimal(original_amount, mapping), amount

View File

@@ -5,10 +5,7 @@
<field name="inherit_id" ref="account.view_account_journal_form" /> <field name="inherit_id" ref="account.view_account_journal_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//page[@name='advanced_settings']/group" position="inside"> <xpath expr="//page[@name='advanced_settings']/group" position="inside">
<group <group string="Statement Import Map" invisible="type != 'bank'">
string="Statement Import Map"
attrs="{'invisible': [('type','!=','bank')]}"
>
<field name="default_sheet_mapping_id" /> <field name="default_sheet_mapping_id" />
</group> </group>
</xpath> </xpath>

View File

@@ -44,24 +44,16 @@
<div <div
class="alert alert-warning" class="alert alert-warning"
role="alert" role="alert"
attrs="{'invisible': [('no_header', '=', False)]}" invisible="not no_header"
> >
<span <span
class="fa fa-info-circle" class="fa fa-info-circle"
/> indicate the column number in the Columns section. The first column is 0. /> indicate the column number in the Columns section. The first column is 0.
</div> </div>
</group> </group>
<group <group invisible="not debit_credit_column">
attrs="{'invisible': [('debit_credit_column', '=', False)]}" <field name="debit_value" required="debit_credit_column" />
> <field name="credit_value" required="debit_credit_column" />
<field
name="debit_value"
attrs="{'required': [('debit_credit_column', '!=', False)]}"
/>
<field
name="credit_value"
attrs="{'required': [('debit_credit_column', '!=', False)]}"
/>
</group> </group>
<group> <group>
<field name="header_lines_skip_count" /> <field name="header_lines_skip_count" />
@@ -84,25 +76,19 @@
<field name="amount_type" /> <field name="amount_type" />
<field <field
name="amount_column" name="amount_column"
attrs="{ invisible="amount_type == 'distinct_credit_debit'"
'required': [('amount_type', '!=', 'distinct_credit_debit'),], required="amount_type != 'distinct_credit_debit'"
'invisible': [('amount_type', '=', 'distinct_credit_debit')],
}"
/> />
<field <field
name="amount_debit_column" name="amount_debit_column"
attrs="{ invisible="amount_type != 'distinct_credit_debit'"
'required': [('amount_type', '=', 'distinct_credit_debit')], required="amount_type == 'distinct_credit_debit'"
'invisible': [('amount_type', '!=', 'distinct_credit_debit')],
}"
/> />
<field <field
name="amount_credit_column" name="amount_credit_column"
attrs="{ invisible="amount_type != 'distinct_credit_debit'"
'required': [('amount_type', '=', 'distinct_credit_debit')], required="amount_type == 'distinct_credit_debit'"
'invisible': [('amount_type', '!=', 'distinct_credit_debit')],
}"
/> />
<field name="amount_inverse_sign" /> <field name="amount_inverse_sign" />
<field name="balance_column" /> <field name="balance_column" />
@@ -110,10 +96,8 @@
<field name="original_amount_column" /> <field name="original_amount_column" />
<field <field
name="debit_credit_column" name="debit_credit_column"
attrs="{ invisible="amount_type != 'absolute_value'"
'required': [('amount_type', '=', 'absolute_value')], required="amount_type == 'absolute_value'"
'invisible': [('amount_type', '!=', 'absolute_value')],
}"
/> />
<field name="transaction_id_column" /> <field name="transaction_id_column" />
<field name="description_column" /> <field name="description_column" />