Skip to content

MPT-18440 AWS billing transfer: support PLS additional charge#289

Merged
d3rky merged 1 commit intomainfrom
MPT-18440-aws-billing-transfer-support-pls-additional-discount
Mar 24, 2026
Merged

MPT-18440 AWS billing transfer: support PLS additional charge#289
d3rky merged 1 commit intomainfrom
MPT-18440-aws-billing-transfer-support-pls-additional-discount

Conversation

@ruben-sebrango
Copy link
Copy Markdown
Collaborator

@ruben-sebrango ruben-sebrango commented Mar 24, 2026

Closes MPT-18440

  • Added support for PLS (Private Label Support) additional charges in AWS billing journal generation
  • Introduced PlSChargeManager to compute and generate PLS charge journal lines based on a configurable percentage applied to total usage amounts
  • Created new MarketplaceJournalLineProcessor to filter out Tax service metrics from marketplace records
  • Refactored LineProcessor base class to JournalLineProcessor and updated all subclasses (CreditJournalLineProcessor, MarketplaceJournalLineProcessor)
  • Added resolve_service_amount() utility function to handle currency conversion and exchange rate calculations
  • Updated AgreementJournalGenerator to detect PLS support type and trigger PLS charge processing
  • Enhanced JournalLineGenerator with is_pls parameter to conditionally exclude support record types when PLS is enabled
  • Added configurable EXT_PLS_CHARGE_PERCENTAGE environment variable with a default value of 5.0% (configurable via Helm values)
  • Updated BillingJournalContext model to include pls_charge_percentage field
  • Added comprehensive test coverage for PLS charge calculations, marketplace tax filtering, and currency conversions

@ruben-sebrango ruben-sebrango requested a review from a team as a code owner March 24, 2026 09:44
@ruben-sebrango ruben-sebrango requested review from d3rky and jentyk March 24, 2026 09:44
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

This PR introduces PLS (Partner Logic Support) charge processing by refactoring the line processor architecture, adding marketplace-specific charge filtering, and integrating a new PLS charge manager into billing journal generation. Configuration is extended to support percentage-based PLS charges via Helm values and application context.

Changes

Cohort / File(s) Summary
Line Processor Architecture
swo_aws_extension/flows/jobs/billing_journal/generators/line_processors/base.py, swo_aws_extension/flows/jobs/billing_journal/generators/line_processors/credit.py, swo_aws_extension/flows/jobs/billing_journal/generators/line_processors/marketplace.py
Renamed LineProcessor to JournalLineProcessor and updated inheritance chain. Added new MarketplaceJournalLineProcessor that filters out "Tax" service records. Delegated currency resolution to external resolve_service_amount(...) utility function.
Journal Line Generation
swo_aws_extension/flows/jobs/billing_journal/generators/journal_line.py
Updated processor registry to use JournalLineProcessor/CreditJournalLineProcessor and route "MARKETPLACE" to new MarketplaceJournalLineProcessor. Added is_pls keyword-only parameter to exclude SUPPORT record type when enabled.
Currency Utilities
swo_aws_extension/flows/jobs/billing_journal/generators/currency.py
Added public resolve_service_amount(...) function to centralize currency conversion logic with exchange-rate handling and rounding.
PLS Charge Processing
swo_aws_extension/flows/jobs/billing_journal/generators/pls_charge_manager.py, tests/flows/jobs/billing_journal/generators/test_pls_charge_manager.py
New PlSChargeManager class processes PLS charges by aggregating usage metrics across accounts, applying percentage-based calculation, and generating a single journal line. Comprehensive test suite validates percentage application, multi-account aggregation, currency conversion, and early-exit conditions.
Agreement Generator Integration
swo_aws_extension/flows/jobs/billing_journal/generators/agreement.py, tests/flows/jobs/billing_journal/generators/test_agreement.py
Updated to derive is_pls flag from support type and pass it to JournalLineGenerator. Integrated PlSChargeManager to append PLS charge lines when applicable. Enhanced test to verify PLS manager invocation and line inclusion.
Configuration & Context
swo_aws_extension/config.py, swo_aws_extension/flows/jobs/billing_journal/models/context.py, swo_aws_extension/management/commands/generate_billing_journals.py, tests/flows/jobs/billing_journal/conftest.py, tests/flows/jobs/billing_journal/models/test_context.py
Added pls_charge_percentage configuration property and context field with default value 5.0. Updated command to pass percentage into context.
Helm Configuration
helm/swo-extension-aws/charts/api/templates/configmap.yaml, helm/swo-extension-aws/charts/worker/templates/configmap.yaml, helm/swo-extension-aws/values.yaml
Extended ConfigMap templates and values to include EXT_PLS_CHARGE_PERCENTAGE with default "5.0".
Test Coverage
tests/flows/jobs/billing_journal/generators/line_processors/test_base.py, tests/flows/jobs/billing_journal/generators/line_processors/test_credit.py, tests/flows/jobs/billing_journal/generators/line_processors/test_marketplace.py, tests/flows/jobs/billing_journal/generators/test_journal_line.py
Updated existing tests to use renamed processors; added comprehensive marketplace processor tests and journal line generator tests for marketplace filtering and PLS exclusion scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • PR #280: Modifies billing_journal generators and models to introduce invoice/organization invoice handling and service metrics infrastructure
  • PR #285: Makes overlapping changes to billing-journal generators and line-processor architecture including processor registry and type updates
  • PR #271: Modifies AgreementJournalGenerator specifically for journal line generation behavior
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Jira Issue Key In Title ✅ Passed The PR title contains exactly one Jira issue key in the required MPT-XXXX format at the beginning.
Test Coverage Required ✅ Passed PR modifies 13 code files and includes 8 test files covering new PLS charge functionality and updated processors, meeting test inclusion requirements.
Single Commit Required ✅ Passed The PR contains exactly one commit (41b324f: MPT-18440 AWS billing transfer: support PLS additional charge), which satisfies the requirement.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
swo_aws_extension/flows/jobs/billing_journal/generators/journal_line.py (1)

