Skip to content

Commit 3fd6438

Browse files
authored
[Bug][SubscriptionBilling]: Customer cannot be changed on contract with closed subscription lines for 28.x (#7481)
<!-- Thank you for submitting a Pull Request. If you're new to contributing to BCApps please read our pull request guideline below * https://github.com/microsoft/BCApps/Contributing.md --> #### Summary <!-- Provide a general summary of your changes --> This is a backport of the PR #7070 #### Work Item(s) <!-- Add the issue number here after the #. The issue needs to be open and approved. Submitting PRs with no linked issues or unapproved issues is highly discouraged. --> Fixes ##6970 [AB#631933](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/631933)
1 parent 37bc083 commit 3fd6438

3 files changed

Lines changed: 50 additions & 6 deletions

File tree

src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ table 8059 "Subscription Line"
882882
OnAfterCalculateServiceAmount(Rec, CalledByFieldNo);
883883
end;
884884

885-
local procedure SetUpdateRequiredOnBillingLines()
885+
internal procedure SetUpdateRequiredOnBillingLines()
886886
var
887887
BillingLine: Record "Billing Line";
888888
begin
@@ -1347,7 +1347,9 @@ table 8059 "Subscription Line"
13471347
repeat
13481348
#pragma warning disable AA0214
13491349
ServiceCommitment.ResetAmountsAndCurrencyFromLCY();
1350-
ServiceCommitment.Modify(true);
1350+
ServiceCommitment.SetUpdateRequiredOnBillingLines();
1351+
ServiceCommitment.ArchiveServiceCommitment();
1352+
ServiceCommitment.Modify(false);
13511353
#pragma warning restore AA0214
13521354
until ServiceCommitment.Next() = 0;
13531355
end;
@@ -1371,7 +1373,9 @@ table 8059 "Subscription Line"
13711373
CurrencyCode := ServiceCommitment."Currency Code";
13721374
ServiceCommitment.SetCurrencyData(CurrencyFactor, CurrencyFactorDate, CurrencyCode);
13731375
ServiceCommitment.RecalculateAmountsFromCurrencyData();
1374-
ServiceCommitment.Modify(true);
1376+
ServiceCommitment.SetUpdateRequiredOnBillingLines();
1377+
ServiceCommitment.ArchiveServiceCommitment();
1378+
ServiceCommitment.Modify(false);
13751379
until ServiceCommitment.Next() = 0;
13761380
end;
13771381

src/Apps/W1/Subscription Billing/App/Service Objects/Tables/SubscriptionHeader.Table.al

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,9 +2035,10 @@ table 8057 "Subscription Header"
20352035
if FieldCaption(Quantity) <> ChangedFieldName then
20362036
ServiceCommitment.CalculateCalculationBaseAmount();
20372037
ServiceCommitment.Validate("Calculation Base Amount");
2038-
if SkipArchiving then
2039-
ServiceCommitment.SetSkipArchiving(true);
2040-
ServiceCommitment.Modify(true);
2038+
ServiceCommitment.SetUpdateRequiredOnBillingLines();
2039+
if not SkipArchiving then
2040+
ServiceCommitment.ArchiveServiceCommitment();
2041+
ServiceCommitment.Modify(false);
20412042
until ServiceCommitment.Next() = 0;
20422043
end else
20432044
if (not Confirmed) and (FieldCaption("Variant Code") = ChangedFieldName) then

src/Apps/W1/Subscription Billing/Test/Customer Contracts/ContractsTest.Codeunit.al

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,45 @@ codeunit 148155 "Contracts Test"
20532053
Assert.AreEqual(TestDesc, ServiceCommitment.Description, StrSubstNo(SubscLineDescErr, TestDesc));
20542054
end;
20552055

2056+
[Test]
2057+
[HandlerFunctions('ExchangeRateSelectionModalPageHandler,MessageHandler')]
2058+
procedure ChangeSellToCustomerOnContractWithClosedSubscriptionLines()
2059+
var
2060+
Customer: Record Customer;
2061+
CustomerContract: Record "Customer Subscription Contract";
2062+
CustomerContractLine: Record "Cust. Sub. Contract Line";
2063+
NewCustomer: Record Customer;
2064+
ServiceCommitment: Record "Subscription Line";
2065+
ServiceObject: Record "Subscription Header";
2066+
begin
2067+
// [SCENARIO] Changing the Sell-to Customer on a contract that has closed subscription lines should succeed without error.
2068+
Initialize();
2069+
2070+
// [GIVEN] A customer contract with a service commitment linked to a contract line.
2071+
SetupServiceObjectForNewItemWithServiceCommitment(Customer, ServiceObject, false, false);
2072+
ContractTestLibrary.CreateCustomerContractAndCreateContractLinesForItems(CustomerContract, ServiceObject, Customer."No.");
2073+
2074+
// [GIVEN] The contract line and its subscription line are both marked as closed (as done by UpdateServiceCommitmentAndCloseCustomerContractLine).
2075+
CustomerContractLine.SetRange("Subscription Contract No.", CustomerContract."No.");
2076+
CustomerContractLine.SetRange("Contract Line Type", Enum::"Contract Line Type"::Item);
2077+
CustomerContractLine.FindFirst();
2078+
CustomerContractLine.GetServiceCommitment(ServiceCommitment);
2079+
ServiceCommitment.Closed := true;
2080+
ServiceCommitment.Modify(false);
2081+
CustomerContractLine.Closed := true;
2082+
CustomerContractLine.Modify(false);
2083+
2084+
// [GIVEN] A second customer to change the contract to.
2085+
ContractTestLibrary.CreateCustomerInLCY(NewCustomer);
2086+
2087+
// [WHEN] Changing the Sell-to Customer - should not throw an error even though closed subscription lines exist.
2088+
CustomerContract.SetHideValidationDialog(true);
2089+
CustomerContract.Validate("Sell-to Customer No.", NewCustomer."No.");
2090+
2091+
// [THEN] The customer is changed successfully.
2092+
CustomerContract.TestField("Sell-to Customer No.", NewCustomer."No.");
2093+
end;
2094+
20562095
#endregion Tests
20572096

20582097
#region Procedures

0 commit comments

Comments
 (0)