Implemented impact warnings when deactivating Studio configurations in OpenSPP Studio, as specified in section 2.3 of the spec:
"Deactivating shows impact warning ('This field is used by 1,247 records')"
File: /wizard/deactivate_wizard.py
- Transient model
spp.studio.deactivate.wizard - Displays impact warnings before deactivation
- Extracts record count from impact messages (handles formatted numbers like "1,247")
- Provides Confirm/Cancel actions
- Logs deactivation decisions
Fields:
config_model: Model name of configuration being deactivatedconfig_id: ID of configuration recordconfig_name: Display name (computed)config_type: Type of configuration (computed)impact_message: Warning message from model's_get_deactivation_impact()record_count: Extracted count of affected records (computed)
File: /wizard/deactivate_wizard_views.xml
- Clean, user-friendly warning dialog
- Shows configuration name and type
- Displays affected record count
- Shows detailed impact message
- Info box explaining data preservation
- Danger-styled "Confirm Deactivation" button
- Cancel button
The infrastructure for impact checking was already in place:
studio_mixin.py (lines 112-150):
action_deactivate()calls_get_deactivation_impact()- If impact exists, shows wizard via
_show_deactivation_warning() - Otherwise proceeds with
_do_deactivate()
Each Studio model implements _get_deactivation_impact():
- Counts records where field has non-empty values
- Returns message: "This field contains data in N records. Deactivating will hide the field but preserve the data."
- Counts
spp.event.datarecords using this event type - Returns message: "This event type is used by N event record(s). Deactivating will hide the event type but preserve existing events."
Change Request Types (spp_studio_change_requests/models/studio_change_request_type.py, lines 263-279)
- Counts active/pending change requests of this type
- Returns message: "This change request type has N active or pending requests. Deactivating will prevent new requests but existing ones will remain."
- Checks if rule is linked to a program
- Returns message: "This rule is linked to program 'X'. Deactivating will not remove the eligibility manager, but the rule can no longer be edited."
File: /security/ir.model.access.csv
- Added access rules for wizard:
access_studio_deactivate_wizard_editor: For Studio Editorsaccess_studio_deactivate_wizard_manager: For Studio Managers
- Wizard creation with context values
- Record count extraction (with/without commas)
- Config info computation
- Cancel action
- Error handling for invalid models/records
- Full deactivation flow with no data (no wizard)
- Full deactivation flow with data (shows wizard)
- Wizard confirmation actually deactivates
- Impact message format validation
- Config info computed correctly
Files Modified:
spp_studio/__init__.py: Added wizard importspp_studio/__manifest__.py: Added wizard views to data filesspp_studio/tests/__init__.py: Added wizard testsspp_studio_fields/tests/__init__.py: Added integration tests
-
User clicks "Deactivate" on a Studio configuration
- System calls
action_deactivate()on the configuration
- System calls
-
System checks for impact
- Calls model-specific
_get_deactivation_impact() - Each model type has custom logic to count affected records
- Calls model-specific
-
If no impact (no data)
- Proceeds directly with
_do_deactivate() - Configuration becomes inactive
- No wizard shown
- Proceeds directly with
-
If impact exists (data would be affected)
- Returns wizard action with impact message in context
- Wizard opens showing:
- Configuration name and type
- Number of affected records
- Detailed impact description
- Warning that data will be preserved
-
User decides
- Cancel: Closes wizard, configuration remains active
- Confirm: Calls
_do_deactivate(), configuration becomes inactive
Field with 1,247 records:
This field contains data in 1,247 records. Deactivating will hide
the field but preserve the data.
Event type with 5 events:
This event type is used by 5 event record(s). Deactivating will
hide the event type but preserve existing events.
Change request type with pending requests:
This change request type has 3 active or pending requests.
Deactivating will prevent new requests but existing ones will remain.
All tests pass:
88 total | 88 passed | 100.0% pass rate | 0 failed | 0 errors | 0 skipped
✅ All tests passed!
/spp_studio/wizard/__init__.py/spp_studio/wizard/deactivate_wizard.py/spp_studio/wizard/deactivate_wizard_views.xml/spp_studio/tests/test_deactivate_wizard.py/spp_studio_fields/tests/test_deactivation_impact.py/spp_studio/DEACTIVATION_IMPACT_IMPLEMENTATION.md(this file)
/spp_studio/__init__.py/spp_studio/__manifest__.py/spp_studio/security/ir.model.access.csv/spp_studio/tests/__init__.py/spp_studio_fields/tests/__init__.py
- All existing
_get_deactivation_impact()implementations were already in place - The wizard integrates seamlessly with existing lifecycle management
- Data is never deleted - only hidden by deactivation
- Users can reactivate configurations later if needed
- Logging tracks all deactivation decisions for audit purposes