Skip to content

[Master]- Recurring billing is stuck due to an error related to updating the Subscription Line table#7404

Open
neeleshsinghal wants to merge 6 commits intomicrosoft:mainfrom
neeleshsinghal:bugs/Bug-623011-Recurring-billing-related-to-updating-the-Subscription-Line
Open

[Master]- Recurring billing is stuck due to an error related to updating the Subscription Line table#7404
neeleshsinghal wants to merge 6 commits intomicrosoft:mainfrom
neeleshsinghal:bugs/Bug-623011-Recurring-billing-related-to-updating-the-Subscription-Line

Conversation

@neeleshsinghal
Copy link
Contributor

@neeleshsinghal neeleshsinghal commented Mar 26, 2026

AB#629263

Work Item Bug 629263: [master] [ALL-E] Recurring billing is stuck due to an error related to updating the Subscription Line table

Fixes AB#629263

@github-actions github-actions bot added AL: Apps (W1) Add-on apps for W1 From Fork Pull request is coming from a fork Linked Issue is linked to a Azure Boards work item labels Mar 26, 2026
@github-actions github-actions bot modified the milestone: Version 29.0 Mar 26, 2026
@neeleshsinghal neeleshsinghal marked this pull request as ready for review March 26, 2026 08:47
@neeleshsinghal neeleshsinghal requested a review from a team as a code owner March 26, 2026 08:47
@JesperSchulz JesperSchulz added the Finance GitHub request for Finance area label Mar 27, 2026
JesperSchulz
JesperSchulz previously approved these changes Mar 27, 2026
@JesperSchulz JesperSchulz requested a review from Copilot March 27, 2026 08:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes recurring billing getting stuck by preventing Subscription Line.CalculateNextToDate (with “Align to End of Month”) from returning a NextToDate earlier than FromDate, and adds a regression test for AB#623011.

Changes:

  • Add guard logic in Subscription Line date calculation to clamp NextToDate when it would fall before FromDate.
  • Add a new test verifying CalculateNextToDate does not return a date before FromDate for “Align to End of Month”.
  • Add a small helper to mock/insert a Subscription Line record for the test.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
.../RecurringBillingDocsTest.Codeunit.al Adds regression test + helper for reproducing and validating AB#623011 scenario
.../SubscriptionLine.Table.al Adjusts CalculateNextToDate logic to avoid returning a date before FromDate

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1949 to +1950
if NextToDate < FromDate then
NextToDate := CalcDate(PeriodFormula, FromDate) - 1;
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

This fix can still yield NextToDate < FromDate if CalcDate(PeriodFormula, FromDate) returns FromDate (e.g., a zero/empty period formula, if permitted), since subtracting 1 would move it earlier. To fully enforce the invariant, clamp the result (e.g., set NextToDate to FromDate when the computed value would be earlier) so NextToDate is guaranteed to be >= FromDate for all allowed PeriodFormula values.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

@neeleshsinghal neeleshsinghal requested a review from Copilot March 27, 2026 09:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

Could not find linked issues in the pull request description. Please make sure the pull request description contains a line that contains 'Fixes #' followed by the issue number being fixed. Use that pattern for every issue you want to link.

…DocsTest.Codeunit.al

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
neeleshsinghal and others added 2 commits March 27, 2026 15:13
…DocsTest.Codeunit.al

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…DocsTest.Codeunit.al

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@neeleshsinghal neeleshsinghal requested a review from Copilot March 27, 2026 09:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2478 to +2480
LibraryLowerPermissions.SetO365Full();
NextToDate := SubscriptionLine.CalculateNextToDate(PeriodFormula, FromDate);
LibraryLowerPermissions.RestoreO365Permissions();
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

If CalculateNextToDate errors, RestoreO365Permissions() will not run, which can leak elevated permissions into subsequent tests and cause cross-test interference. Consider wrapping the call in a [TryFunction] helper (or an existing run-with-permissions utility if available) so permissions are always restored on both success and failure paths.

Copilot uses AI. Check for mistakes.
@neeleshsinghal neeleshsinghal requested a review from Copilot March 27, 2026 09:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2478 to +2486
LibraryLowerPermissions.SetO365Full();
NextToDate := SubscriptionLine.CalculateNextToDate(PeriodFormula, FromDate);
LibraryLowerPermissions.RestoreO365Permissions();

// [THEN] NextToDate is not before FromDate
Assert.IsTrue(NextToDate >= FromDate,
StrSubstNo(NextToDateBeforeFromDateErr, NextToDate, FromDate));
end;

Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

RestoreO365Permissions() won’t run if CalculateNextToDate(...) throws, which can leak elevated permissions into subsequent tests and cause cascading failures. Consider wrapping the calculation in a [TryFunction] helper (or equivalent test utility) so permissions are restored on both success and failure, and then rethrow the captured error after restoring permissions.

Suggested change
LibraryLowerPermissions.SetO365Full();
NextToDate := SubscriptionLine.CalculateNextToDate(PeriodFormula, FromDate);
LibraryLowerPermissions.RestoreO365Permissions();
// [THEN] NextToDate is not before FromDate
Assert.IsTrue(NextToDate >= FromDate,
StrSubstNo(NextToDateBeforeFromDateErr, NextToDate, FromDate));
end;
NextToDate := CalculateNextToDateWithO365Permissions(SubscriptionLine, PeriodFormula, FromDate);
// [THEN] NextToDate is not before FromDate
Assert.IsTrue(NextToDate >= FromDate,
StrSubstNo(NextToDateBeforeFromDateErr, NextToDate, FromDate));
Assert.IsTrue(NextToDate >= FromDate,
StrSubstNo(NextToDateBeforeFromDateErr, NextToDate, FromDate));
end;
local procedure CalculateNextToDateWithO365Permissions(var SubscriptionLine: Record "Subscription Line"; PeriodFormula: DateFormula; FromDate: Date): Date
var
NextToDate: Date;
begin
LibraryLowerPermissions.SetO365Full();
if not TryCalculateNextToDate(SubscriptionLine, PeriodFormula, FromDate, NextToDate) then begin
LibraryLowerPermissions.RestoreO365Permissions();
Error(GetLastErrorText());
end;
LibraryLowerPermissions.RestoreO365Permissions();
exit(NextToDate);
end;
[TryFunction]
local procedure TryCalculateNextToDate(var SubscriptionLine: Record "Subscription Line"; PeriodFormula: DateFormula; FromDate: Date; var NextToDate: Date)
begin
NextToDate := SubscriptionLine.CalculateNextToDate(PeriodFormula, FromDate);
end;

Copilot uses AI. Check for mistakes.
@neeleshsinghal neeleshsinghal requested a review from Copilot March 27, 2026 09:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1949 to +1950
if NextToDate < FromDate then
NextToDate := CalcDate(PeriodFormula, FromDate) - 1;
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

Coverage gap: the new safeguard is only regression-tested for <1D> with a specific date combination. Add at least one additional test that exercises a formula that could evaluate to FromDate (if such formulas are supported) to ensure the fix truly prevents NextToDate < FromDate across valid inputs.

Copilot uses AI. Check for mistakes.
neeleshsinghal and others added 2 commits March 27, 2026 15:49
…DocsTest.Codeunit.al

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…DocsTest.Codeunit.al

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AL: Apps (W1) Add-on apps for W1 Finance GitHub request for Finance area From Fork Pull request is coming from a fork Linked Issue is linked to a Azure Boards work item

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants