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

Back merge Staging Into DEV #4351

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d404219
[hotfix] 216567 deduplication key error when deduplicating records (#…
MarekBiczysko Oct 1, 2024
e2390f7
skip trivy failure
wozniakpl Oct 1, 2024
483006d
fix document status when copy population (#4291)
pavlo-mk Oct 4, 2024
b9e36c2
block running simultaneously task with same data for enroll hhs
pkujawa Oct 10, 2024
421a6b1
reset first and last registration dates for copied repr
pkujawa Oct 10, 2024
e2808b2
fix test
pkujawa Oct 10, 2024
7994109
adjust additional tests
pkujawa Oct 10, 2024
2ddabeb
fix test
pkujawa Oct 10, 2024
fe10104
hofix_rdi_merge_deduplication
Oct 11, 2024
27dd6dd
Merge branch 'master' into hofix_rdi_merge_deduplication
MarekBiczysko Oct 11, 2024
d1d6736
Merge pull request #4314 from unicef/hofix_rdi_merge_deduplication
domdinicola Oct 11, 2024
966cc47
Merge branch 'staging' into not-allow-to-run-same-enroll-multiple-times
pkujawa Oct 14, 2024
57d8e0f
Merge branch 'staging' into not-allow-to-run-same-enroll-multiple-times
pkujawa Oct 14, 2024
2c4dce7
remove dev code
Oct 14, 2024
d681e58
fix rdi merge update collections
Oct 14, 2024
24f6d1a
Merge branch 'master' into hofix_rdi_merge_deduplication
MarekBiczysko Oct 14, 2024
c96f0db
Merge pull request #4308 from unicef/not-allow-to-run-same-enroll-mul…
pkujawa Oct 14, 2024
aa150a7
Merge pull request #4324 from unicef/hofix_rdi_merge_deduplication
domdinicola Oct 14, 2024
3aa050f
update pg
domdinicola Oct 14, 2024
6caa781
Merge pull request #4325 from unicef/cp
domdinicola Oct 14, 2024
66d37da
tweak admin
domdinicola Oct 15, 2024
89be3d8
Merge pull request #4329 from unicef/admin_pp_del_root
domdinicola Oct 15, 2024
84c4d9c
vision tweaks
domdinicola Oct 15, 2024
865307e
Merge pull request #4332 from unicef/vision
domdinicola Oct 15, 2024
9b86316
217950_Payment_Module_Getting_Delivery_Mechanism_error_when_rejecting…
Oct 15, 2024
e7cc5d5
Merge pull request #4338 from unicef/217950_Payment_Module_Getting_De…
domdinicola Oct 16, 2024
7d46efe
vision tweaks
domdinicola Oct 16, 2024
eb67393
vision tweaks
domdinicola Oct 16, 2024
0a86e53
Merge pull request #4339 from unicef/vision
domdinicola Oct 16, 2024
1d726b1
fix exclude section ids
Oct 16, 2024
ca435ec
view biometrics
Oct 16, 2024
30f61e2
Merge branch 'staging' into fixes-stg
mmaciekk Oct 16, 2024
3908f65
Merge pull request #4340 from unicef/fixes-stg
mmaciekk Oct 16, 2024
6895771
dev_fix_rdi_merge_deduplication (#4323)
MarekBiczysko Oct 15, 2024
6fbfca3
Merge pull request #4344 from unicef/stg_fix_rdi_merge_deduplication
domdinicola Oct 17, 2024
d3af6ac
conflicts
pavlo-mk Oct 17, 2024
3ab6b2a
conflicts
pavlo-mk Oct 17, 2024
c0fda46
Merge pull request #4347 from unicef/back_merge_prodINTOstg
domdinicola Oct 18, 2024
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 @@ -78,7 +78,7 @@ export const BiometricsResults = ({
}}
data-cy="button-open-biometrics-results"
>
{t('Open Biometrics Results')}
{t('View Biometrics Results')}
</Button>
</Box>
)}
Expand Down Expand Up @@ -143,9 +143,7 @@ export const BiometricsResults = ({
{t('Algorithm similarity score:')} {similarityScore}
</strong>
</div>
<div>
{t('Face images matching suggests: Duplicates')}
</div>
<div>{t('Face images matching suggests: Duplicates')}</div>
</Box>
</DialogContainer>
</DialogContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function ExcludeSection({
excludeHouseholdError,
} = paymentPlan;

const initialExcludedIds = paymentPlan?.excludedIndividuals?.map(
const initialExcludedIds = paymentPlan?.excludedHouseholds?.map(
(el) => el.unicefId,
);
const [isExclusionsOpen, setExclusionsOpen] = useState(initialOpen);
Expand All @@ -67,7 +67,7 @@ export function ExcludeSection({
const getTooltipText = (): string => {
if (!hasOpenOrLockedStatus) {
return t(
'Beneficiaries can only be excluded from a Payment Plan in status open or locked',
'Households can only be excluded from a Payment Plan in status open or locked',
);
}
if (!hasExcludePermission) {
Expand Down Expand Up @@ -115,7 +115,7 @@ export function ExcludeSection({
awaitRefetchQueries: true,
});
if (!error) {
showMessage(t('Beneficiaries exclusion started'));
showMessage(t('Households exclusion started'));
setExclusionsOpen(false);
}
} catch (e) {
Expand All @@ -125,7 +125,7 @@ export function ExcludeSection({

const handleApply = (): void => {
const idRegex =
/^(\s*IND-\d{2}-\d{4}\.\d{4}\s*)(,\s*IND-\d{2}-\d{4}\.\d{4}\s*)*$/;
/^(\s*HH-\d{2}-\d{4}\.\d{4}\s*)(,\s*HH-\d{2}-\d{4}\.\d{4}\s*)*$/;
const ids = idsValue.trim().split(/,\s*|\s+/);
const invalidIds: string[] = [];
const alreadyExcludedIds: string[] = [];
Expand Down Expand Up @@ -311,7 +311,8 @@ export function ExcludeSection({
<Grid item xs={6}>
<Box mr={2}>
<StyledTextField
label={t('Beneficiaries Ids')}
label={t('Households Ids')}
data-cy="input-households-ids"
value={idsValue}
onChange={handleIdsChange}
fullWidth
Expand Down Expand Up @@ -368,7 +369,7 @@ export function ExcludeSection({
<Box mt={2} mb={2}>
<GreyText>
{`${numberOfExcluded} ${
numberOfExcluded === 1 ? 'Beneficiary' : 'Beneficiaries'
numberOfExcluded === 1 ? 'Household' : 'Households'
} excluded`}
</GreyText>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export const VolumeByDeliveryMechanismSection: React.FC<
color={getDeliveryMechanismColor(vdm.deliveryMechanism.name)}
>
<LabelizedField
label={`${vdm.deliveryMechanism.name} (${vdm.deliveryMechanism.fsp?.name})`}
value={`${vdm.volume} ${paymentPlan.currency} (${vdm.volumeUsd} USD)`}
label={`${vdm.deliveryMechanism.name} (${vdm.deliveryMechanism.fsp?.name ?? '-'})`}
value={`${vdm.volume ?? '0.00'} ${paymentPlan.currency} (${vdm.volumeUsd ?? '0.00'} USD)`}
/>
</FieldBorder>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function ExcludeSection({
const getTooltipText = (): string => {
if (!hasOpenOrLockedStatus) {
return t(
'Households can only be excluded from a Payment Plan in status open or locked',
'Beneficiaries can only be excluded from a Payment Plan in status open or locked',
);
}
if (!hasExcludePermission) {
Expand Down Expand Up @@ -115,7 +115,7 @@ export function ExcludeSection({
awaitRefetchQueries: true,
});
if (!error) {
showMessage(t('Households exclusion started'));
showMessage(t('Beneficiaries exclusion started'));
setExclusionsOpen(false);
}
} catch (e) {
Expand All @@ -125,7 +125,7 @@ export function ExcludeSection({

const handleApply = (): void => {
const idRegex =
/^(\s*HH-\d{2}-\d{4}\.\d{4}\s*)(,\s*HH-\d{2}-\d{4}\.\d{4}\s*)*$/;
/^(\s*IND-\d{2}-\d{4}\.\d{4}\s*)(,\s*IND-\d{2}-\d{4}\.\d{4}\s*)*$/;
const ids = idsValue.trim().split(/,\s*|\s+/);
const invalidIds: string[] = [];
const alreadyExcludedIds: string[] = [];
Expand Down Expand Up @@ -311,7 +311,8 @@ export function ExcludeSection({
<Grid item xs={6}>
<Box mr={2}>
<StyledTextField
label={t('Household Ids')}
label={t('Beneficiaries Ids')}
data-cy="input-beneficiaries-ids"
value={idsValue}
onChange={handleIdsChange}
fullWidth
Expand Down Expand Up @@ -368,7 +369,7 @@ export function ExcludeSection({
<Box mt={2} mb={2}>
<GreyText>
{`${numberOfExcluded} ${
numberOfExcluded === 1 ? 'Household' : 'Households'
numberOfExcluded === 1 ? 'Beneficiary' : 'Beneficiaries'
} excluded`}
</GreyText>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export const VolumeByDeliveryMechanismSection: React.FC<
color={getDeliveryMechanismColor(vdm.deliveryMechanism.name)}
>
<LabelizedField
label={`${vdm.deliveryMechanism.name} (${vdm.deliveryMechanism.fsp?.name})`}
value={`${vdm.volume} ${paymentPlan.currency} (${vdm.volumeUsd} USD)`}
label={`${vdm.deliveryMechanism.name} (${vdm.deliveryMechanism.fsp?.name ?? '-'})`}
value={`${vdm.volume ?? '0.00'} ${paymentPlan.currency} (${vdm.volumeUsd ?? '0.00'} USD)`}
/>
</FieldBorder>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function EditFollowUpSetUpFspPage(): React.ReactElement {

const mappedInitialDeliveryMechanisms =
paymentPlanData.paymentPlan.deliveryMechanisms.map((el) => ({
deliveryMechanism: el.name,
deliveryMechanism: el.code,
fsp: el.fsp?.id || '',
chosenConfiguration: el.chosenConfiguration || '',
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const EditPeopleFollowUpSetUpFspPage = (): React.ReactElement => {

const mappedInitialDeliveryMechanisms =
paymentPlanData.paymentPlan.deliveryMechanisms.map((el) => ({
deliveryMechanism: el.name,
deliveryMechanism: el.code,
fsp: el.fsp?.id || '',
chosenConfiguration: el.chosenConfiguration || '',
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const EditPeopleSetUpFspPage = (): React.ReactElement => {

const mappedInitialDeliveryMechanisms =
paymentPlanData.paymentPlan.deliveryMechanisms.map((el) => ({
deliveryMechanism: el.name,
deliveryMechanism: el.code,
fsp: el.fsp?.id || '',
chosenConfiguration: el.chosenConfiguration || '',
}));
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/utils/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -907,5 +907,6 @@
"You cannot upload more than 10 files.": "You cannot upload more than 10 files.",
"File deleted successfully.": "File deleted successfully.",
"FX Rate Applied": "FX Rate Applied",
"If displayed exchange rate differs from Vision, please contact your designated focal point for resolutionIf displayed exchange rate differs from Vision, please contact your designated focal point for resolution": "If displayed exchange rate differs from Vision, please contact your designated focal point for resolution"
"If displayed exchange rate differs from Vision, please contact your designated focal point for resolution. If displayed exchange rate differs from Vision, please contact your designated focal point for resolution": "If displayed exchange rate differs from Vision, please contact your designated focal point for resolution",
"View Biometrics Results": "View Biometrics Results"
}
35 changes: 27 additions & 8 deletions src/hct_mis_api/apps/household/celery_tasks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import hashlib
import json
import logging
from typing import List, Optional
from uuid import UUID

from django.core.cache import cache
from django.core.paginator import Paginator
from django.db import transaction
from django.utils import timezone
Expand Down Expand Up @@ -204,14 +207,30 @@ def revalidate_phone_number_task(individual_ids: List[UUID]) -> None:
@log_start_and_end
@sentry_tags
def enroll_households_to_program_task(households_ids: List, program_for_enroll_id: str, user_id: str) -> None:
households = Household.objects.filter(pk__in=households_ids)
program_for_enroll = Program.objects.get(id=program_for_enroll_id)
enroll_households_to_program(households, program_for_enroll, user_id)
populate_index(
Individual.objects.filter(program=program_for_enroll),
get_individual_doc(program_for_enroll.business_area.slug),
)
populate_index(Household.objects.filter(program=program_for_enroll), HouseholdDocument)
task_params = {
"task_name": "enroll_households_to_program_task",
"household_ids": sorted([str(household_id) for household_id in households_ids]),
"program_for_enroll_id": program_for_enroll_id,
}
task_params_str = json.dumps(task_params, sort_keys=True)
cache_key = hashlib.sha256(task_params_str.encode()).hexdigest()
if cache.get(cache_key):
logger.info("Task enroll_households_to_program_task with this data is already running.")
return

# 1 day timeout
cache.set(cache_key, True, timeout=24 * 60 * 60)
try:
households = Household.objects.filter(pk__in=households_ids)
program_for_enroll = Program.objects.get(id=program_for_enroll_id)
enroll_households_to_program(households, program_for_enroll, user_id)
populate_index(
Individual.objects.filter(program=program_for_enroll),
get_individual_doc(program_for_enroll.business_area.slug),
)
populate_index(Household.objects.filter(program=program_for_enroll), HouseholdDocument)
finally:
cache.delete(cache_key)


@app.task()
Expand Down
3 changes: 2 additions & 1 deletion src/hct_mis_api/apps/payment/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
VerificationPlanStatusChangeServices,
)
from hct_mis_api.apps.utils.admin import HOPEModelAdminBase, PaymentPlanCeleryTasksMixin
from hct_mis_api.apps.utils.security import is_root

if TYPE_CHECKING:
from uuid import UUID
Expand Down Expand Up @@ -262,7 +263,7 @@ class PaymentPlanAdmin(HOPEModelAdminBase, PaymentPlanCeleryTasksMixin):
search_fields = ("id", "unicef_id")

def has_delete_permission(self, request: HttpRequest, obj: Optional[Any] = None) -> bool:
return False
return is_root(request)


class PaymentHouseholdSnapshotInline(admin.StackedInline):
Expand Down
9 changes: 9 additions & 0 deletions src/hct_mis_api/apps/program/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.conf import settings
from django.db import transaction
from django.db.models import Q, QuerySet
from django.utils import timezone

from hct_mis_api.apps.account.models import Partner, User
from hct_mis_api.apps.core.models import DataCollectingType, FlexibleAttribute
Expand Down Expand Up @@ -109,6 +110,8 @@ def copy_individual(self, individual: Individual) -> Individual:
individual.program = self.program
individual.copied_from_id = copied_from_pk
individual.registration_data_import = self.rdi
individual.first_registration_date = timezone.now()
individual.last_registration_date = timezone.now()
individual.rdi_merge_status = self.rdi_merge_status
return individual

Expand All @@ -135,6 +138,8 @@ def copy_household(self, household: Household, new_individuals: List[Individual]
household.program = self.program
household.total_cash_received = None
household.total_cash_received_usd = None
household.first_registration_date = timezone.now()
household.last_registration_date = timezone.now()
household.copied_from_id = copy_from_household_id
household.registration_data_import = self.rdi
household.rdi_merge_status = self.rdi_merge_status
Expand Down Expand Up @@ -456,6 +461,8 @@ def enroll_households_to_program(households: QuerySet, program: Program, user_id
household.registration_data_import = rdi
household.total_cash_received = None
household.total_cash_received_usd = None
household.first_registration_date = timezone.now()
household.last_registration_date = timezone.now()

if original_head_of_household_unicef_id in individuals_dict:
household.head_of_household = individuals_dict[original_head_of_household_unicef_id]
Expand Down Expand Up @@ -506,6 +513,8 @@ def copy_individual(individual: Individual, program: Program, rdi: RegistrationD
individual.program = program
individual.household = None
individual.registration_data_import = rdi
individual.first_registration_date = timezone.now()
individual.last_registration_date = timezone.now()

documents_to_create = CopyProgramPopulation.copy_document_per_individual(documents, individual)
identities_to_create = CopyProgramPopulation.copy_individual_identity_per_individual(identities, individual)
Expand Down
37 changes: 0 additions & 37 deletions src/hct_mis_api/apps/registration_datahub/celery_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,26 +482,6 @@ def deduplication_engine_process(self: Any, program_id: str) -> None:
raise


@app.task(bind=True, default_retry_delay=60, max_retries=3)
@sentry_tags
@log_start_and_end
def create_grievance_tickets_for_dedup_engine_results(self: Any, rdi_id: str) -> None:
from hct_mis_api.apps.registration_datahub.services.biometric_deduplication import (
BiometricDeduplicationService,
)

rdi = RegistrationDataImport.objects.get(id=rdi_id)
program = Program.objects.get(id=rdi.program_id)
set_sentry_business_area_tag(program.business_area.name)

try:
rdi = RegistrationDataImport.objects.get(id=rdi_id)
BiometricDeduplicationService().create_grievance_tickets_for_duplicates(rdi)
except Exception as e:
logger.exception(e)
raise


@app.task(bind=True, default_retry_delay=60, max_retries=3)
@log_start_and_end
@sentry_tags
Expand All @@ -523,20 +503,3 @@ def fetch_biometric_deduplication_results_and_process(self: Any, deduplication_s
except Exception as e:
logger.exception(e)
raise


@app.task(bind=True, default_retry_delay=60, max_retries=3)
@sentry_tags
@log_start_and_end
def update_rdis_deduplication_engine_statistics(self: Any, program_id: str) -> None:
from hct_mis_api.apps.registration_datahub.services.biometric_deduplication import (
BiometricDeduplicationService,
)

program = Program.objects.get(id=program_id)
set_sentry_business_area_tag(program.business_area.name)
try:
BiometricDeduplicationService().update_rdis_deduplication_statistics(program_id)
except Exception as e:
logger.exception(e)
raise
Loading
Loading