Skip to content

Commit

Permalink
Merge pull request #29370 from frappe/mergify/bp/version-13-pre-relea…
Browse files Browse the repository at this point in the history
…se/pr-29366

fix: Cleanup empty rows on bank statement import (backport #29366)
  • Loading branch information
deepeshgarg007 authored Jan 20, 2022
2 parents 56dd253 + 6a53cfe commit 84803f8
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from openpyxl.utils import get_column_letter
from six import string_types

INVALID_VALUES = ("", None)

class BankStatementImport(DataImport):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -96,6 +97,18 @@ def download_errored_template(data_import_name):
data_import = frappe.get_doc("Bank Statement Import", data_import_name)
data_import.export_errored_rows()

def parse_data_from_template(raw_data):
data = []

for i, row in enumerate(raw_data):
if all(v in INVALID_VALUES for v in row):
# empty row
continue

data.append(row)

return data

def start_import(data_import, bank_account, import_file_path, google_sheets_url, bank, template_options):
"""This method runs in background job"""

Expand All @@ -105,7 +118,8 @@ def start_import(data_import, bank_account, import_file_path, google_sheets_url,
file = import_file_path if import_file_path else google_sheets_url

import_file = ImportFile("Bank Transaction", file = file, import_type="Insert New Records")
data = import_file.raw_data

data = parse_data_from_template(import_file.raw_data)

if import_file_path:
add_bank_account(data, bank_account)
Expand Down

0 comments on commit 84803f8

Please sign in to comment.