Skip to content

Commit

Permalink
[MIG] account_statement_import_sheet_file: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rov-adhoc committed May 7, 2024
1 parent 9e7a6e6 commit 0dbf4d4
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 85 deletions.
2 changes: 1 addition & 1 deletion account_statement_import_sheet_file/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.0.0",
"version": "17.0.1.0.0",
"category": "Accounting",
"website": "https://github.com/OCA/bank-statement-import",
"author": "ForgeFlow, CorporateHub, Odoo Community Association (OCA)",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,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(
Expand Down Expand Up @@ -178,7 +179,8 @@ def _check_amount_type(self):
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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,18 @@ def _parse_rows(self, mapping, currency_code, data, columns): # noqa: C901
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")
Expand Down Expand Up @@ -320,6 +320,18 @@ def _decimal(column_name):
else None
)

debit_column = (
self._get_values_from_column(values, columns, "amount_debit_column")
if columns["amount_debit_column"]
else None
)

credit_column = (
self._get_values_from_column(values, columns, "amount_credit_column")
if columns["amount_credit_column"]
else None
)

if currency != currency_code:
continue

Expand All @@ -336,6 +348,13 @@ def _decimal(column_name):
if debit_credit == mapping.debit_value:
amount = -amount

if debit_column and credit_column:
debit_amount = self._parse_decimal(debit_column, mapping)
debit_amount = debit_amount.copy_abs()
credit_amount = self._parse_decimal(credit_column, mapping)
credit_amount = credit_amount.copy_abs()
amount = -(credit_amount - debit_amount)

if original_amount:
original_amount = self._parse_decimal(
original_amount, mapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand All @@ -84,34 +76,26 @@
<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="balance_column" />
<field name="original_currency_column" />
<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" />
Expand Down

0 comments on commit 0dbf4d4

Please sign in to comment.