[Bug][SubscriptionBilling] Process Usage Data Billing uses lines marked Processing Status = Error (currency mismatch)
Nobody has claimed this yet.
- Dominant language
- AL
- Stars
- 683
- Forks
- 459
- Avg merge
- 3d 26m
- Merged PRs (30d)
- 633
Description
Describe the issue
When the currency of a usage data import does not match the currency of the Customer/Vendor Subscription Contract, and the contract's Subscription Contract Type disallows a different currency (Allow Diff. Curr. in Cust. UD / Allow Diff. Curr. in Vend. UD = false), the Create Usage Data Billing step correctly marks the Usage Data Billing line with Processing Status = Error.
This happens in table 8022 "Usage Data Billing", procedure AlignContractCurrency, in src/Apps/W1/Subscription Billing/App/Usage Based Billing/Tables/UsageDataBilling.Table.al:
if AllowDiffCurrency then
Rec."Currency Code" := TempSubscriptionLine."Currency Code"
else begin
Rec."Currency Code" := ImportCurrencyCode;
Rec."Processing Status" := Enum::"Processing Status"::Error;
Rec.SetReason(CurrencyMismatchErr);
end;
However, the subsequent Process Usage Data Billing step (codeunit 8026 "Process Usage Data Billing", src/Apps/W1/Subscription Billing/App/Usage Based Billing/Codeunits/ProcessUsageDataBilling.Codeunit.al) never checks Processing Status. Its Code() procedure filters Usage Data Billing on only three fields:
UsageDataBilling.SetRange("Usage Data Import Entry No.", UsageDataImport."Entry No.");
UsageDataBilling.SetRange("Document No.", '');
UsageDataBilling.SetFilter("Subscription Contract No.", '<>%1', '');
As a result, the errored lines are still processed:
CalculateCustomerUsageDataBillingPricerecalculates and overwrites the line's"Unit Price"andAmountusing the contract currency, despite the currency-mismatch rejection.ProcessServiceCommitmentthen uses those lines to update theSubscription HeaderQuantityand theSubscription LinePrice/"Unit Cost"/"Unit Cost (LCY)". BecauseCommit()is called afterUpdateServiceObjectQuantity, these writes are not rolled back by any later error.- The aggregation helpers —
FindUsageDataBilling,CalculateTotalUsageBillingQuantity,CalculateSumCostAmountFromUsageDataBilling,CalculateSumAmountFromUsageDataBilling— sum over the errored lines too, so a subscription line with a mix of valid and errored usage rows gets incorrect totals.
The error marking is therefore cosmetic: data the system explicitly refused to trust is still used to recalculate amounts and to update the Subscription and Subscription Line.
Expected behavior
Usage Data Billing lines with Processing Status = Error must be skipped by the Process Usage Data Billing step. Their amounts must not be recalculated, and they must not contribute to the values written back to the Subscription Header or Subscription Line.
Steps to reproduce
- Create a Customer and a Vendor with a non-blank
Currency Code, then create aCustomer Subscription Contractand aVendor Subscription Contractfor them with usage-based Subscription Lines. - Assign
Subscription Contract Types to both contracts withAllow Diff. Curr. in Cust. UD=falseandAllow Diff. Curr. in Vend. UD=false. - Create a Usage Data Import (Generic supplier) whose imported usage data has no currency code, so the import currency differs from the contract currency. Use
Usage Based Pricing=Usage Quantityand a supplier withUnit Price from Import=false. - Run the Create Usage Data Billing processing step. The Usage Data Billing lines get
Processing Status=Errorwith the currency-mismatch reason;Unit PriceandAmountare0. - Run the Process Usage Data Billing processing step.
Actual: the errored lines get a Unit Price and Amount calculated, and the Subscription Header Quantity plus the Subscription Line Price / Unit Cost are updated from the rejected data.
Expected: the lines keep Processing Status = Error, Unit Price and Amount stay 0, and the Subscription Header and Subscription Line are left untouched.
Additional context
No response
I will provide a fix for a bug
- I will provide a fix for a bug
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/Apps/W1/Subscription Billing/App/Usage Based Billing/Codeunits/ProcessUsageDataBilling.Codeunit.al, especially Code(), and compare its filters with the Processing Status requirement. Review AlignContractCurrency in src/Apps/W1/Subscription Billing/App/Usage Based Billing/Tables/UsageDataBilling.Table.al, then run the reproduction steps. Done means errored lines remain unchanged and do not affect subscription totals or updates.
Written by the indexing model from the issue text.
Assessment
- Domain
- backend, payments
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100