Merge PR #760 into 16.0

Signed-off-by pedrobaeza
This commit is contained in:
OCA-git-bot
2025-01-13 15:42:18 +00:00
2 changed files with 18 additions and 29 deletions

View File

@@ -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
@@ -177,19 +177,7 @@ class AccountStatementImportSheetParser(models.TransientModel):
) 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

View File

@@ -44,6 +44,7 @@
<div
class="alert alert-warning"
role="alert"
colspan="2"
attrs="{'invisible': [('no_header', '=', False)]}"
>
<span