Skip to content

Add functionality to run formulas on existing records - #395

Merged
arsen-vs merged 13 commits into
developfrom
feature/289969-Steficon-formula
Jun 22, 2026
Merged

Add functionality to run formulas on existing records#395
arsen-vs merged 13 commits into
developfrom
feature/289969-Steficon-formula

Conversation

@arsen-vs

@arsen-vs arsen-vs commented May 28, 2026

Copy link
Copy Markdown
Contributor
  • Introduced a new form, RunTransformerForm, to allow users to select a batch and specify the record type for formula application.
  • Implemented a new admin action, run_on_existing_records, to handle the execution of formulas directly in the Country Workspace.
  • Created a corresponding HTML template for the form, enhancing the user interface for running formulas without rule commits.
  • Added permission checks to ensure users can only run formulas on batches they are authorized to process.

AB#289969

@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.83333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.95%. Comparing base (d5816db) to head (5534d70).

Files with missing lines Patch % Lines
.../country_workspace/workspaces/admin/transformer.py 95.45% 0 Missing and 3 partials ⚠️
...y_workspace/workspaces/admin/batch/reprocessing.py 96.55% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #395   +/-   ##
========================================
  Coverage    96.94%   96.95%           
========================================
  Files          238      238           
  Lines         9822     9905   +83     
  Branches      1091     1104   +13     
========================================
+ Hits          9522     9603   +81     
+ Misses         143      142    -1     
- Partials       157      160    +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/country_workspace/workspaces/admin/transformer.py
@vitali-yanushchyk-valor

Copy link
Copy Markdown
Contributor

ApplyTo controls which records receive the transformer. However, this action runs the full reprocess_batch workflow, so both households and individuals are still rebuilt from raw_data and have their validation state reset.
Could we use apply_batch_transformers() here instead, so that only the selected records are transformed?

Arsen P added 9 commits June 8, 2026 13:59
- Introduced a new form, `RunTransformerForm`, to allow users to select a batch and specify the record type for formula application.
- Implemented a new admin action, `run_on_existing_records`, to handle the execution of formulas directly in the Country Workspace.
- Created a corresponding HTML template for the form, enhancing the user interface for running formulas without rule commits.
- Added permission checks to ensure users can only run formulas on batches they are authorized to process.
…ctionality

- Introduced tests for the `RunTransformerForm` to validate choices based on program type.
- Added tests for the `run_on_existing_records` method in the `CountryTransformerAdmin`, covering scenarios for rendering the form, handling permissions, and processing valid and invalid submissions.
- Utilized mocking to simulate requests and responses, ensuring isolated and reliable test outcomes.
- Updated the ApplyToOptions class in RunTransformerForm to inherit from models.TextChoices instead of forms.TextChoices, aligning with Django best practices for defining choice fields.
- This change enhances the integration with Django's model layer, improving maintainability and consistency across the application.
- Updated test cases in `test_transformer.py` to use explicit patching for the `get_object` and `get_change_url` methods of `CountryTransformerAdmin`, improving clarity and maintainability of the tests.
- This change enhances the readability of the test setup by clearly indicating the target of the mocks.
…stance

- Modified the `run_on_existing_records` method calls in the test cases to explicitly pass the `transformer_admin` instance, enhancing clarity and ensuring proper context is maintained during testing.
- This change improves the accuracy of the tests by aligning with the method's expected parameters.
…and improve mock form usage

- Modified the test cases to set `state.tenant` and `state.program` to None, ensuring proper handling of these values during testing.
- Enhanced the mock setup for `RunTransformerForm` to explicitly define `ApplyToOptions`, improving clarity and consistency in the tests.
- These changes contribute to more robust and maintainable test cases for the `run_on_existing_records` functionality.
- Introduced a new test case to verify that the batch queryset is filtered correctly by the office parameter in the RunTransformerForm.
- Utilized mocking to simulate the queryset behavior, ensuring that the filter method is called with the expected office argument.
- This addition enhances the test coverage for the RunTransformerForm functionality, contributing to more robust testing practices.
…sing.py

- Added a new permission for the "Run Formula on Existing Records" button in CountryTransformerAdmin to ensure proper access control.
- Refactored the action for batch processing to use `apply_batch_transformers`, improving clarity and functionality.
- Introduced a new helper function `_apply_transformer_only` to streamline the transformation of individual records.
- Updated the `apply_batch_transformers` function to handle batch processing for both households and individuals, including logging and error handling.
- Enhanced unit tests in test_transformer.py to verify the new action and permission checks, ensuring robust testing of the updated functionality.
- Removed the `_apply_transformer_only` function to streamline the transformation process.
- Updated `apply_batch_transformers` to delegate transformation logic to `run_batch_postprocessing`, enhancing clarity and maintainability.
- Added new unit tests for `apply_batch_transformers` to ensure proper error handling and validation of transformer IDs.
- Improved test coverage for batch processing scenarios, verifying the correct delegation and response structure.
@arsen-vs
arsen-vs force-pushed the feature/289969-Steficon-formula branch from 0e55b8e to 5624673 Compare June 8, 2026 11:15
- Registered the CountryTransformerAdmin in the TenantAdminSite for improved admin management.
- Added a new entry for "Transformers" in the admin site navigation, linking to the CountryTransformerAdmin changelist.
- Updated the __all__ list in admin/__init__.py to include CountryTransformerAdmin for proper module exports.
Comment thread src/country_workspace/workspaces/admin/batch/reprocessing.py Outdated
Comment thread src/country_workspace/workspaces/admin/transformer.py
- Added a clean method to RunTransformerForm to validate that households cannot be selected for non-master-detail programs, enhancing data integrity.
- Updated apply_batch_transformers to delegate transformation logic to a new utility function, improving code clarity and maintainability.
- Enhanced unit tests to cover the new validation logic in RunTransformerForm, ensuring robust error handling and user feedback.
Comment thread src/country_workspace/workspaces/admin/batch/reprocessing.py
Comment thread src/country_workspace/workspaces/admin/transformer.py Outdated
- Updated the validation logic in RunTransformerForm to allow household applications only for master-detail programs, improving data integrity.
- Modified the unit tests to parameterize the `apply_to` field, ensuring comprehensive coverage for both household and both options in the validation scenario.
@arsen-vs
arsen-vs merged commit 721b72b into develop Jun 22, 2026
12 checks passed
@arsen-vs
arsen-vs deleted the feature/289969-Steficon-formula branch June 22, 2026 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants