-
Notifications
You must be signed in to change notification settings - Fork 257
Deletion of Document Lines Leaves Incorrect Usage Data References #4862
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
base: main
Are you sure you want to change the base?
Deletion of Document Lines Leaves Incorrect Usage Data References #4862
Conversation
@microsoft-github-policy-service agree [company="Singhammer IT Consulting AG"] |
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test TestBillingLineInUsageDataNoWhenBillingProposalIsCreated is failing.
if UsageDataBilling.FindSet() then | ||
repeat | ||
UsageDataBilling."Billing Line Entry No." := BillingLine."Entry No."; | ||
UsageDataBilling.Modify(false); | ||
until UsageDataBilling.Next() = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to use ModifyAll() here instead of Looping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
exit; | ||
if Rec.IsTemporary then | ||
exit; | ||
PurchaseHeader.Get(Rec."Document Type", Rec."Document No."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a built in function named FilterDocumentWithLine in Usage Data Billing table. Can we use this one instead? I would like to avoid unintentionally breaking whatever might have been programmed at any other BC client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
exit; | ||
if Rec.IsTemporary then | ||
exit; | ||
SalesHeader.Get(Rec."Document Type", Rec."Document No."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For whatever reason there might be Sales Lines without existing Sales Header. I would thus prefer conditional Get.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
UsageDataBilling.FilterOnServiceCommitment(SubscriptionLine); | ||
UsageDataBilling.SetRange("Document Type", "Usage Based Billing Doc. Type"::None); | ||
UsageDataBilling.SetFilter("Charge Start Date", '<=%1', BillingLine."Billing from"); | ||
UsageDataBilling.SetFilter("Charge End Date", '>=%1', BillingLine."Billing to"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a function named SetUsageDataBillingFilters. Can we use this one? Or perhaps even IsUsageDataBillingFound? In this case this loop can convert to a two liner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filtering is completely different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is charge end date before charge start date?
The idea is that one Usage Data Billing can have multiple BIlling Lines. Let's say yearly Usage data will have 12 billing lines with different Billing To, and we need to "catch" them all. Let's discuss it if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, my fault. Sorry.
UsageDataBilling.FilterDocumentWithLine("Service Partner"::Vendor, UsageBasedDocTypeConv.ConvertPurchaseDocTypeToUsageBasedBillingDocType(Rec."Document Type"), Rec."Document No.", Rec."Line No."); | ||
if UsageDataBilling.IsEmpty() then | ||
exit; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a built in function named FilterDocumentWithLine in Usage Data Billing table. Can we use this one instead?
UsageDataBilling.FilterDocumentWithLine("Service Partner"::Customer, UsageBasedDocTypeConv.ConvertSalesDocTypeToUsageBasedBillingDocType(Rec."Document Type"), Rec."Document No.", Rec."Line No."); | ||
if UsageDataBilling.IsEmpty() then | ||
exit; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a built in function named FilterDocumentWithLine in Usage Data Billing table. Can we use this one instead? I would like to avoid unintentionally breaking whatever might have been programmed at any other BC client.
local procedure ClearUsageDataBillingDocumentValues(var UsageDataBilling: Record "Usage Data Billing") | ||
begin | ||
if UsageDataBilling.FindSet() then | ||
repeat | ||
UsageDataBilling.SaveDocumentValues(UsageDataBilling."Document Type"::None, '', 0, 0); | ||
until UsageDataBilling.Next() = 0; | ||
end; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same code exist in the function RemoveDocumentValuesFromUsageDataBilling. I think the function RemoveDocumentValuesFromUsageDataBilling should also call the function ClearUsageDataBillingDocumentValues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
[HandlerFunctions('ExchangeRateSelectionModalPageHandler,CreateCustomerBillingDocumentPageHandler,MessageHandler')] | ||
[Test] | ||
procedure DeleteUsageDataBillingLineWhenRelatedSalesInvoiceLineIsDeleted() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function name is misleading as the Scenario states that some fields in Usage Data Billing are cleared but the record is not deleted. I guess also that the Test should not check if there are not Usage Data Billings for the Invoice Line but if the Usage Data Billing has been cleared.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scenario + test is updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update of scenario and test is incorrect. This function does NOT delete the UsageDataBilling. It should only test clearing the "Billing Line Entry No.".
|
||
[HandlerFunctions('ExchangeRateSelectionModalPageHandler,CreateVendorBillingDocumentPageHandler,MessageHandler')] | ||
[Test] | ||
procedure DeleteUsageDataBillingLineWhenRelatedPurchLineIsDeleted() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function name is misleading as the Scenario states that some fields in Usage Data Billing are cleared but the record is not deleted. Also the name of function is missing the word "Invoice". I guess also that the Test should not check if there are not Usage Data Billings for the Invoice Line but if the Usage Data Billing has been cleared.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scenario + test is updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update of scenario and test is incorrect. This function does NOT delete the UsageDataBilling. It should only test clearing the "Billing Line Entry No.".
src/Apps/W1/Subscription Billing/Test/UBB/UsageBasedBillingTest.Codeunit.al
Outdated
Show resolved
Hide resolved
UsageDataBilling.FilterOnServiceCommitment(SubscriptionLine); | ||
UsageDataBilling.SetRange("Document Type", "Usage Based Billing Doc. Type"::None); | ||
UsageDataBilling.SetFilter("Charge Start Date", '<=%1', BillingLine."Billing from"); | ||
UsageDataBilling.SetFilter("Charge End Date", '>=%1', BillingLine."Billing to"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
[HandlerFunctions('ExchangeRateSelectionModalPageHandler,CreateCustomerBillingDocumentPageHandler,MessageHandler')] | ||
[Test] | ||
procedure DeleteUsageDataBillingLineWhenRelatedSalesInvoiceLineIsDeleted() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update of scenario and test is incorrect. This function does NOT delete the UsageDataBilling. It should only test clearing the "Billing Line Entry No.".
|
||
[HandlerFunctions('ExchangeRateSelectionModalPageHandler,CreateVendorBillingDocumentPageHandler,MessageHandler')] | ||
[Test] | ||
procedure DeleteUsageDataBillingLineWhenRelatedPurchLineIsDeleted() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update of scenario and test is incorrect. This function does NOT delete the UsageDataBilling. It should only test clearing the "Billing Line Entry No.".
src/Apps/W1/Subscription Billing/Test/UBB/UsageBasedBillingTest.Codeunit.al
Show resolved
Hide resolved
if UsageDataBilling.FindSet() then | ||
repeat | ||
// Check if usage data period overlaps with billing line period | ||
if IsPeriodsOverlapping(UsageDataBilling."Charge Start Date", UsageDataBilling."Charge End Date", | ||
BillingLine."Billing from", BillingLine."Billing to") then begin | ||
UsageDataBilling."Billing Line Entry No." := BillingLine."Entry No."; | ||
UsageDataBilling.Modify(false); | ||
end; | ||
until UsageDataBilling.Next() = 0; | ||
end; | ||
|
||
local procedure IsPeriodsOverlapping(UsageStartDate: Date; UsageEndDate: Date; BillingStartDate: Date; BillingEndDate: Date): Boolean | ||
begin | ||
exit((UsageStartDate <= BillingEndDate) and (UsageEndDate >= BillingStartDate)); | ||
end; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part could still be aligned with the function that serve the purpose of checking if there are Usage Data Billing connected to a Billing Line. The function is called SetUsageDataBillingFilters in Subscription Lines. Otherwise, we introduce code redundancy that can be avoided. The proposed solution fixes an issue but deserves a bit of optimization. Also, it is better to use ModifyAll after filters have been set.
Head branch was pushed to by a user without write access
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move ahead
Please remove 'CorrectPostedPurchInvoice' |
var | ||
PurchCrMemoHeader: Record "Purchase Header"; | ||
PurchInvHeader: Record "Purch. Inv. Header"; | ||
CorrectPostedPurchInvoice: Codeunit "Correct Posted Purch. Invoice"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this one. It have become an error after moving to BCAPPS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
Head branch was pushed to by a user without write access
b4de3b8
Summary
Fix incorrect usage data handling in usage-based contracts. Deleting invoice or credit memo lines currently leaves stale or unlinked usage data entries. The solution ensures related usage data is reset or removed properly while keeping posted-linked records intact.
Work Item(s)
Fixes AB#4856