34-34: Prefer a named constant/enum for the marketplace record-type key.

Line 34 uses a raw string literal ("MARKETPLACE"), which is easy to drift from upstream record-type values. Use a shared constant (or enum entry) to reduce typo and mismatch risk.

♻️ Suggested tweak
+MARKETPLACE_RECORD_TYPE = "MARKETPLACE"
+
 def _build_processor_registry(*, is_pls: bool = False) -> dict[str, JournalLineProcessor]:
@@
-        "MARKETPLACE": marketplace,
+        MARKETPLACE_RECORD_TYPE: marketplace,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@swo_aws_extension/flows/jobs/billing_journal/generators/journal_line.py` at
line 34, Replace the raw string literal "MARKETPLACE" used as the record-type
key in the dict with a shared constant or enum entry to avoid drift/typos;
locate the literal in journal_line.py (the dict entry with "MARKETPLACE":
marketplace) and import/use the project-wide record-type identifier (for example
RECORD_TYPE_MARKETPLACE or RecordType.MARKETPLACE) instead of the string so the
key is tied to the canonical constant used across the billing_journal codebase.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@swo_aws_extension/flows/jobs/billing_journal/generators/pls_charge_manager.py`:
- Around line 60-68: Replace the hardcoded placeholder invoice_entity value with
the established empty-string fallback used in base.py: when constructing
InvoiceDetails in pls_charge_manager (the InvoiceDetails(...) call used to build
JournalLine via JournalLine.build), set invoice_entity="" instead of
"invoice_entity_name" so the PLS charge follows the same fallback pattern as
other generators.

In `@tests/flows/jobs/billing_journal/generators/test_pls_charge_manager.py`:
- Around line 31-38: build_usage_result currently constructs an
OrganizationUsageResult with reports set to an empty dict which mismatches the
typed OrganizationReport; change build_usage_result to create and pass a proper
OrganizationReport instance (e.g., instantiate OrganizationReport with an
empty/internal-empty payload) instead of {} so
OrganizationUsageResult(reports=OrganizationReport(...), usage_by_account={...})
preserves type safety; update the call site in build_usage_result and ensure
AccountUsage and OrganizationUsageResult usage remains unchanged.

---

Nitpick comments:
In `@swo_aws_extension/flows/jobs/billing_journal/generators/journal_line.py`:
- Line 34: Replace the raw string literal "MARKETPLACE" used as the record-type
key in the dict with a shared constant or enum entry to avoid drift/typos;
locate the literal in journal_line.py (the dict entry with "MARKETPLACE":
marketplace) and import/use the project-wide record-type identifier (for example
RECORD_TYPE_MARKETPLACE or RecordType.MARKETPLACE) instead of the string so the
key is tied to the canonical constant used across the billing_journal codebase.
🪄 Autofix (Beta)

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: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: aaf063c5-634b-4bb6-83da-3a0e34c40d24

📥 Commits

Reviewing files that changed from the base of the PR and between ef880bb and 5ede6b1.

