-
-
Notifications
You must be signed in to change notification settings - Fork 222
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
zandre-eng
wants to merge
9
commits into
master
Choose a base branch
from
ze/case-import-payment-validation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+105
−7
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
16c0438
create feature flag
zandre-eng 4b7401b
validate required fields exist
zandre-eng 80fb505
validate required fields exist for bulk import
zandre-eng 24971cd
validate field values
zandre-eng 926eb08
minor text update
zandre-eng 9da1701
fix translation formatting
zandre-eng d1d68f2
update ff name
zandre-eng 523002f
update function name
zandre-eng 36a93de
use sets to check for missing fields
zandre-eng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,13 +29,19 @@ | |
BULK_UPLOAD_DATE_OPENED, | ||
CASE_IMPORT_DATA_DICTIONARY_VALIDATION, | ||
DOMAIN_PERMISSIONS_MIRROR, | ||
MOBILE_WORKER_VERIFICATION, | ||
) | ||
from corehq.util.metrics import metrics_counter, metrics_histogram | ||
from corehq.util.metrics.load_counters import case_load_counter | ||
from corehq.util.soft_assert import soft_assert | ||
from corehq.util.timer import TimingContext | ||
|
||
from .const import LookupErrors | ||
from .const import ( | ||
LookupErrors, | ||
MOMO_REQUIRED_PAYMENT_FIELDS, | ||
MOMO_NO_EDIT_PAYMENT_FIELDS, | ||
MOMO_PAYMENT_CASE_TYPE, | ||
) | ||
from .exceptions import ( | ||
BlankExternalId, | ||
CaseGeneration, | ||
|
@@ -169,6 +175,12 @@ def _do_import(self, spreadsheet): | |
def import_row(self, row_num, raw_row, import_context): | ||
search_id = self._parse_search_id(raw_row) | ||
fields_to_update = self._populate_updated_fields(raw_row) | ||
if ( | ||
self.mobile_worker_verification_ff_enabled | ||
and self.submission_handler.case_type == MOMO_PAYMENT_CASE_TYPE | ||
): | ||
self._validate_payment_fields(fields_to_update) | ||
|
||
if self._has_custom_case_import_operations(): | ||
fields_to_update = self._perform_custom_case_import_operations( | ||
row_num, | ||
|
@@ -207,6 +219,29 @@ def import_row(self, row_num, raw_row, import_context): | |
|
||
self.submission_handler.add_caseblock(RowAndCase(row_num, caseblock)) | ||
|
||
def _validate_payment_fields(self, fields): | ||
errors = [] | ||
for field_name in MOMO_NO_EDIT_PAYMENT_FIELDS: | ||
if fields.get(field_name): | ||
errors.append(CaseRowError( | ||
column_name=field_name, | ||
message=_( | ||
'This field value cannot be set for cases with the ' | ||
'"{}" case type.'.format(MOMO_PAYMENT_CASE_TYPE) | ||
), | ||
)) | ||
for field_name in MOMO_REQUIRED_PAYMENT_FIELDS: | ||
if field_name not in fields or not fields[field_name]: | ||
errors.append(CaseRowError( | ||
column_name=field_name, | ||
message=_( | ||
'This field requires a value for cases with the ' | ||
'"{}" case type.'.format(MOMO_PAYMENT_CASE_TYPE) | ||
), | ||
)) | ||
if any(errors): | ||
raise CaseRowErrorList(errors) | ||
|
||
def _has_custom_case_import_operations(self): | ||
return any( | ||
extension.should_call_for_domain(self.domain) | ||
|
@@ -227,6 +262,10 @@ def _perform_custom_case_import_operations(self, row_num, raw_row, fields_to_upd | |
def user(self): | ||
return CouchUser.get_by_user_id(self.config.couch_user_id) | ||
|
||
@cached_property | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
def mobile_worker_verification_ff_enabled(self): | ||
return MOBILE_WORKER_VERIFICATION.enabled(self.domain) | ||
|
||
def _parse_search_id(self, row): | ||
""" Find and convert the search id in an Excel row """ | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason for this check to be during import and not earlier when uploading file?
is it because this could take really long so we don't want to do it then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main motivation for doing it here is that this is the part in the import where we're looping through all the sheet rows, and so we're able to easily see if there are cell values with empty required fields.
Doing this at an earlier point would mean we would have to do an extra loop through all the rows to validate their values which felt unnecessary. Additionally, failing it here simply results in the row not getting imported. This therefore then doesn't block the entire import and other rows can still get imported if they're valid.