snapshot: preserve custom field parity across forms timeline and pdf

This commit is contained in:
Md Bayazid Bostame
2026-03-27 13:21:25 +01:00
parent 2e5e941d41
commit fdc27f2123
20 changed files with 2294 additions and 545 deletions

View File

@@ -9,6 +9,7 @@ from django.utils.translation import override
from .form_builder import (
LOCKED_FIELD_RULES,
LOCKED_SECTION_RULES,
get_custom_field_configs,
ensure_form_field_configs,
ensure_form_section_configs,
get_default_page_map,
@@ -16,6 +17,7 @@ from .form_builder import (
get_section_order,
)
from .forms import OffboardingRequestForm, OnboardingRequestForm
from .models import FormCustomFieldConfig
PDF_SECTION_TITLES = {
"onboarding": {
@@ -251,6 +253,25 @@ def build_pdf_sections(form_type: str, request_obj, language_code: str | None =
}
)
custom_values = getattr(request_obj, 'custom_field_values', {}) or {}
for cfg in get_custom_field_configs(form_type):
if cfg.section_key not in sections:
continue
raw_value = custom_values.get(cfg.field_key)
if cfg.field_type == FormCustomFieldConfig.FIELD_TYPE_CHECKBOX:
raw_value = _yes_no_text(language_code)[0] if raw_value else ''
sections[cfg.section_key]["fields"].append(
{
"name": f"custom__{cfg.field_key}",
"label": cfg.translated_label(language_code),
"help_text": cfg.translated_help_text(language_code),
"kind": _field_kind(raw_value),
"value": raw_value,
"is_empty": _is_empty_value(raw_value),
"is_locked": False,
}
)
not_available = _not_available_text(language_code)
result = []
for section in sections.values():