📒 Files selected for processing (14)
  • swo_aws_extension/flows/jobs/billing_journal/generators/agreement.py
  • swo_aws_extension/flows/jobs/billing_journal/generators/currency.py
  • swo_aws_extension/flows/jobs/billing_journal/generators/journal_line.py
  • swo_aws_extension/flows/jobs/billing_journal/generators/line_processors/base.py
  • swo_aws_extension/flows/jobs/billing_journal/generators/line_processors/credit.py
  • swo_aws_extension/flows/jobs/billing_journal/generators/line_processors/marketplace.py
  • swo_aws_extension/flows/jobs/billing_journal/generators/pls_charge_manager.py
  • swo_aws_extension/parameters.py
  • tests/flows/jobs/billing_journal/generators/line_processors/test_base.py
  • tests/flows/jobs/billing_journal/generators/line_processors/test_credit.py
  • tests/flows/jobs/billing_journal/generators/line_processors/test_marketplace.py
  • tests/flows/jobs/billing_journal/generators/test_agreement.py
  • tests/flows/jobs/billing_journal/generators/test_journal_line.py
  • tests/flows/jobs/billing_journal/generators/test_pls_charge_manager.py

@ruben-sebrango ruben-sebrango force-pushed the MPT-18440-aws-billing-transfer-support-pls-additional-discount branch from 5ede6b1 to 41b324f Compare March 24, 2026 12:40
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@swo_aws_extension/config.py`:
- Line 6: Update the config so DEFAULT_PLS_CHARGE_PERCENTAGE and the
EXTENSION_CONFIG lookup return a Decimal instead of float and treat empty or
whitespace values as missing (fall back to Decimal('5.0')); specifically, when
reading PLS_CHARGE_PERCENTAGE from EXTENSION_CONFIG parse/validate using Decimal
(strip whitespace and check emptiness) and default to Decimal('5.0') if blank or
invalid, and then remove the redundant Decimal(str(...)) wrapping in
generate_billing_journals.py (around the value used at the previous line 89)
since the config property now already yields a Decimal.
🪄 Autofix (Beta)

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: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 44c24ce7-bfd8-4af7-bf28-a5cafb7fb6a2

📥 Commits

Reviewing files that changed from the base of the PR and between 5ede6b1 and 41b324f.

📒 Files selected for processing (21)
  • helm/swo-extension-aws/charts/api/templates/configmap.yaml
  • helm/swo-extension-aws/charts/worker/templates/configmap.yaml
  • helm/swo-extension-aws/values.yaml
  • swo_aws_extension/config.py
  • swo_aws_extension/flows/jobs/billing_journal/generators/agreement.py
  • swo_aws_extension/flows/jobs/billing_journal/generators/currency.py
  • swo_aws_extension/flows/jobs/billing_journal/generators/journal_line.py
  • swo_aws_extension/flows/jobs/billing_journal/generators/line_processors/base.py
  • swo_aws_extension/flows/jobs/billing_journal/generators/line_processors/credit.py
  • swo_aws_extension/flows/jobs/billing_journal/generators/line_processors/marketplace.py
  • swo_aws_extension/flows/jobs/billing_journal/generators/pls_charge_manager.py
  • swo_aws_extension/flows/jobs/billing_journal/models/context.py
  • swo_aws_extension/management/commands/generate_billing_journals.py
  • tests/flows/jobs/billing_journal/conftest.py
  • tests/flows/jobs/billing_journal/generators/line_processors/test_base.py
  • tests/flows/jobs/billing_journal/generators/line_processors/test_credit.py
  • tests/flows/jobs/billing_journal/generators/line_processors/test_marketplace.py
  • tests/flows/jobs/billing_journal/generators/test_agreement.py
  • tests/flows/jobs/billing_journal/generators/test_journal_line.py
  • tests/flows/jobs/billing_journal/generators/test_pls_charge_manager.py
  • tests/flows/jobs/billing_journal/models/test_context.py
✅ Files skipped from review due to trivial changes (6)
  • helm/swo-extension-aws/values.yaml
  • helm/swo-extension-aws/charts/api/templates/configmap.yaml
  • swo_aws_extension/flows/jobs/billing_journal/models/context.py
  • helm/swo-extension-aws/charts/worker/templates/configmap.yaml
  • tests/flows/jobs/billing_journal/generators/line_processors/test_marketplace.py
  • tests/flows/jobs/billing_journal/generators/test_pls_charge_manager.py
🚧 Files skipped from review as they are similar to previous changes (7)
  • tests/flows/jobs/billing_journal/generators/line_processors/test_credit.py
  • tests/flows/jobs/billing_journal/generators/test_journal_line.py
  • tests/flows/jobs/billing_journal/generators/line_processors/test_base.py
  • swo_aws_extension/flows/jobs/billing_journal/generators/currency.py
  • tests/flows/jobs/billing_journal/generators/test_agreement.py
  • swo_aws_extension/flows/jobs/billing_journal/generators/line_processors/credit.py
  • swo_aws_extension/flows/jobs/billing_journal/generators/journal_line.py

@d3rky d3rky merged commit 5610405 into main Mar 24, 2026
11 checks passed
@d3rky d3rky deleted the MPT-18440-aws-billing-transfer-support-pls-additional-discount branch March 24, 2026 12:58
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.

2 participants