Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Preserve manual rates when changing timesheet context - #6077

Open
Marukome0743 wants to merge 3 commits into
kimai:mainfrom
Marukome0743:pr6077
Open

Preserve manual rates when changing timesheet context#6077
Marukome0743 wants to merge 3 commits into
kimai:mainfrom
Marukome0743:pr6077

Conversation

@Marukome0743

@Marukome0743 Marukome0743 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

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.

Before After
Fixed price is cleared and the hourly price falls back to 50. Manual fixed price 80 is preserved.
Before: fixed price cleared after activity change After: manual fixed price preserved after activity change

Verification

  • vendor/bin/phpunit tests/Timesheet/Calculator/RateResetCalculatorTest.php — 7 tests, 33 assertions
  • vendor/bin/phpunit tests/Controller/TimesheetControllerTest.php --filter testEditActionKeepsManualFixedRateWhenActivityChanges — 1 test, 9 assertions
  • ./php-cs-fixer.sh core
  • ./phpstan.sh core
  • ./phpstan.sh test
  • vendor/bin/phpunit tests/Pdf/MPdfConverterTest.php — 3 tests, 10 assertions
  • Browser reproduction with a one-hour entry, hourly rate 50, and manual fixed price 80

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I verified that my code applies to the guidelines (composer code-check)
  • I updated the documentation (not needed: no public behavior or configuration documentation changed)
  • I agree that this code is used in Kimai (see license)

@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.73%. Comparing base (7c2ed4b) to head (70ffc05).
⚠️ Report is 63 commits behind head on main.

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     
Files with missing lines Coverage Δ
src/Timesheet/Calculator/RateResetCalculator.php 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 RateResetCalculator to 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.

Comment thread src/Timesheet/Calculator/RateResetCalculator.php
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.

Fixed price automatically removed on activity change

2 participants