From b71ecf3044b52bc7fabe58e82df161ac041f015f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Holu=C5=A1a?= Date: Thu, 23 Jul 2026 11:28:09 +0200 Subject: [PATCH 1/3] Enhance FA General Report logic and add tests for Tax Deprec. Group and FA Posting Group handling --- .../Codeunits/FAGeneralReportCZF.Codeunit.al | 4 +- .../test/Src/FixedAssetsCZF.Codeunit.al | 82 +++++++++++++++++++ .../FixedAsset/FAGeneralReport.Codeunit.al | 2 +- .../ERMFixedAssetsReportsII.Codeunit.al | 64 +++++++++++++++ 4 files changed, 150 insertions(+), 2 deletions(-) diff --git a/src/Apps/CZ/FixedAssetLocalization/app/Src/Codeunits/FAGeneralReportCZF.Codeunit.al b/src/Apps/CZ/FixedAssetLocalization/app/Src/Codeunits/FAGeneralReportCZF.Codeunit.al index dff65021d57..fbdfa048253 100644 --- a/src/Apps/CZ/FixedAssetLocalization/app/Src/Codeunits/FAGeneralReportCZF.Codeunit.al +++ b/src/Apps/CZ/FixedAssetLocalization/app/Src/Codeunits/FAGeneralReportCZF.Codeunit.al @@ -24,7 +24,9 @@ codeunit 31246 "FA General Report CZF" if FixedAsset.FindSet() then repeat if FADepreciationBook.Get(FixedAsset."No.", DeprBookCode) then - if FixedAsset."Tax Deprec. Group Code CZF" <> FADepreciationBook."Tax Deprec. Group Code CZF" then begin + if (FixedAsset."Tax Deprec. Group Code CZF" <> FADepreciationBook."Tax Deprec. Group Code CZF") and + (FADepreciationBook."Tax Deprec. Group Code CZF" <> '') + then begin FixedAsset."Tax Deprec. Group Code CZF" := FADepreciationBook."Tax Deprec. Group Code CZF"; FixedAsset.Modify(); end; diff --git a/src/Apps/CZ/FixedAssetLocalization/test/Src/FixedAssetsCZF.Codeunit.al b/src/Apps/CZ/FixedAssetLocalization/test/Src/FixedAssetsCZF.Codeunit.al index c92b4193cdf..b6568dc2523 100644 --- a/src/Apps/CZ/FixedAssetLocalization/test/Src/FixedAssetsCZF.Codeunit.al +++ b/src/Apps/CZ/FixedAssetLocalization/test/Src/FixedAssetsCZF.Codeunit.al @@ -280,6 +280,88 @@ codeunit 148087 "Fixed Assets CZF" GLEntry.TestField("G/L Account No.", FAExtendedPostingGroupCZF."Sales Acc. On Disp. (Gain)"); end; + [Test] + procedure SetFATaxDeprGroupDoesNotClearTaxDepreciationGroupWhenDepreciationBookTaxDepGroupIsBlank() + var + FASetup: Record "FA Setup"; + FixedAsset: Record "Fixed Asset"; + FADepreciationBook: Record "FA Depreciation Book"; + TaxDepreciationGroupCZF: Record "Tax Depreciation Group CZF"; + FAGeneralReportCZF: Codeunit "FA General Report CZF"; + OriginalTaxDepGroupCode: Code[20]; + begin + // [SCENARIO] SetFATaxDeprGroup does not clear Tax Deprec. Group Code CZF on Fixed Asset + // when FA Depreciation Book has blank Tax Deprec. Group Code CZF. + + Initialize(); + FASetup.Get(); + + // [GIVEN] Fixed Asset and FA Depreciation Book with Tax Deprec. Group Code CZF are created. + CreateFixedAsset(FixedAsset); + CreateTaxDepreciationGroupCZF(TaxDepreciationGroupCZF, TaxDepreciationGroupCZF."Depreciation Type"::"Straight-line"); + CreateFADepreciationBook( + FADepreciationBook, FixedAsset."No.", + FASetup."Tax Depreciation Book CZF", TaxDepreciationGroupCZF.Code, true, + FADepreciationBook."Depreciation Method"::"Straight-Line"); + FixedAsset.Validate("Tax Deprec. Group Code CZF", TaxDepreciationGroupCZF.Code); + FixedAsset.Modify(true); + OriginalTaxDepGroupCode := FixedAsset."Tax Deprec. Group Code CZF"; + + // [GIVEN] FA Depreciation Book Tax Deprec. Group Code CZF is blank. + FADepreciationBook."Tax Deprec. Group Code CZF" := ''; // Without validation because validation set the Fixed Asset Tax Deprec. Group Code CZF to blank. + FADepreciationBook.Modify(true); + + // [WHEN] SetFATaxDeprGroup is called. + FixedAsset.SetRange("No.", FixedAsset."No."); + FAGeneralReportCZF.SetFATaxDeprGroup(FixedAsset, FADepreciationBook."Depreciation Book Code"); + + // [THEN] Tax Deprec. Group Code CZF on Fixed Asset remains unchanged. + FixedAsset.Get(FixedAsset."No."); + FixedAsset.TestField("Tax Deprec. Group Code CZF", OriginalTaxDepGroupCode); + end; + + [Test] + procedure SetFATaxDeprGroupUpdatesTaxDepreciationGroupWhenDepreciationBookTaxDepGroupIsDifferentAndNotBlank() + var + FASetup: Record "FA Setup"; + FixedAsset: Record "Fixed Asset"; + FADepreciationBook: Record "FA Depreciation Book"; + TaxDepreciationGroupCZF: Record "Tax Depreciation Group CZF"; + NewTaxDepreciationGroupCZF: Record "Tax Depreciation Group CZF"; + FAGeneralReportCZF: Codeunit "FA General Report CZF"; + NewTaxDepGroupCode: Code[20]; + begin + // [SCENARIO] SetFATaxDeprGroup updates Tax Deprec. Group Code CZF on Fixed Asset + // when FA Depreciation Book has a different non-blank Tax Deprec. Group Code CZF. + + Initialize(); + FASetup.Get(); + + // [GIVEN] Fixed Asset and FA Depreciation Book with initial Tax Deprec. Group Code CZF are created. + CreateFixedAsset(FixedAsset); + CreateTaxDepreciationGroupCZF(TaxDepreciationGroupCZF, TaxDepreciationGroupCZF."Depreciation Type"::"Straight-line"); + CreateFADepreciationBook( + FADepreciationBook, FixedAsset."No.", + FASetup."Tax Depreciation Book CZF", TaxDepreciationGroupCZF.Code, true, + FADepreciationBook."Depreciation Method"::"Straight-Line"); + FixedAsset.Validate("Tax Deprec. Group Code CZF", TaxDepreciationGroupCZF.Code); + FixedAsset.Modify(true); + + // [GIVEN] FA Depreciation Book has another non-blank Tax Deprec. Group Code CZF. + CreateTaxDepreciationGroupCZF(NewTaxDepreciationGroupCZF, NewTaxDepreciationGroupCZF."Depreciation Type"::"Declining-Balance"); + NewTaxDepGroupCode := NewTaxDepreciationGroupCZF.Code; + FADepreciationBook."Tax Deprec. Group Code CZF" := NewTaxDepGroupCode; // Without validation because validation set the Fixed Asset Tax Deprec. Group Code CZF to new value. + FADepreciationBook.Modify(true); + + // [WHEN] SetFATaxDeprGroup is called. + FixedAsset.SetRange("No.", FixedAsset."No."); + FAGeneralReportCZF.SetFATaxDeprGroup(FixedAsset, FADepreciationBook."Depreciation Book Code"); + + // [THEN] Tax Deprec. Group Code CZF on Fixed Asset is updated from FA Depreciation Book. + FixedAsset.Get(FixedAsset."No."); + FixedAsset.TestField("Tax Deprec. Group Code CZF", NewTaxDepGroupCode); + end; + local procedure CreateFixedAsset(var FixedAsset: Record "Fixed Asset") begin LibraryFixedAsset.CreateFixedAsset(FixedAsset); diff --git a/src/Layers/W1/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al b/src/Layers/W1/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al index 9cc73376a69..6778683fb15 100644 --- a/src/Layers/W1/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al +++ b/src/Layers/W1/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al @@ -273,7 +273,7 @@ codeunit 5626 "FA General Report" if FA.Find('-') then repeat if FADeprBook.Get(FA."No.", DeprBookCode) then - if FA."FA Posting Group" <> FADeprBook."FA Posting Group" then begin + if (FA."FA Posting Group" <> FADeprBook."FA Posting Group") and (FADeprBook."FA Posting Group" <> '') then begin FA."FA Posting Group" := FADeprBook."FA Posting Group"; FA.Modify(); end; diff --git a/src/Layers/W1/Tests/Fixed Asset/ERMFixedAssetsReportsII.Codeunit.al b/src/Layers/W1/Tests/Fixed Asset/ERMFixedAssetsReportsII.Codeunit.al index 7f29b80a095..6eab51bcf9e 100644 --- a/src/Layers/W1/Tests/Fixed Asset/ERMFixedAssetsReportsII.Codeunit.al +++ b/src/Layers/W1/Tests/Fixed Asset/ERMFixedAssetsReportsII.Codeunit.al @@ -838,6 +838,70 @@ codeunit 134981 "ERM Fixed Assets Reports - II" VerifyGroupTotalValue(AcquisitionCostTxt, Amount); end; + [Test] + [Scope('OnPrem')] + procedure SetFAPostingGroupDoesNotClearFAPostingGroupWhenDepreciationBookPostingGroupIsBlank() + var + FAGenReport: Codeunit "FA General Report"; + FixedAsset: Record "Fixed Asset"; + FADepreciationBook: Record "FA Depreciation Book"; + FAPostingGroupCode: Code[20]; + begin + // [SCENARIO] SetFAPostingGroup does not clear FA Posting Group on Fixed Asset + // when related FA Depreciation Book has blank FA Posting Group. + + // [GIVEN] Fixed Asset and related FA Depreciation Book exist, and FA Depreciation Book has blank FA Posting Group. + Initialize(); + LibraryFixedAsset.CreateFAWithPostingGroup(FixedAsset); + CreateFADepreciationBook(FADepreciationBook, FixedAsset); + FAPostingGroupCode := FixedAsset."FA Posting Group"; + FADepreciationBook.Validate("FA Posting Group", ''); + FADepreciationBook.Modify(true); + + // [WHEN] SetFAPostingGroup is called. + FixedAsset.SetRange("No.", FixedAsset."No."); + FAGenReport.SetFAPostingGroup(FixedAsset, FADepreciationBook."Depreciation Book Code"); + + // [THEN] FA Posting Group on Fixed Asset remains unchanged. + FixedAsset.Get(FixedAsset."No."); + FixedAsset.TestField("FA Posting Group", FAPostingGroupCode); + end; + + [Test] + [Scope('OnPrem')] + procedure SetFAPostingGroupUpdatesFAPostingGroupWhenDepreciationBookPostingGroupIsDifferentAndNotBlank() + var + FAGenReport: Codeunit "FA General Report"; + FixedAsset: Record "Fixed Asset"; + FADepreciationBook: Record "FA Depreciation Book"; + FAPostingGroup: Record "FA Posting Group"; + NewFAPostingGroupCode: Code[20]; + begin + // [SCENARIO] SetFAPostingGroup updates FA Posting Group on Fixed Asset + // when related FA Depreciation Book has a different non-blank FA Posting Group. + + // [GIVEN] Fixed Asset and related FA Depreciation Book exist, and FA Depreciation Book has a different non-blank FA Posting Group. + Initialize(); + LibraryFixedAsset.CreateFAWithPostingGroup(FixedAsset); + CreateFADepreciationBook(FADepreciationBook, FixedAsset); + LibraryFixedAsset.CreateFAPostingGroup(FAPostingGroup); + NewFAPostingGroupCode := FAPostingGroup.Code; + if NewFAPostingGroupCode = FixedAsset."FA Posting Group" then begin + LibraryFixedAsset.CreateFAPostingGroup(FAPostingGroup); + NewFAPostingGroupCode := FAPostingGroup.Code; + end; + FADepreciationBook.Validate("FA Posting Group", NewFAPostingGroupCode); + FADepreciationBook.Modify(true); + + // [WHEN] SetFAPostingGroup is called. + FixedAsset.SetRange("No.", FixedAsset."No."); + FAGenReport.SetFAPostingGroup(FixedAsset, FADepreciationBook."Depreciation Book Code"); + + // [THEN] FA Posting Group on Fixed Asset is updated from FA Depreciation Book. + FixedAsset.Get(FixedAsset."No."); + FixedAsset.TestField("FA Posting Group", NewFAPostingGroupCode); + end; + [Test] [HandlerFunctions('CalculateDepreciationRequestPageHandler,DepreciationCalcConfirmHandler')] [Scope('OnPrem')] From a1203e136057876d9d05f1326937ea0fc9a3ec7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Holu=C5=A1a?= Date: Thu, 23 Jul 2026 11:28:09 +0200 Subject: [PATCH 2/3] Enhance FA General Report logic and add tests for Tax Deprec. Group and FA Posting Group handling --- .../Codeunits/FAGeneralReportCZF.Codeunit.al | 4 +- .../test/Src/FixedAssetsCZF.Codeunit.al | 82 +++++++++++++++++++ .../FixedAsset/FAGeneralReport.Codeunit.al | 2 +- .../ERMFixedAssetsReportsII.Codeunit.al | 64 +++++++++++++++ 4 files changed, 150 insertions(+), 2 deletions(-) diff --git a/src/Apps/CZ/FixedAssetLocalization/app/Src/Codeunits/FAGeneralReportCZF.Codeunit.al b/src/Apps/CZ/FixedAssetLocalization/app/Src/Codeunits/FAGeneralReportCZF.Codeunit.al index dff65021d57..fbdfa048253 100644 --- a/src/Apps/CZ/FixedAssetLocalization/app/Src/Codeunits/FAGeneralReportCZF.Codeunit.al +++ b/src/Apps/CZ/FixedAssetLocalization/app/Src/Codeunits/FAGeneralReportCZF.Codeunit.al @@ -24,7 +24,9 @@ codeunit 31246 "FA General Report CZF" if FixedAsset.FindSet() then repeat if FADepreciationBook.Get(FixedAsset."No.", DeprBookCode) then - if FixedAsset."Tax Deprec. Group Code CZF" <> FADepreciationBook."Tax Deprec. Group Code CZF" then begin + if (FixedAsset."Tax Deprec. Group Code CZF" <> FADepreciationBook."Tax Deprec. Group Code CZF") and + (FADepreciationBook."Tax Deprec. Group Code CZF" <> '') + then begin FixedAsset."Tax Deprec. Group Code CZF" := FADepreciationBook."Tax Deprec. Group Code CZF"; FixedAsset.Modify(); end; diff --git a/src/Apps/CZ/FixedAssetLocalization/test/Src/FixedAssetsCZF.Codeunit.al b/src/Apps/CZ/FixedAssetLocalization/test/Src/FixedAssetsCZF.Codeunit.al index c92b4193cdf..b6568dc2523 100644 --- a/src/Apps/CZ/FixedAssetLocalization/test/Src/FixedAssetsCZF.Codeunit.al +++ b/src/Apps/CZ/FixedAssetLocalization/test/Src/FixedAssetsCZF.Codeunit.al @@ -280,6 +280,88 @@ codeunit 148087 "Fixed Assets CZF" GLEntry.TestField("G/L Account No.", FAExtendedPostingGroupCZF."Sales Acc. On Disp. (Gain)"); end; + [Test] + procedure SetFATaxDeprGroupDoesNotClearTaxDepreciationGroupWhenDepreciationBookTaxDepGroupIsBlank() + var + FASetup: Record "FA Setup"; + FixedAsset: Record "Fixed Asset"; + FADepreciationBook: Record "FA Depreciation Book"; + TaxDepreciationGroupCZF: Record "Tax Depreciation Group CZF"; + FAGeneralReportCZF: Codeunit "FA General Report CZF"; + OriginalTaxDepGroupCode: Code[20]; + begin + // [SCENARIO] SetFATaxDeprGroup does not clear Tax Deprec. Group Code CZF on Fixed Asset + // when FA Depreciation Book has blank Tax Deprec. Group Code CZF. + + Initialize(); + FASetup.Get(); + + // [GIVEN] Fixed Asset and FA Depreciation Book with Tax Deprec. Group Code CZF are created. + CreateFixedAsset(FixedAsset); + CreateTaxDepreciationGroupCZF(TaxDepreciationGroupCZF, TaxDepreciationGroupCZF."Depreciation Type"::"Straight-line"); + CreateFADepreciationBook( + FADepreciationBook, FixedAsset."No.", + FASetup."Tax Depreciation Book CZF", TaxDepreciationGroupCZF.Code, true, + FADepreciationBook."Depreciation Method"::"Straight-Line"); + FixedAsset.Validate("Tax Deprec. Group Code CZF", TaxDepreciationGroupCZF.Code); + FixedAsset.Modify(true); + OriginalTaxDepGroupCode := FixedAsset."Tax Deprec. Group Code CZF"; + + // [GIVEN] FA Depreciation Book Tax Deprec. Group Code CZF is blank. + FADepreciationBook."Tax Deprec. Group Code CZF" := ''; // Without validation because validation set the Fixed Asset Tax Deprec. Group Code CZF to blank. + FADepreciationBook.Modify(true); + + // [WHEN] SetFATaxDeprGroup is called. + FixedAsset.SetRange("No.", FixedAsset."No."); + FAGeneralReportCZF.SetFATaxDeprGroup(FixedAsset, FADepreciationBook."Depreciation Book Code"); + + // [THEN] Tax Deprec. Group Code CZF on Fixed Asset remains unchanged. + FixedAsset.Get(FixedAsset."No."); + FixedAsset.TestField("Tax Deprec. Group Code CZF", OriginalTaxDepGroupCode); + end; + + [Test] + procedure SetFATaxDeprGroupUpdatesTaxDepreciationGroupWhenDepreciationBookTaxDepGroupIsDifferentAndNotBlank() + var + FASetup: Record "FA Setup"; + FixedAsset: Record "Fixed Asset"; + FADepreciationBook: Record "FA Depreciation Book"; + TaxDepreciationGroupCZF: Record "Tax Depreciation Group CZF"; + NewTaxDepreciationGroupCZF: Record "Tax Depreciation Group CZF"; + FAGeneralReportCZF: Codeunit "FA General Report CZF"; + NewTaxDepGroupCode: Code[20]; + begin + // [SCENARIO] SetFATaxDeprGroup updates Tax Deprec. Group Code CZF on Fixed Asset + // when FA Depreciation Book has a different non-blank Tax Deprec. Group Code CZF. + + Initialize(); + FASetup.Get(); + + // [GIVEN] Fixed Asset and FA Depreciation Book with initial Tax Deprec. Group Code CZF are created. + CreateFixedAsset(FixedAsset); + CreateTaxDepreciationGroupCZF(TaxDepreciationGroupCZF, TaxDepreciationGroupCZF."Depreciation Type"::"Straight-line"); + CreateFADepreciationBook( + FADepreciationBook, FixedAsset."No.", + FASetup."Tax Depreciation Book CZF", TaxDepreciationGroupCZF.Code, true, + FADepreciationBook."Depreciation Method"::"Straight-Line"); + FixedAsset.Validate("Tax Deprec. Group Code CZF", TaxDepreciationGroupCZF.Code); + FixedAsset.Modify(true); + + // [GIVEN] FA Depreciation Book has another non-blank Tax Deprec. Group Code CZF. + CreateTaxDepreciationGroupCZF(NewTaxDepreciationGroupCZF, NewTaxDepreciationGroupCZF."Depreciation Type"::"Declining-Balance"); + NewTaxDepGroupCode := NewTaxDepreciationGroupCZF.Code; + FADepreciationBook."Tax Deprec. Group Code CZF" := NewTaxDepGroupCode; // Without validation because validation set the Fixed Asset Tax Deprec. Group Code CZF to new value. + FADepreciationBook.Modify(true); + + // [WHEN] SetFATaxDeprGroup is called. + FixedAsset.SetRange("No.", FixedAsset."No."); + FAGeneralReportCZF.SetFATaxDeprGroup(FixedAsset, FADepreciationBook."Depreciation Book Code"); + + // [THEN] Tax Deprec. Group Code CZF on Fixed Asset is updated from FA Depreciation Book. + FixedAsset.Get(FixedAsset."No."); + FixedAsset.TestField("Tax Deprec. Group Code CZF", NewTaxDepGroupCode); + end; + local procedure CreateFixedAsset(var FixedAsset: Record "Fixed Asset") begin LibraryFixedAsset.CreateFixedAsset(FixedAsset); diff --git a/src/Layers/W1/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al b/src/Layers/W1/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al index 9cc73376a69..6778683fb15 100644 --- a/src/Layers/W1/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al +++ b/src/Layers/W1/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al @@ -273,7 +273,7 @@ codeunit 5626 "FA General Report" if FA.Find('-') then repeat if FADeprBook.Get(FA."No.", DeprBookCode) then - if FA."FA Posting Group" <> FADeprBook."FA Posting Group" then begin + if (FA."FA Posting Group" <> FADeprBook."FA Posting Group") and (FADeprBook."FA Posting Group" <> '') then begin FA."FA Posting Group" := FADeprBook."FA Posting Group"; FA.Modify(); end; diff --git a/src/Layers/W1/Tests/Fixed Asset/ERMFixedAssetsReportsII.Codeunit.al b/src/Layers/W1/Tests/Fixed Asset/ERMFixedAssetsReportsII.Codeunit.al index 7f29b80a095..6eab51bcf9e 100644 --- a/src/Layers/W1/Tests/Fixed Asset/ERMFixedAssetsReportsII.Codeunit.al +++ b/src/Layers/W1/Tests/Fixed Asset/ERMFixedAssetsReportsII.Codeunit.al @@ -838,6 +838,70 @@ codeunit 134981 "ERM Fixed Assets Reports - II" VerifyGroupTotalValue(AcquisitionCostTxt, Amount); end; + [Test] + [Scope('OnPrem')] + procedure SetFAPostingGroupDoesNotClearFAPostingGroupWhenDepreciationBookPostingGroupIsBlank() + var + FAGenReport: Codeunit "FA General Report"; + FixedAsset: Record "Fixed Asset"; + FADepreciationBook: Record "FA Depreciation Book"; + FAPostingGroupCode: Code[20]; + begin + // [SCENARIO] SetFAPostingGroup does not clear FA Posting Group on Fixed Asset + // when related FA Depreciation Book has blank FA Posting Group. + + // [GIVEN] Fixed Asset and related FA Depreciation Book exist, and FA Depreciation Book has blank FA Posting Group. + Initialize(); + LibraryFixedAsset.CreateFAWithPostingGroup(FixedAsset); + CreateFADepreciationBook(FADepreciationBook, FixedAsset); + FAPostingGroupCode := FixedAsset."FA Posting Group"; + FADepreciationBook.Validate("FA Posting Group", ''); + FADepreciationBook.Modify(true); + + // [WHEN] SetFAPostingGroup is called. + FixedAsset.SetRange("No.", FixedAsset."No."); + FAGenReport.SetFAPostingGroup(FixedAsset, FADepreciationBook."Depreciation Book Code"); + + // [THEN] FA Posting Group on Fixed Asset remains unchanged. + FixedAsset.Get(FixedAsset."No."); + FixedAsset.TestField("FA Posting Group", FAPostingGroupCode); + end; + + [Test] + [Scope('OnPrem')] + procedure SetFAPostingGroupUpdatesFAPostingGroupWhenDepreciationBookPostingGroupIsDifferentAndNotBlank() + var + FAGenReport: Codeunit "FA General Report"; + FixedAsset: Record "Fixed Asset"; + FADepreciationBook: Record "FA Depreciation Book"; + FAPostingGroup: Record "FA Posting Group"; + NewFAPostingGroupCode: Code[20]; + begin + // [SCENARIO] SetFAPostingGroup updates FA Posting Group on Fixed Asset + // when related FA Depreciation Book has a different non-blank FA Posting Group. + + // [GIVEN] Fixed Asset and related FA Depreciation Book exist, and FA Depreciation Book has a different non-blank FA Posting Group. + Initialize(); + LibraryFixedAsset.CreateFAWithPostingGroup(FixedAsset); + CreateFADepreciationBook(FADepreciationBook, FixedAsset); + LibraryFixedAsset.CreateFAPostingGroup(FAPostingGroup); + NewFAPostingGroupCode := FAPostingGroup.Code; + if NewFAPostingGroupCode = FixedAsset."FA Posting Group" then begin + LibraryFixedAsset.CreateFAPostingGroup(FAPostingGroup); + NewFAPostingGroupCode := FAPostingGroup.Code; + end; + FADepreciationBook.Validate("FA Posting Group", NewFAPostingGroupCode); + FADepreciationBook.Modify(true); + + // [WHEN] SetFAPostingGroup is called. + FixedAsset.SetRange("No.", FixedAsset."No."); + FAGenReport.SetFAPostingGroup(FixedAsset, FADepreciationBook."Depreciation Book Code"); + + // [THEN] FA Posting Group on Fixed Asset is updated from FA Depreciation Book. + FixedAsset.Get(FixedAsset."No."); + FixedAsset.TestField("FA Posting Group", NewFAPostingGroupCode); + end; + [Test] [HandlerFunctions('CalculateDepreciationRequestPageHandler,DepreciationCalcConfirmHandler')] [Scope('OnPrem')] From 147a592b55183f14fcc696a68674f43cd962998c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Holu=C5=A1a?= Date: Thu, 23 Jul 2026 12:12:34 +0200 Subject: [PATCH 3/3] invoke miapp --- .../ERMFixedAssetsReportsII.Codeunit.al | 64 +++++++++++++++++++ .../FixedAsset/FAGeneralReport.Codeunit.al | 2 +- .../FixedAsset/FAGeneralReport.Codeunit.al | 2 +- .../FixedAsset/FAGeneralReport.Codeunit.al | 2 +- .../ERMFixedAssetsReportsII.Codeunit.al | 64 +++++++++++++++++++ 5 files changed, 131 insertions(+), 3 deletions(-) diff --git a/src/Layers/CZ/Tests/Fixed Asset/ERMFixedAssetsReportsII.Codeunit.al b/src/Layers/CZ/Tests/Fixed Asset/ERMFixedAssetsReportsII.Codeunit.al index a7ea960850c..b6be153c364 100644 --- a/src/Layers/CZ/Tests/Fixed Asset/ERMFixedAssetsReportsII.Codeunit.al +++ b/src/Layers/CZ/Tests/Fixed Asset/ERMFixedAssetsReportsII.Codeunit.al @@ -846,6 +846,70 @@ codeunit 134981 "ERM Fixed Assets Reports - II" VerifyGroupTotalValue(AcquisitionCostTxt, Amount); end; + [Test] + [Scope('OnPrem')] + procedure SetFAPostingGroupDoesNotClearFAPostingGroupWhenDepreciationBookPostingGroupIsBlank() + var + FAGenReport: Codeunit "FA General Report"; + FixedAsset: Record "Fixed Asset"; + FADepreciationBook: Record "FA Depreciation Book"; + FAPostingGroupCode: Code[20]; + begin + // [SCENARIO] SetFAPostingGroup does not clear FA Posting Group on Fixed Asset + // when related FA Depreciation Book has blank FA Posting Group. + + // [GIVEN] Fixed Asset and related FA Depreciation Book exist, and FA Depreciation Book has blank FA Posting Group. + Initialize(); + LibraryFixedAsset.CreateFAWithPostingGroup(FixedAsset); + CreateFADepreciationBook(FADepreciationBook, FixedAsset); + FAPostingGroupCode := FixedAsset."FA Posting Group"; + FADepreciationBook.Validate("FA Posting Group", ''); + FADepreciationBook.Modify(true); + + // [WHEN] SetFAPostingGroup is called. + FixedAsset.SetRange("No.", FixedAsset."No."); + FAGenReport.SetFAPostingGroup(FixedAsset, FADepreciationBook."Depreciation Book Code"); + + // [THEN] FA Posting Group on Fixed Asset remains unchanged. + FixedAsset.Get(FixedAsset."No."); + FixedAsset.TestField("FA Posting Group", FAPostingGroupCode); + end; + + [Test] + [Scope('OnPrem')] + procedure SetFAPostingGroupUpdatesFAPostingGroupWhenDepreciationBookPostingGroupIsDifferentAndNotBlank() + var + FAGenReport: Codeunit "FA General Report"; + FixedAsset: Record "Fixed Asset"; + FADepreciationBook: Record "FA Depreciation Book"; + FAPostingGroup: Record "FA Posting Group"; + NewFAPostingGroupCode: Code[20]; + begin + // [SCENARIO] SetFAPostingGroup updates FA Posting Group on Fixed Asset + // when related FA Depreciation Book has a different non-blank FA Posting Group. + + // [GIVEN] Fixed Asset and related FA Depreciation Book exist, and FA Depreciation Book has a different non-blank FA Posting Group. + Initialize(); + LibraryFixedAsset.CreateFAWithPostingGroup(FixedAsset); + CreateFADepreciationBook(FADepreciationBook, FixedAsset); + LibraryFixedAsset.CreateFAPostingGroup(FAPostingGroup); + NewFAPostingGroupCode := FAPostingGroup.Code; + if NewFAPostingGroupCode = FixedAsset."FA Posting Group" then begin + LibraryFixedAsset.CreateFAPostingGroup(FAPostingGroup); + NewFAPostingGroupCode := FAPostingGroup.Code; + end; + FADepreciationBook.Validate("FA Posting Group", NewFAPostingGroupCode); + FADepreciationBook.Modify(true); + + // [WHEN] SetFAPostingGroup is called. + FixedAsset.SetRange("No.", FixedAsset."No."); + FAGenReport.SetFAPostingGroup(FixedAsset, FADepreciationBook."Depreciation Book Code"); + + // [THEN] FA Posting Group on Fixed Asset is updated from FA Depreciation Book. + FixedAsset.Get(FixedAsset."No."); + FixedAsset.TestField("FA Posting Group", NewFAPostingGroupCode); + end; + [Test] [HandlerFunctions('CalculateDepreciationRequestPageHandler,DepreciationCalcConfirmHandler')] [Scope('OnPrem')] diff --git a/src/Layers/DACH/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al b/src/Layers/DACH/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al index a35fbc82fd4..818d820a32e 100644 --- a/src/Layers/DACH/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al +++ b/src/Layers/DACH/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al @@ -277,7 +277,7 @@ codeunit 5626 "FA General Report" if FA.Find('-') then repeat if FADeprBook.Get(FA."No.", DeprBookCode) then - if FA."FA Posting Group" <> FADeprBook."FA Posting Group" then begin + if (FA."FA Posting Group" <> FADeprBook."FA Posting Group") and (FADeprBook."FA Posting Group" <> '') then begin FA."FA Posting Group" := FADeprBook."FA Posting Group"; FA.Modify(); end; diff --git a/src/Layers/FR/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al b/src/Layers/FR/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al index 06073f711f4..a87887b1da6 100644 --- a/src/Layers/FR/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al +++ b/src/Layers/FR/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al @@ -307,7 +307,7 @@ codeunit 5626 "FA General Report" if FA.Find('-') then repeat if FADeprBook.Get(FA."No.", DeprBookCode) then - if FA."FA Posting Group" <> FADeprBook."FA Posting Group" then begin + if (FA."FA Posting Group" <> FADeprBook."FA Posting Group") and (FADeprBook."FA Posting Group" <> '') then begin FA."FA Posting Group" := FADeprBook."FA Posting Group"; FA.Modify(); end; diff --git a/src/Layers/IT/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al b/src/Layers/IT/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al index 4e4b869d680..03979b87e95 100644 --- a/src/Layers/IT/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al +++ b/src/Layers/IT/BaseApp/FixedAssets/FixedAsset/FAGeneralReport.Codeunit.al @@ -273,7 +273,7 @@ codeunit 5626 "FA General Report" if FA.Find('-') then repeat if FADeprBook.Get(FA."No.", DeprBookCode) then - if FA."FA Posting Group" <> FADeprBook."FA Posting Group" then begin + if (FA."FA Posting Group" <> FADeprBook."FA Posting Group") and (FADeprBook."FA Posting Group" <> '') then begin FA."FA Posting Group" := FADeprBook."FA Posting Group"; FA.Modify(); end; diff --git a/src/Layers/RU/Tests/Fixed Asset/ERMFixedAssetsReportsII.Codeunit.al b/src/Layers/RU/Tests/Fixed Asset/ERMFixedAssetsReportsII.Codeunit.al index 1179355c8b0..70e2e12670d 100644 --- a/src/Layers/RU/Tests/Fixed Asset/ERMFixedAssetsReportsII.Codeunit.al +++ b/src/Layers/RU/Tests/Fixed Asset/ERMFixedAssetsReportsII.Codeunit.al @@ -836,6 +836,70 @@ codeunit 134981 "ERM Fixed Assets Reports - II" VerifyGroupTotalValue(AcquisitionCostTxt, Amount); end; + [Test] + [Scope('OnPrem')] + procedure SetFAPostingGroupDoesNotClearFAPostingGroupWhenDepreciationBookPostingGroupIsBlank() + var + FAGenReport: Codeunit "FA General Report"; + FixedAsset: Record "Fixed Asset"; + FADepreciationBook: Record "FA Depreciation Book"; + FAPostingGroupCode: Code[20]; + begin + // [SCENARIO] SetFAPostingGroup does not clear FA Posting Group on Fixed Asset + // when related FA Depreciation Book has blank FA Posting Group. + + // [GIVEN] Fixed Asset and related FA Depreciation Book exist, and FA Depreciation Book has blank FA Posting Group. + Initialize(); + LibraryFixedAsset.CreateFAWithPostingGroup(FixedAsset); + CreateFADepreciationBook(FADepreciationBook, FixedAsset); + FAPostingGroupCode := FixedAsset."FA Posting Group"; + FADepreciationBook.Validate("FA Posting Group", ''); + FADepreciationBook.Modify(true); + + // [WHEN] SetFAPostingGroup is called. + FixedAsset.SetRange("No.", FixedAsset."No."); + FAGenReport.SetFAPostingGroup(FixedAsset, FADepreciationBook."Depreciation Book Code"); + + // [THEN] FA Posting Group on Fixed Asset remains unchanged. + FixedAsset.Get(FixedAsset."No."); + FixedAsset.TestField("FA Posting Group", FAPostingGroupCode); + end; + + [Test] + [Scope('OnPrem')] + procedure SetFAPostingGroupUpdatesFAPostingGroupWhenDepreciationBookPostingGroupIsDifferentAndNotBlank() + var + FAGenReport: Codeunit "FA General Report"; + FixedAsset: Record "Fixed Asset"; + FADepreciationBook: Record "FA Depreciation Book"; + FAPostingGroup: Record "FA Posting Group"; + NewFAPostingGroupCode: Code[20]; + begin + // [SCENARIO] SetFAPostingGroup updates FA Posting Group on Fixed Asset + // when related FA Depreciation Book has a different non-blank FA Posting Group. + + // [GIVEN] Fixed Asset and related FA Depreciation Book exist, and FA Depreciation Book has a different non-blank FA Posting Group. + Initialize(); + LibraryFixedAsset.CreateFAWithPostingGroup(FixedAsset); + CreateFADepreciationBook(FADepreciationBook, FixedAsset); + LibraryFixedAsset.CreateFAPostingGroup(FAPostingGroup); + NewFAPostingGroupCode := FAPostingGroup.Code; + if NewFAPostingGroupCode = FixedAsset."FA Posting Group" then begin + LibraryFixedAsset.CreateFAPostingGroup(FAPostingGroup); + NewFAPostingGroupCode := FAPostingGroup.Code; + end; + FADepreciationBook.Validate("FA Posting Group", NewFAPostingGroupCode); + FADepreciationBook.Modify(true); + + // [WHEN] SetFAPostingGroup is called. + FixedAsset.SetRange("No.", FixedAsset."No."); + FAGenReport.SetFAPostingGroup(FixedAsset, FADepreciationBook."Depreciation Book Code"); + + // [THEN] FA Posting Group on Fixed Asset is updated from FA Depreciation Book. + FixedAsset.Get(FixedAsset."No."); + FixedAsset.TestField("FA Posting Group", NewFAPostingGroupCode); + end; + [Test] [HandlerFunctions('CalculateDepreciationRequestPageHandler,MessageHandler')] [Scope('OnPrem')]