Add functionality to run formulas on existing records#395
Open
arsen-vs wants to merge 7 commits into
Open
Conversation
added 5 commits
May 28, 2026 12:29
- 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.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #395 +/- ##
===========================================
+ Coverage 96.90% 97.02% +0.11%
===========================================
Files 232 233 +1
Lines 9694 9771 +77
Branches 1073 1083 +10
===========================================
+ Hits 9394 9480 +86
+ Misses 140 134 -6
+ Partials 160 157 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
- 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.
| @button( | ||
| label="Run Formula on Existing Records", | ||
| change_form=True, | ||
| html_attrs={"title": "Run this formula in Country Workspace without rule commits"}, |
Contributor
There was a problem hiding this comment.
What about add decorator-level permission for button.
Contributor
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RunTransformerForm, to allow users to select a batch and specify the record type for formula application.run_on_existing_records, to handle the execution of formulas directly in the Country Workspace.