-
Notifications
You must be signed in to change notification settings - Fork 0
MPT-18440 AWS billing transfer: support PLS additional charge #289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
d3rky
merged 1 commit into
main
from
MPT-18440-aws-billing-transfer-support-pls-additional-discount
Mar 24, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
swo_aws_extension/flows/jobs/billing_journal/generators/currency.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| from decimal import Decimal | ||
|
|
||
| from swo_aws_extension.constants import DEC_ZERO | ||
| from swo_aws_extension.flows.jobs.billing_journal.models.invoice import InvoiceEntity | ||
|
|
||
|
|
||
| def resolve_service_amount( | ||
| amount: Decimal, | ||
| invoice_entity: InvoiceEntity | None, | ||
| ) -> Decimal: | ||
| """Calculate the service amount converted to the local payment currency.""" | ||
| if not invoice_entity: | ||
| return amount | ||
|
|
||
| if invoice_entity.payment_currency_code == invoice_entity.base_currency_code: | ||
| return amount | ||
| if invoice_entity.exchange_rate <= DEC_ZERO: | ||
| return amount | ||
|
|
||
| return round(amount * invoice_entity.exchange_rate, 6) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
swo_aws_extension/flows/jobs/billing_journal/generators/line_processors/marketplace.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from typing import override | ||
|
|
||
| from swo_aws_extension.flows.jobs.billing_journal.generators.line_processors.base import ( | ||
| JournalLineProcessor, | ||
| ) | ||
| from swo_aws_extension.flows.jobs.billing_journal.models.context import LineProcessorContext | ||
| from swo_aws_extension.flows.jobs.billing_journal.models.journal_line import JournalLine | ||
| from swo_aws_extension.flows.jobs.billing_journal.models.usage import ServiceMetric | ||
|
|
||
| TAX_SERVICE_NAME = "Tax" | ||
|
|
||
|
|
||
| class MarketplaceJournalLineProcessor(JournalLineProcessor): | ||
| """Generates journal lines for Marketplace metrics, excluding Tax entries.""" | ||
|
|
||
| @override | ||
| def process( | ||
| self, | ||
| metric: ServiceMetric, | ||
| context: LineProcessorContext, | ||
| ) -> list[JournalLine]: | ||
| """Process a marketplace metric, skipping Tax services. | ||
|
|
||
| Args: | ||
| metric: The service metric to process. | ||
| context: Shared context for the current account. | ||
|
|
||
| Returns: | ||
| List of journal lines (empty if metric is Tax or should be skipped). | ||
| """ | ||
| if metric.service_name == TAX_SERVICE_NAME: | ||
| return [] | ||
| return super().process(metric, context) |
91 changes: 91 additions & 0 deletions
91
swo_aws_extension/flows/jobs/billing_journal/generators/pls_charge_manager.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| from decimal import Decimal | ||
|
|
||
| from swo_aws_extension.constants import ( | ||
| DEC_ZERO, | ||
| AWSRecordTypeEnum, | ||
| ) | ||
| from swo_aws_extension.flows.jobs.billing_journal.generators.currency import ( | ||
| resolve_service_amount, | ||
| ) | ||
| from swo_aws_extension.flows.jobs.billing_journal.models.invoice import OrganizationInvoice | ||
| from swo_aws_extension.flows.jobs.billing_journal.models.journal_line import ( | ||
| InvoiceDetails, | ||
| JournalDetails, | ||
| JournalLine, | ||
| ) | ||
| from swo_aws_extension.flows.jobs.billing_journal.models.usage import ( | ||
| OrganizationUsageResult, | ||
| ) | ||
| from swo_aws_extension.logger import get_logger | ||
|
|
||
| ITEM_SKU = "AWS Usage" | ||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| class PlSChargeManager: | ||
| """Manager to calculate and generate SWO Enterprise Support for AWS (PLS) charges.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| self._service_name = "SWO Enterprise support for AWS" | ||
|
|
||
| def process( | ||
| self, | ||
| charge_percentage: Decimal, | ||
| usage_result: OrganizationUsageResult, | ||
| journal_details: JournalDetails, | ||
| organization_invoice: OrganizationInvoice, | ||
| ) -> list[JournalLine]: | ||
| """Process PLS charge and return journal lines. | ||
|
|
||
| Args: | ||
| charge_percentage: The PLS percentage scalar to compute the charge. | ||
| usage_result: The global organization usage result. | ||
| journal_details: Shared journal details containing the MPA ID. | ||
| organization_invoice: The organization invoice. | ||
|
|
||
| Returns: | ||
| List containing the PLS Charge journal line, if applicable. | ||
| """ | ||
| principal_amount = organization_invoice.principal_invoice_amount | ||
| if principal_amount is None or principal_amount == DEC_ZERO: | ||
| return [] | ||
|
|
||
| if charge_percentage <= DEC_ZERO: | ||
| return [] | ||
|
|
||
| base_amount = self._calculate_base_amount(usage_result, organization_invoice) | ||
| if base_amount <= DEC_ZERO: | ||
| return [] | ||
|
|
||
| charge_amount = self._calculate_charge_amount(base_amount, charge_percentage) | ||
|
|
||
| invoice_details = InvoiceDetails( | ||
| item_sku=ITEM_SKU, | ||
| service_name=self._service_name, | ||
| amount=charge_amount, | ||
| account_id=journal_details.mpa_id, | ||
| invoice_entity="", | ||
| invoice_id="invoice_id", | ||
| ) | ||
| return [JournalLine.build(ITEM_SKU, journal_details, invoice_details)] | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def _calculate_base_amount( | ||
| self, | ||
| usage_result: OrganizationUsageResult, | ||
| organization_invoice: OrganizationInvoice, | ||
| ) -> Decimal: | ||
| total = DEC_ZERO | ||
| for account_usage in usage_result.usage_by_account.values(): | ||
| usage_metrics = list(account_usage.get_metrics_by_record_type(AWSRecordTypeEnum.USAGE)) | ||
| total += sum( | ||
| resolve_service_amount( | ||
| metric.amount, | ||
| organization_invoice.entities.get(metric.invoice_entity or ""), | ||
| ) | ||
| for metric in usage_metrics | ||
| ) | ||
| return total | ||
|
|
||
| def _calculate_charge_amount(self, base_amount: Decimal, percentage: Decimal) -> Decimal: | ||
| charge = base_amount * (percentage / Decimal(100)) | ||
| return round(charge, 6) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.