Skip to content

Commit

Permalink
Merge pull request #3853 from unicef/develop
Browse files Browse the repository at this point in the history
Staging with peoples enh
  • Loading branch information
johniak authored May 10, 2024
2 parents e3bb55d + 1949fda commit b038e70
Show file tree
Hide file tree
Showing 328 changed files with 20,083 additions and 691 deletions.
2 changes: 1 addition & 1 deletion backend/.coveragerc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[run]
branch = True
source = hct_mis_api
concurrency=multiprocessing
concurrency=multiprocessing,thread

omit =
*/selenium_tests/**
Expand Down
213 changes: 141 additions & 72 deletions backend/hct_mis_api/apps/core/attributes_qet_queries.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,7 @@ def __init__(
super().__init__(*args, **kwargs)
self.scopes: Iterable = scopes or set()
if fields:
self.extend(fields)
self.extend(copy.deepcopy(fields))
self.all_fields = copy.deepcopy(CORE_FIELDS_ATTRIBUTES)

def extend(self, __iterable: Iterable[dict]) -> None:
Expand Down Expand Up @@ -1865,11 +1865,22 @@ def _fill_label_template(self, field: dict, language: str = "English(EN)") -> Op
def from_scopes(cls, scopes: list[Scope]) -> "FieldFactory":
factory = cls()
all_fields = copy.deepcopy(factory.all_fields)
factory.scopes.update(scopes)
factory.extend(filter(lambda field: any(True for scope in scopes if scope in field["scope"]), all_fields))
if Scope.XLSX_PEOPLE in scopes:
for field_attr in factory:
field_attr["xlsx_field"] = "pp_" + field_attr["xlsx_field"].replace("_h_c", "_i_c")
return factory

@classmethod
def from_only_scopes(cls, scopes: list[Scope]) -> "FieldFactory":
factory = cls()
all_fields = copy.deepcopy(factory.all_fields)
factory.scopes.update(scopes)
factory.extend(filter(lambda field: all(scope in field["scope"] for scope in scopes), all_fields))
if Scope.XLSX_PEOPLE in scopes:
for field_attr in factory:
field_attr["xlsx_field"] = "pp_" + field_attr["xlsx_field"].replace("_h_c", "_i_c")
return factory

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions backend/hct_mis_api/apps/core/fixtures/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -6681,8 +6681,8 @@
"description": "Partial individuals collected (Social Worker)",
"type": "SOCIAL",
"active": true,
"individual_filters_available": false,
"household_filters_available": true,
"individual_filters_available": true,
"household_filters_available": false,
"compatible_types": [2, 3],
"limit_to": ["c259b1a0-ae3a-494e-b343-f7c8eb060c68", "3e269a73-123b-43e1-86af-ced1b30d8e80"]
}
Expand Down
12 changes: 9 additions & 3 deletions backend/hct_mis_api/apps/core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
FlexibleAttributeGroup,
)
from hct_mis_api.apps.core.utils import decode_id_string
from hct_mis_api.apps.program.models import Program

if TYPE_CHECKING:
from django.db.models.query import QuerySet
Expand Down Expand Up @@ -268,9 +269,14 @@ def get_fields_attr_generators(
if flex_field is not False:
yield from FlexibleAttribute.objects.order_by("created_at")
if flex_field is not True:
yield from FieldFactory.from_scope(Scope.TARGETING).filtered_by_types(FILTERABLE_TYPES).apply_business_area(
business_area_slug=business_area_slug, program_id=program_id
)
if program_id and Program.objects.get(id=program_id).is_social_worker_program:
yield from FieldFactory.from_only_scopes([Scope.XLSX_PEOPLE, Scope.TARGETING]).filtered_by_types(
FILTERABLE_TYPES
).apply_business_area(business_area_slug=business_area_slug, program_id=program_id)
else:
yield from FieldFactory.from_scope(Scope.TARGETING).filtered_by_types(FILTERABLE_TYPES).apply_business_area(
business_area_slug=business_area_slug, program_id=program_id
)


def resolve_asset(business_area_slug: str, uid: str) -> Dict:
Expand Down
334 changes: 334 additions & 0 deletions backend/hct_mis_api/apps/core/tests/test_attributes_get_queries.py

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions backend/hct_mis_api/apps/core/tests/test_core_fields.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,89 @@
from unittest.mock import patch

from hct_mis_api.apps.core.base_test_case import APITestCase
from hct_mis_api.apps.core.field_attributes.core_fields_attributes import (
CORE_FIELDS_ATTRIBUTES,
FieldFactory,
)
from hct_mis_api.apps.core.field_attributes.fields_types import TYPE_STRING, Scope


class TestCoreFields(APITestCase):

def setUp(self) -> None:
self.scopes = [Scope.GLOBAL, Scope.XLSX_PEOPLE]
super().setUp()

def test_all_fields_have_lookup(self) -> None:
for field in CORE_FIELDS_ATTRIBUTES:
self.assertTrue(field.get("lookup"), f'{field.get("name")} does not have a lookup')

@patch(
"hct_mis_api.apps.core.field_attributes.core_fields_attributes.CORE_FIELDS_ATTRIBUTES",
[
{
"id": "b1f90314-b8b8-4bcb-9265-9d48d1fce5a4",
"type": TYPE_STRING,
"name": "given_name",
"lookup": "given_name",
"required": False,
"label": {"English(EN)": "Given name"},
"hint": "",
"choices": [],
"associated_with": "individual",
"xlsx_field": "given_name_i_c",
"scope": [Scope.GLOBAL, Scope.TARGETING, Scope.KOBO_IMPORT, Scope.INDIVIDUAL_UPDATE, Scope.XLSX_PEOPLE],
},
{
"id": "b1f90314-b8b8-4bcb-9265-9d48d1fce524",
"type": TYPE_STRING,
"name": "given_name1",
"lookup": "given_name1",
"required": False,
"label": {"English(EN)": "Given name1"},
"hint": "",
"choices": [],
"associated_with": "individual",
"xlsx_field": "given_name1_i_c",
"scope": [Scope.GLOBAL, Scope.TARGETING, Scope.KOBO_IMPORT, Scope.INDIVIDUAL_UPDATE],
},
{
"id": "36ab3421-6e7a-40d1-b816-ea5cbdcc0b6a",
"type": TYPE_STRING,
"name": "full_name",
"lookup": "full_name",
"required": True,
"label": {"English(EN)": "Full name"},
"hint": "",
"choices": [],
"associated_with": "individual",
"xlsx_field": "full_name_i_c",
"scope": [Scope.GLOBAL, Scope.XLSX_PEOPLE],
},
],
)
def test_xlsx_people_scope_filtering(self) -> None:
factory_result = FieldFactory.from_only_scopes(self.scopes)
self.assertEqual(len(factory_result), 2)

@patch(
"hct_mis_api.apps.core.field_attributes.core_fields_attributes.CORE_FIELDS_ATTRIBUTES",
[
{
"id": "b1f90314-b8b8-4bcb-9265-9d48d1fce5a4",
"type": TYPE_STRING,
"name": "given_name",
"lookup": "given_name",
"required": False,
"label": {"English(EN)": "Given name"},
"hint": "",
"choices": [],
"associated_with": "individual",
"xlsx_field": "given_name_i_c",
"scope": [Scope.GLOBAL, Scope.TARGETING, Scope.KOBO_IMPORT, Scope.INDIVIDUAL_UPDATE, Scope.XLSX_PEOPLE],
}
],
)
def test_xlsx_people_scope_modification(self) -> None:
factory_result = FieldFactory.from_only_scopes(self.scopes)
self.assertEqual(factory_result[0]["xlsx_field"], "pp_given_name_i_c")
19 changes: 17 additions & 2 deletions backend/hct_mis_api/apps/household/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class Meta:
MARITAL_STATUS_CHOICE,
getter=lambda c: c[0],
)
phone_no = factory.Sequence(lambda n: f"+48 609 456 {n%1000:03d}")
phone_no = factory.Sequence(lambda n: f"+48 609 456 {n % 1000:03d}")
phone_no_valid = True
phone_no_alternative = ""
phone_no_alternative_valid = True
Expand Down Expand Up @@ -363,15 +363,30 @@ def create_household_and_individuals(
individuals_data = []
if household_data.get("size") is None:
household_data["size"] = len(individuals_data)
if "program" not in household_data:
program = ProgramFactory()
else:
program = household_data["program"]
if "registration_data_import" not in household_data:
rdi = RegistrationDataImportFactory(program=program)
household_data["registration_data_import"] = rdi
household: Household = HouseholdFactory.build(**household_data)
household.program.save()
household.household_collection.save()
household.registration_data_import.imported_by.save()
household.registration_data_import.program.save()
household.registration_data_import.save()
household.program.save()
for individual_data in individuals_data:
if "program" not in individual_data:
individual_data["program"] = program
if "registration_data_import" not in individual_data:
individual_data["registration_data_import"] = household_data["registration_data_import"]
individuals: List[Individual] = [
IndividualFactory(household=household, program=household.program, **individual_data)
IndividualFactory(
household=household,
**individual_data,
)
for individual_data in individuals_data
]
household.head_of_household = individuals[0]
Expand Down
4 changes: 2 additions & 2 deletions backend/hct_mis_api/apps/payment/celery_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)
from hct_mis_api.apps.payment.models import PaymentPlan, PaymentVerificationPlan
from hct_mis_api.apps.payment.pdf.payment_plan_export_pdf_service import (
PaymentPlanPDFExportSevice,
PaymentPlanPDFExportService,
)
from hct_mis_api.apps.payment.services.payment_household_snapshot_service import (
create_payment_plan_snapshot_data,
Expand Down Expand Up @@ -565,7 +565,7 @@ def export_pdf_payment_plan_summary(self: Any, payment_plan_id: str, user_id: st
payment_plan.export_pdf_file_summary.delete()
payment_plan.export_pdf_file_summary = None

service = PaymentPlanPDFExportSevice(payment_plan)
service = PaymentPlanPDFExportService(payment_plan)
pdf, filename = service.generate_pdf_summary()

file_pdf_obj = FileTemp(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
logger = logging.getLogger(__name__)


class PaymentPlanPDFExportSevice:
class PaymentPlanPDFExportService:
text_template = "payment/pdf_file_generated_email.txt"
html_template = "payment/pdf_file_generated_email.html"

def __init__(self, payment_plan: PaymentPlan):
self.payment_plan = payment_plan
self.download_link: str = ""
self.payment_plan_link: str = ""
self.is_social_worker_program = payment_plan.program.is_social_worker_program

@staticmethod
def get_link(api_url: Optional[str] = None) -> str:
Expand Down Expand Up @@ -58,7 +59,10 @@ def get_email_context(self, user: "User") -> Dict:

def generate_pdf_summary(self) -> Any:
self.generate_web_links()
template_name = "payment/payment_plan_summary_pdf_template.html"
if self.is_social_worker_program:
template_name = "payment/people_payment_plan_summary_pdf_template.html"
else:
template_name = "payment/payment_plan_summary_pdf_template.html"
filename = f"PaymentPlanSummary-{self.payment_plan.unicef_id}.pdf"
delivery_mechanism_per_payment_plan = self.payment_plan.delivery_mechanisms.select_related(
"financial_service_provider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h2>LETTER OF AUTHORIZATION</h2>
<table class="table">
<tbody>
<tr>
<td colspan="4" class="header">PAYMENT PLAN DETAILS</td>
<td colspan="4" class="header">PAYMENT PLAN DETAILS</td>
</tr>
<tr>
<td>Start Date</td>
Expand Down Expand Up @@ -96,9 +96,9 @@ <h3>PAYMENT PLAN ACCEPTANCE PROCESS</h3>
<table>
<tbody>
<tr>
<td colspan="2" class="header">approval</td>
<td colspan="2" class="header">authorization</td>
<td colspan="2" class="header">release</td>
<td colspan="2" class="header">approval</td>
<td colspan="2" class="header">authorization</td>
<td colspan="2" class="header">release</td>
</tr>
<tr>
<td>Name of Approver</td>
Expand Down Expand Up @@ -167,8 +167,8 @@ <h3>PAYMENT PLAN ACCEPTANCE PROCESS</h3>

<p></p>
<p></p>
<p>Link to Payment Plan: <a href="{{ payment_plan_link }}">{{ payment_plan_link }}</a></p>
<p>Link to Payment Plan: <a href="{{ payment_plan_link }}">{{ payment_plan_link }}</a></p>
<p></p>
<p>Generated on {% now "N j, Y" %}</p>

{% endblock %}
{% endblock %}
Loading

0 comments on commit b038e70

Please sign in to comment.