Preserve manual rates when changing timesheet context - #6077
Preserve manual rates when changing timesheet context#6077Marukome0743 wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6077 +/- ##
=========================================
Coverage 88.72% 88.73%
- Complexity 10055 10064 +9
=========================================
Files 889 889
Lines 32051 32076 +25
=========================================
+ Hits 28438 28462 +24
- Misses 3613 3614 +1
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression where editing an existing timesheet entry and changing its context (activity/project/user) could unintentionally wipe a manually entered fixed/hourly rate due to Doctrine changeset behavior. It updates the rate-reset logic to distinguish manual rates from previously auto-calculated values (to avoid carrying over rule-derived rates), and adjusts a PDF test assertion to accept valid uncompressed output.
Changes:
- Reworks
RateResetCalculatorto reconstruct the previous automatic rate before resetting, preserving only genuinely manual fixed/hourly rates. - Expands unit + controller test coverage for rate reset/preservation behavior on context changes.
- Makes the PDF associated-files test accept both compressed and uncompressed representations while keeping path-leak checks.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Timesheet/Calculator/RateResetCalculator.php |
Computes previous-context automatic rates to decide whether to preserve manual fixed/hourly rates during resets. |
tests/Timesheet/Calculator/RateResetCalculatorTest.php |
Adds focused unit tests covering manual vs automatic fixed/hourly rate preservation and reset behavior. |
tests/Controller/TimesheetControllerTest.php |
Adds an integration test ensuring manual fixed rate survives activity change on edit. |
tests/Pdf/MPdfConverterTest.php |
Updates assertion to accept uncompressed content while maintaining path-leak verification. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
Fixes #5735.
Changing the activity, project, or user of an existing timesheet entry reset all stored rate metadata. An unchanged manual fixed or hourly rate is absent from Doctrine's changeset, so it was treated like an automatically calculated value and silently replaced.
This change reconstructs the automatic rate for the previous timesheet context before resetting rates. A stored fixed or hourly rate is preserved only when it differs from that previous automatic result. Rule-derived values are still discarded and recalculated for the new context.
This distinction addresses the concern raised on #5810: that implementation preserved every stored rate and could incorrectly carry a rate rule from the old activity into the new one.
User impact: manually entered fixed and hourly prices now survive activity, project, and user changes, while configured rate rules continue to follow the selected context.
The PHP 8.5 coverage job also exposed an existing PDF assertion that assumed associated-file content was always Flate-compressed. The assertion now accepts the valid uncompressed PDF representation while retaining the path-leak checks against both raw and decompressed content.
AI assistance was used to investigate, implement, and test this change. The resulting code and behavior were reviewed and verified locally.
Before / after
Both screenshots show the saved entry after changing its activity without editing the fixed price.
Verification
vendor/bin/phpunit tests/Timesheet/Calculator/RateResetCalculatorTest.php— 7 tests, 33 assertionsvendor/bin/phpunit tests/Controller/TimesheetControllerTest.php --filter testEditActionKeepsManualFixedRateWhenActivityChanges— 1 test, 9 assertions./php-cs-fixer.sh core./phpstan.sh core./phpstan.sh testvendor/bin/phpunit tests/Pdf/MPdfConverterTest.php— 3 tests, 10 assertionsTypes of changes
Checklist
composer code-check)