Skip to content

fix: decode BC OData enum encoding so G/L Account lines show in cost breakdowns#212

Merged
EdiWeeks merged 3 commits into
mainfrom
fix/211-gl-account-breakdown-encoding
Jun 19, 2026
Merged

fix: decode BC OData enum encoding so G/L Account lines show in cost breakdowns#212
EdiWeeks merged 3 commits into
mainfrom
fix/211-gl-account-breakdown-encoding

Conversation

@EdiWeeks

@EdiWeeks EdiWeeks commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Job Planning Lines of Type = G/L Account were not appearing in the Budget Cost and Billable Price per-type breakdowns on the project details page — the G/L Account row always showed £0.

Root cause: BC's OData serializer URL-encodes named enum values, so type "G/L Account" arrives over the wire as G_x002F_L_x0020_Account (/_x002F_, space → _x0020_). Thyme compared the raw value against the plain 'G/L Account' string, so these lines never matched. (The same encoding was already handled for lineType but not for type.)

Confirmed against live production BC/jobPlanningLines for PR00100 task 9999 returns:

{ "lineType": "Budget",   "type": "G_x002F_L_x0020_Account", "totalCost": 500 }
{ "lineType": "Billable", "type": "G_x002F_L_x0020_Account", "totalPrice": 24000 }
image

Changes

  • src/utils/unitConversion.ts — add decodeBCEnum(), which generically decodes BC's _xHHHH_ enum escapes (not hardcoded to one value — decodes whatever BC sends).
  • src/services/bc/bcClient.ts — decode type and lineType once at the fetch boundary (getJobPlanningLines and getJobPlanningLinesForWeek), so all downstream comparisons use the plain values.
  • tests/unit/utils/unitConversion.test.ts — 4 new tests covering the exact wire value confirmed from production.

Test plan

  • Confirmed root cause against live production BC (/jobPlanningLines, PR00100 task 9999)
  • bun run test — 37/37 unit tests pass (incl. new decodeBCEnum cases)
  • bun run typecheck — clean
  • bun run lint — 0 errors
  • bun run build — succeeds
  • Manually verified on project PR00100: Budget Cost G/L Account row now shows £500.00 and Billable Price G/L Account row shows £24,000.00 (previously £0.00)

Note: bun run format:check flags ~161 files locally due to a Windows CRLF/line-ending mismatch (pristine main files I never touched also fail). The committed blobs are LF (core.autocrlf=true), so CI's format check passes.

Fixes #211

🤖 Generated with Claude Code

…downs

BC's OData serializer URL-encodes named enum values, so a planning line
of type "G/L Account" arrives as "G_x002F_L_x0020_Account". Thyme compared
the raw value against the plain "G/L Account" string, so G/L Account
planning lines never matched and their amounts showed as 0 in the Budget
Cost and Billable Price per-type breakdowns on the project details page
(confirmed against live BC for PR00100 task 9999).

Add decodeBCEnum() to decode the _xHHHH_ escapes generically and apply it
to type/lineType once at the fetch boundary in bcClient, so all downstream
comparisons use the plain values.

Fixes #211

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 19, 2026 17:00

Copilot AI left a comment

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.

Pull request overview

This PR fixes missing G/L Account Job Planning Lines in the project details cost breakdowns by decoding Business Central’s OData enum escaping (e.g. G_x002F_L_x0020_AccountG/L Account) so downstream comparisons operate on plain values.

Changes:

  • Added a generic decodeBCEnum() helper to decode BC _xHHHH_ enum escapes.
  • Normalized type and lineType in bcClient when fetching job planning lines (decode at the boundary).
  • Added unit tests covering the production-confirmed encoded enum values.

Reviewed changes

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

File Description
src/utils/unitConversion.ts Introduces decodeBCEnum() used to normalize BC enum strings.
src/services/bc/bcClient.ts Decodes planning-line type/lineType during fetch to fix downstream matching.
tests/unit/utils/unitConversion.test.ts Adds unit tests validating enum decoding behavior (including production example).

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

Comment thread src/utils/unitConversion.ts
Comment thread src/services/bc/bcClient.ts
EdiWeeks and others added 2 commits June 19, 2026 18:11
- decodeBCEnum: scan left-to-right with a sticky regex so a literal
  underscore escape (_x005F_) is consumed as one unit and a following
  escape sequence is left intact, rather than re-read. Add tests for the
  _x005F_ and adjacent-escape cases.
- normalizePlanningLines: narrow decoded type/lineType against the known
  unions and fall back to the original value when unrecognized, instead of
  a blind cast that could mask unexpected BC enums.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 19, 2026 17:25

Copilot AI left a comment

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.

Pull request overview

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

@EdiWeeks
EdiWeeks requested a review from BenGWeeks June 19, 2026 17:29
@EdiWeeks
EdiWeeks merged commit 3266180 into main Jun 19, 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] G/L Account budget/billable lines not displayed in project cost breakdown

3 participants