Skip to content

Commit

Permalink
Merge PR #760 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Jan 13, 2025
2 parents 2298d49 + 6deab7c commit d318ba1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ class AccountStatementImportSheetParser(models.TransientModel):
_description = "Bank Statement Import Sheet Parser"

@api.model
def parse_header(self, data_file, encoding, csv_options, header_lines_skip_count=0):
try:
workbook = xlrd.open_workbook(
file_contents=data_file,
encoding_override=encoding if encoding else None,
)
sheet = workbook.sheet_by_index(0)
values = sheet.row_values(header_lines_skip_count - 1)
return [str(value) for value in values]
except xlrd.XLRDError:
_logger.error("Pass this method")

data = StringIO(data_file.decode(encoding or "utf-8"))
csv_data = reader(data, **csv_options)
csv_data_lst = list(csv_data)
header = [value.strip() for value in csv_data_lst[header_lines_skip_count - 1]]
def parse_header(self, csv_or_xlsx, mapping):
if mapping.no_header:
return []
header_line = mapping.header_lines_skip_count
# prevent negative indexes
if header_line > 0:
header_line -= 1
if isinstance(csv_or_xlsx, tuple):
header = [
str(value).strip() for value in csv_or_xlsx[1].row_values(header_line)
]
else:
[next(csv_or_xlsx) for _i in range(header_line)]
header = [value.strip() for value in next(csv_or_xlsx)]
if mapping.offset_column:
header = header[mapping.offset_column :]
return header

@api.model
Expand Down Expand Up @@ -177,19 +177,7 @@ def _parse_lines(self, mapping, data_file, currency_code):
) from None
decoded_file = data_file.decode(detected_encoding)
csv_or_xlsx = reader(StringIO(decoded_file), **csv_options)
header = False
if not mapping.no_header:
header_line = mapping.header_lines_skip_count - 1
if isinstance(csv_or_xlsx, tuple):
header = [
str(value).strip()
for value in csv_or_xlsx[1].row_values(header_line)
]
else:
[next(csv_or_xlsx) for _i in range(header_line)]
header = [value.strip() for value in next(csv_or_xlsx)]
if mapping.offset_column:
header = header[mapping.offset_column :]
header = self.parse_header(csv_or_xlsx, mapping)

# NOTE no seria necesario debit_column y credit_column ya que tenemos los
# respectivos campos related
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<div
class="alert alert-warning"
role="alert"
colspan="2"
attrs="{'invisible': [('no_header', '=', False)]}"
>
<span
Expand Down

0 comments on commit d318ba1

Please sign in to comment.