Skip to content

fix: convert planning-line quantities to hours on the project list#201

Merged
EdiWeeks merged 3 commits into
mainfrom
fix/192-list-planned-hours-mismatch
May 5, 2026
Merged

fix: convert planning-line quantities to hours on the project list#201
EdiWeeks merged 3 commits into
mainfrom
fix/192-list-planned-hours-mismatch

Conversation

@EdiWeeks
Copy link
Copy Markdown
Contributor

@EdiWeeks EdiWeeks commented May 5, 2026

Summary

The project list's Planned column was summing BCJobPlanningLine.quantity directly with no UoM conversion. Projects whose resources are configured in DAYs therefore showed raw days against a column labelled "h" — for Cairn Homes – Support & Maintenance, 31.5d was rendered as 61h (planned), which then made Remaining go strongly negative (-107h (276%)). The project details page already converts via the per-resource UoM map, so the list and details views disagreed for the same project.
image

  • Added sumPlannedHours(planningLines, uomMap) and isBudgetPlanningLine helpers in utils/unitConversion.ts. Same rule as the details page: only Resource Budget lines (or Both Budget and Billable, including the _x0020_-encoded variant), with each quantity converted to hours via the UoM map.
  • projectService.getProjectBudgets now fetches the resource UoM table once per call and uses sumPlannedHours, so the list matches the details page.
  • projectDetailsService delegates to the same shared helper instead of carrying its own copy, so the two stay in sync going forward.

Test plan

  • On the projects list, Cairn Homes – Support & Maintenance (PR00010) shows Planned 237h and Remaining ~+68.5h (was 61h / -107h / 276%).
  • Open the project details page for the same project — the values match.
  • Spot-check another DAY-based project (e.g. W&R Barnett rows in [BUG] Incorrect data display in columns on project screen #192's screenshot): Planned column now reads in hours, Remaining is no longer wildly negative.
  • HOUR-based projects: Planned column unchanged.
  • Sort by Planned and Remaining — order is consistent with the new values.

Fixes #192

🤖 Generated with Claude Code

The project list's "Planned" column summed BCJobPlanningLine.quantity
directly, with no UoM conversion. Resources entered in DAYs (e.g. 31.5
days for Cairn Homes – Support & Maintenance) showed up as 31.5 raw
quantity in a column labelled "h", which then made the Remaining cell
go strongly negative (276% spent of a 61h budget that should have been
237h). The project details page already converted via the per-resource
UoM map, so the two views disagreed.

- Add `sumPlannedHours(planningLines, uomMap)` and `isBudgetPlanningLine`
  helpers in utils/unitConversion.ts. They mirror the rule used on the
  details page: Resource Budget lines only, quantity → hours via the UoM
  conversion factor.
- projectService.getProjectBudgets now fetches the resource UoM table
  once per call and reuses sumPlannedHours, matching the details page.
- projectDetailsService delegates to the same helper, replacing its
  local copy of the rule, so the two stay in sync going forward.

Fixes #192

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 5, 2026 15:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 incorrect “Planned (h)” values on the projects list by converting Job Planning Line quantities to hours using the per-resource unit-of-measure (UoM) conversion data, matching the logic already used on the project details page (fixes #192).

Changes:

  • Added shared helpers in unitConversion.ts to identify budget planning lines and sum planned hours with UoM conversion.
  • Updated projectService.getProjectBudgets to fetch resource UoMs once and compute planned hours via the shared helper.
  • Refactored projectDetailsService to use the shared helper (removing the local budget-line predicate) so list/details stay consistent.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/utils/unitConversion.ts Adds isBudgetPlanningLine and sumPlannedHours to centralize budget-line filtering + quantity→hours conversion.
src/services/bc/projectService.ts Uses UoM conversion + shared summation logic when computing project “Planned” hours for the list view.
src/services/bc/projectDetailsService.ts Delegates planned-hours computation (and budget line checks) to shared utilities to keep behavior consistent.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/utils/unitConversion.ts
Comment thread src/utils/unitConversion.ts
Comment thread src/services/bc/projectService.ts
- Widen `BCJobPlanningLine.lineType` (and the matching field on
  `PlanAllocation` in usePlanStore) to include the `_x0020_`-encoded
  variant of "Both Budget and Billable". Six call sites already special-
  cased this form at runtime; the type now matches reality so future
  narrowing comparisons can't silently miss it.
- Add unit tests for `isBudgetPlanningLine` and `sumPlannedHours` in
  tests/unit/utils/unitConversion.test.ts, matching the coverage style
  of the other helpers in the same module (Budget vs Billable vs Both,
  encoded form, Resource vs Item vs G/L, UoM conversion + summation).
- `getProjectBudgets` returns an empty map immediately when called with
  no project codes, skipping the `getResourceUnitsOfMeasure` round-trip
  for the empty-input case.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@EdiWeeks EdiWeeks requested a review from BenGWeeks May 5, 2026 15:58
Copilot AI review requested due to automatic review settings May 5, 2026 16:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@EdiWeeks EdiWeeks merged commit eb17e4a into main May 5, 2026
8 checks passed
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.

[BUG] Incorrect data display in columns on project screen

3 participants