Skip to content

Add functionality to run formulas on existing records#395

Open
arsen-vs wants to merge 7 commits into
developfrom
feature/289969-Steficon-formula
Open

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

Conversation

@arsen-vs
Copy link
Copy Markdown
Contributor

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

  • 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.

Arsen P 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
Copy link
Copy Markdown

codecov Bot commented Jun 5, 2026

Codecov Report

❌ Patch coverage is 96.61017% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.02%. Comparing base (7c39df2) to head (fd386dc).
⚠️ Report is 14 commits behind head on develop.

Files with missing lines Patch % Lines
.../country_workspace/workspaces/admin/transformer.py 96.61% 0 Missing and 2 partials ⚠️
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.
📢 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.

- 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"},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about add decorator-level permission for button.

@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?

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.

2 participants