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

Case Import Payment Validation #35803

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
22 changes: 19 additions & 3 deletions corehq/apps/case_importer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ def _process_excel_mapping(domain, spreadsheet, search_column):
def _create_bulk_configs(domain, request, case_upload):
all_configs = []
worksheet_titles = _get_workbook_sheet_names(case_upload)
mobile_worker_verification_ff_enabled = MOBILE_WORKER_VERIFICATION.enabled(domain)
errors = []
for index, title in enumerate(worksheet_titles):
with case_upload.get_spreadsheet(index) as spreadsheet:
_, excel_fields, _ = _process_excel_mapping(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double underscores!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah these were changed to double underscores otherwise they overshadow the gettext import which is imported as _.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think the double underscores don't look right, I can always change these to have variable names instead 🤔

Expand All @@ -301,6 +303,16 @@ def _create_bulk_configs(domain, request, case_upload):
request.POST['search_field']
)
excel_fields = list(set(excel_fields) - set(RESERVED_FIELDS))
if mobile_worker_verification_ff_enabled and title == MOMO_PAYMENT_CASE_TYPE:
missing_fields = _check_payment_fields_exist(excel_fields)
if missing_fields:
errors.append(_(
'Sheet with case type "{}" is missing one or more required '
'fields: {}'.format(
title, ', '.join(missing_fields)
)
))
break
config = importer_util.ImporterConfig.from_dict({
'couch_user_id': request.couch_user._id,
'excel_fields': excel_fields,
Expand All @@ -312,7 +324,7 @@ def _create_bulk_configs(domain, request, case_upload):
'create_new_cases': request.POST['create_new_cases'] == 'True',
})
all_configs.append(config)
return all_configs
return all_configs, errors


@require_POST
Expand Down Expand Up @@ -433,7 +445,9 @@ def excel_commit(request, domain):
case_type = request.POST['case_type']
all_configs = []
if case_type == ALL_CASE_TYPE_IMPORT:
all_configs = _create_bulk_configs(domain, request, case_upload)
all_configs, errors = _create_bulk_configs(domain, request, case_upload)
if any(errors):
return render_error(request, domain, ', '.join(errors))
else:
config = importer_util.ImporterConfig.from_request(request)
all_configs = [config]
Expand Down Expand Up @@ -495,7 +509,9 @@ def _bulk_case_upload_api(request, domain):

all_configs = []
if context['is_bulk_import']:
all_configs = _create_bulk_configs(domain, request, case_upload)
all_configs, errors = _create_bulk_configs(domain, request, case_upload)
if any(errors):
raise ImporterError(', '.join(errors))
else:
with case_upload.get_spreadsheet() as spreadsheet:
_, excel_fields, _ = _process_excel_mapping(domain, spreadsheet, search_column)
Expand Down