Repository navigation
feat: add usage quantity detail to surface unit config on invoices api - OM-410 - #4858
Conversation
📝 WalkthroughWalkthroughThe invoice API now exposes optional usage quantity details on standard invoice lines. The detail contains raw quantity, invoiced quantity, and display unit. The converter omits it when unit configuration or required quantities are missing. Generated models and tests were updated. ChangesInvoice usage quantity details
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant InvoiceLine
participant BillingInvoiceConverter
participant V3BillingInvoiceAPI
InvoiceLine->>BillingInvoiceConverter: provide usage configuration and rated quantities
BillingInvoiceConverter->>BillingInvoiceConverter: validate configuration and quantities
BillingInvoiceConverter->>V3BillingInvoiceAPI: attach UsageQuantityDetail
V3BillingInvoiceAPI->>V3BillingInvoiceAPI: expose raw quantity, invoiced quantity, and display unit
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
5039f53 to
17d0298
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/billing/unitconfig_legacy_test.go (1)
156-217: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoffOptional: pull the shared invoice setup into one suite fixture.
This block repeats the setup from
TestRatesConvertedQuantityalmost verbatim: billing profile, service period, pending line, the 7400 event, and the invoice collection. Only the display unit and the namespace differ. A suite helper that takes the*productcatalog.UnitConfigand returns the invoiced standard line would remove roughly sixty duplicated lines and keep the two tests focused on their distinct assertions. Fine to defer if you prefer each e2e test to read start to finish on its own.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/billing/unitconfig_legacy_test.go` around lines 156 - 217, Extract the repeated billing setup in this test block and the nearby TestRatesConvertedQuantity path into a shared suite helper that provisions the billing profile, creates the pending invoice line, adds the 7400 usage event, and returns the invoiced standard line. Keep the helper parameterized by the existing unit-config symbols, especially the *productcatalog.UnitConfig, so the tests only differ in their display unit and namespace while preserving the current assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@api/v3/handlers/billinginvoices/convert.go`:
- Around line 321-326: Update the stale prose around
BillingInvoiceUsageQuantityDetail so it no longer describes the removed
applied_unit_config field: in toAPIUsageQuantityDetail, revise the comment to
say the detail carries raw_quantity, invoiced_quantity, and the configured
display unit, and explicitly note that the config itself remains on
rate_card.unit_config; in the matching convert_test then-comment, remove the
reference to a config snapshot so it matches the three assertions that remain.
---
Nitpick comments:
In `@test/billing/unitconfig_legacy_test.go`:
- Around line 156-217: Extract the repeated billing setup in this test block and
the nearby TestRatesConvertedQuantity path into a shared suite helper that
provisions the billing profile, creates the pending invoice line, adds the 7400
usage event, and returns the invoiced standard line. Keep the helper
parameterized by the existing unit-config symbols, especially the
*productcatalog.UnitConfig, so the tests only differ in their display unit and
namespace while preserving the current assertions.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: e086cf31-38ad-4478-a406-fdeef6ec1c54
⛔ Files ignored due to path filters (1)
api/v3/openapi.yamlis excluded by!**/openapi.yaml
📒 Files selected for processing (10)
api/spec/packages/aip-client-javascript/src/index.tsapi/spec/packages/aip-client-javascript/src/models/schemas.tsapi/spec/packages/aip-client-javascript/src/models/types.tsapi/spec/packages/aip/src/invoices/invoice.tspapi/spec/packages/aip/src/productcatalog/unitconfig.tspapi/v3/api.gen.goapi/v3/client/models_invoices.goapi/v3/handlers/billinginvoices/convert.goapi/v3/handlers/billinginvoices/convert_test.gotest/billing/unitconfig_legacy_test.go
17d0298 to
8cf8b87
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
What
Surface the UnitConfig quantity audit trail on the v3 invoice standard line. A new read-only usage_quantity_detail field (BillingInvoiceUsageQuantityDetail: raw_quantity, invoiced_quantity, display_unit) is emitted per standard line whenever the line carries a unit_config. Wires the previously-orphaned InvoiceUsageQuantityDetail TypeSpec model onto the standard line and populates it in the v3 converter (mapStandardLine → new mapUsageQuantityDetail). Additive; identity when no unit_config.
Why
We exposed (#4730) the unit_config rule on the invoice line's rate card, but the invoice API surfaced no quantities to go with it — the only quantity anywhere was the already-converted Quantity on each detailed line, with no raw meter value and no unit. So a converted line ("2 GB @ $5") could not be traced back to the meter reading it came from. usage_quantity_detail provides that trace — raw metered → invoiced (billed) quantity + display unit — completing the audit trail, and it reads identically across both billing paths.
How
Pure read-side exposure of data we already persists — no schema, migration, adapter, or engine changes. raw_quantity and invoiced_quantity map straight from the stored UsageBased.MeteredQuantity / .Quantity on the domain standard line, so no recompute is needed (the linear UnitConfig.Apply isn't even called on this path). It's populated in the single v3 converter both engines funnel through, so legacy and charges are covered by one mapping; gated on GetUnitConfig() != nil so non unit_config lines are unchanged — which also covers the charges custom-currency path (no config). Two fields were deliberately trimmed from the orphan model: converted_quantity (the pre-rounding value, derivable as raw × factor and omitted to keep this a lean stored-fields-only object) and applied_unit_config (a full duplicate of rate_card.unit_config, already on the same line since item A — kept a single source of truth for the config). Covered by converter unit tests plus a DB-backed integration test that runs a real invoice through ToAPIStandardInvoice and asserts the audit-trail math end to end (7400 raw → ceil(7400/1000) = 8 GB).
Summary by CodeRabbit
New Features
Updates
Tests
Greptile Summary
The PR adds a read-only usage quantity audit trail to v3 standard invoice lines when unit conversion is configured.
Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
Sequence Diagram
Reviews (3): Last reviewed commit: "feat: add usage quantity detail to surfa..." | Re-trigger Greptile
Context used: