Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Cleanup empty rows on bank statement import #29366

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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