Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ namespace Microsoft.SubscriptionBilling;
#if not CLEANSCHEMA29
using Microsoft.Finance.GeneralLedger.Setup;
#endif
using Microsoft.Purchases.History;
using Microsoft.Sales.Document;
using Microsoft.Sales.History;
using System.Upgrade;

codeunit 8032 "Upgrade Subscription Billing"
Expand All @@ -28,6 +30,7 @@ codeunit 8032 "Upgrade Subscription Billing"
UpdateCreateContractDeferralsFlag();
DeleteSalesSubscriptionLinesConnectedToDeletedQuote();
RemoveDocumentNoFromBillingLines();
FillPostingGroupsInContractDeferrals();
end;

#if not CLEANSCHEMA29
Expand Down Expand Up @@ -321,6 +324,83 @@ codeunit 8032 "Upgrade Subscription Billing"
exit('MS-XXXXXX-RemoveDocumentNoFromBillingLines-20250819');
end;

local procedure FillPostingGroupsInContractDeferrals()
var
CustContractDeferral: Record "Cust. Sub. Contract Deferral";
VendContractDeferral: Record "Vend. Sub. Contract Deferral";
UpgradeTag: Codeunit "Upgrade Tag";
begin
if UpgradeTag.HasUpgradeTag(FillPostingGroupsInContractDeferralsTag()) then
exit;

CustContractDeferral.SetRange("Gen. Bus. Posting Group", '');
CustContractDeferral.SetRange("Gen. Prod. Posting Group", '');
if CustContractDeferral.FindSet(true) then
repeat
UpdateCustDeferralPostingGroups(CustContractDeferral);
until CustContractDeferral.Next() = 0;

VendContractDeferral.SetRange("Gen. Bus. Posting Group", '');
VendContractDeferral.SetRange("Gen. Prod. Posting Group", '');
if VendContractDeferral.FindSet(true) then
repeat
UpdateVendDeferralPostingGroups(VendContractDeferral);
until VendContractDeferral.Next() = 0;

UpgradeTag.SetUpgradeTag(FillPostingGroupsInContractDeferralsTag());
end;

local procedure UpdateCustDeferralPostingGroups(var CustContractDeferral: Record "Cust. Sub. Contract Deferral")
var
SalesInvoiceLine: Record "Sales Invoice Line";
SalesCrMemoLine: Record "Sales Cr.Memo Line";
CustContractDeferralToUpdate: Record "Cust. Sub. Contract Deferral";
begin
CustContractDeferralToUpdate := CustContractDeferral;
case CustContractDeferral."Document Type" of
"Rec. Billing Document Type"::Invoice:
if SalesInvoiceLine.Get(CustContractDeferral."Document No.", CustContractDeferral."Document Line No.") then begin
CustContractDeferralToUpdate."Gen. Bus. Posting Group" := SalesInvoiceLine."Gen. Bus. Posting Group";
CustContractDeferralToUpdate."Gen. Prod. Posting Group" := SalesInvoiceLine."Gen. Prod. Posting Group";
CustContractDeferralToUpdate.Modify(false);
end;
"Rec. Billing Document Type"::"Credit Memo":
if SalesCrMemoLine.Get(CustContractDeferral."Document No.", CustContractDeferral."Document Line No.") then begin
CustContractDeferralToUpdate."Gen. Bus. Posting Group" := SalesCrMemoLine."Gen. Bus. Posting Group";
CustContractDeferralToUpdate."Gen. Prod. Posting Group" := SalesCrMemoLine."Gen. Prod. Posting Group";
CustContractDeferralToUpdate.Modify(false);
end;
end;
end;

local procedure UpdateVendDeferralPostingGroups(var VendContractDeferral: Record "Vend. Sub. Contract Deferral")
var
PurchInvLine: Record "Purch. Inv. Line";
PurchCrMemoLine: Record "Purch. Cr. Memo Line";
VendContractDeferralToUpdate: Record "Vend. Sub. Contract Deferral";
begin
VendContractDeferralToUpdate := VendContractDeferral;
case VendContractDeferral."Document Type" of
"Rec. Billing Document Type"::Invoice:
if PurchInvLine.Get(VendContractDeferral."Document No.", VendContractDeferral."Document Line No.") then begin
VendContractDeferralToUpdate."Gen. Bus. Posting Group" := PurchInvLine."Gen. Bus. Posting Group";
VendContractDeferralToUpdate."Gen. Prod. Posting Group" := PurchInvLine."Gen. Prod. Posting Group";
VendContractDeferralToUpdate.Modify(false);
end;
"Rec. Billing Document Type"::"Credit Memo":
if PurchCrMemoLine.Get(VendContractDeferral."Document No.", VendContractDeferral."Document Line No.") then begin
VendContractDeferralToUpdate."Gen. Bus. Posting Group" := PurchCrMemoLine."Gen. Bus. Posting Group";
VendContractDeferralToUpdate."Gen. Prod. Posting Group" := PurchCrMemoLine."Gen. Prod. Posting Group";
VendContractDeferralToUpdate.Modify(false);
end;
end;
end;

local procedure FillPostingGroupsInContractDeferralsTag(): Text[250]
begin
exit('MS-623188-FillPostingGroupsInContractDeferrals-20250209');
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Upgrade Tag", OnGetPerCompanyUpgradeTags, '', false, false)]
local procedure RegisterPerCompanyTags(var PerCompanyUpgradeTags: List of [Code[250]])
begin
Expand All @@ -335,5 +415,6 @@ codeunit 8032 "Upgrade Subscription Billing"
PerCompanyUpgradeTags.Add(GetUpdateCreateContractDeferralsFlag());
PerCompanyUpgradeTags.Add(DeleteSalesSubscriptionLinesConnectedToDeletedQuoteTag());
PerCompanyUpgradeTags.Add(RemoveDocumentNoFromBillingLinesTag());
PerCompanyUpgradeTags.Add(FillPostingGroupsInContractDeferralsTag());
end;
}
Loading