From cb751743be65fc8abed2038022acc84c75f44646 Mon Sep 17 00:00:00 2001 From: "matthieu.saison" Date: Thu, 5 Sep 2024 17:03:54 +0200 Subject: [PATCH] add offsetheader --- .../models/account_statement_import_sheet_mapping.py | 5 +++++ .../models/account_statement_import_sheet_parser.py | 5 +++++ .../views/account_statement_import_sheet_mapping.xml | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/account_statement_import_txt_xlsx/models/account_statement_import_sheet_mapping.py b/account_statement_import_txt_xlsx/models/account_statement_import_sheet_mapping.py index a0a9e26fb..adae071c2 100644 --- a/account_statement_import_txt_xlsx/models/account_statement_import_sheet_mapping.py +++ b/account_statement_import_txt_xlsx/models/account_statement_import_sheet_mapping.py @@ -62,6 +62,11 @@ class AccountStatementImportSheetMapping(models.Model): 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", ) + offset_header = fields.Integer( + "Offset Header", + default=0, + help="Number of row to ignore until the header", + ) skip_empty_lines = fields.Boolean( "Skip Empty Lines", default=False, diff --git a/account_statement_import_txt_xlsx/models/account_statement_import_sheet_parser.py b/account_statement_import_txt_xlsx/models/account_statement_import_sheet_parser.py index 1d56b6ab8..29d87dcbd 100644 --- a/account_statement_import_txt_xlsx/models/account_statement_import_sheet_parser.py +++ b/account_statement_import_txt_xlsx/models/account_statement_import_sheet_parser.py @@ -168,6 +168,11 @@ def _parse_lines(self, mapping, data_file, currency_code): decoded_file = data_file.decode(detected_encoding) csv_or_xlsx = reader(StringIO(decoded_file), **csv_options) header = False + + if mapping.offset_header: + for _row in range(mapping.offset_header): + next(csv_or_xlsx) + if not mapping.no_header: if isinstance(csv_or_xlsx, tuple): header = [ diff --git a/account_statement_import_txt_xlsx/views/account_statement_import_sheet_mapping.xml b/account_statement_import_txt_xlsx/views/account_statement_import_sheet_mapping.xml index 0ab58c800..d4144ee02 100644 --- a/account_statement_import_txt_xlsx/views/account_statement_import_sheet_mapping.xml +++ b/account_statement_import_txt_xlsx/views/account_statement_import_sheet_mapping.xml @@ -59,6 +59,10 @@ name="offset_row" attrs="{'invisible': [('no_header', '=', True)]}" /> +