ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[BugFix] Codeunit 5600 - FA Insert Ledger Entry - SetFAPostingType skips OnAfterSetFAPostingType on "FA Posting Category" not empty

Open Codey42 opened this issue 4 years ago • 1 comments

Dear ALAppExtensions team,

Through this issue we would like to request fixing the "exit" condition "FA Posting Category" <> "FA Posting Category"::" " in method SetFAPostingType in Codeunit 5600 FA Insert Ledger Entry. Reason is that the event OnAfterSetFAPostingType is not called if this condition evaluates to true.

Current code (with annotation):

local procedure SetFAPostingType(var FALedgEntry: Record "FA Ledger Entry")
begin
    with FALedgEntry do begin
        UpdateDebitCredit(FALedgEntry);
        "Part of Book Value" := false;
        "Part of Depreciable Basis" := false;
        // >>>> Start >>>>>>>>>>>>>>>>
        // -> If this condition evaluates to true, "OnAfterSetFAPostingType" is not called.
        if "FA Posting Category" <> "FA Posting Category"::" " then
            exit;
        // <<<< End <<<<<<<<<<<<<<<<
        case "FA Posting Type" of
            "FA Posting Type"::"Write-Down":
                FAPostingTypeSetup.Get(
                    DeprBookCode, FAPostingTypeSetup."FA Posting Type"::"Write-Down");
            "FA Posting Type"::Appreciation:
                FAPostingTypeSetup.Get(
                    DeprBookCode, FAPostingTypeSetup."FA Posting Type"::Appreciation);
            "FA Posting Type"::"Custom 1":
                FAPostingTypeSetup.Get(
                    DeprBookCode, FAPostingTypeSetup."FA Posting Type"::"Custom 1");
            "FA Posting Type"::"Custom 2":
                FAPostingTypeSetup.Get(
                    DeprBookCode, FAPostingTypeSetup."FA Posting Type"::"Custom 2");
        end;
        case "FA Posting Type" of
            "FA Posting Type"::"Acquisition Cost",
            "FA Posting Type"::"Salvage Value":
                "Part of Depreciable Basis" := true;
            "FA Posting Type"::"Write-Down",
            "FA Posting Type"::Appreciation,
            "FA Posting Type"::"Custom 1",
            "FA Posting Type"::"Custom 2":
                "Part of Depreciable Basis" := FAPostingTypeSetup."Part of Depreciable Basis";
        end;
        case "FA Posting Type" of
            "FA Posting Type"::"Acquisition Cost",
            "FA Posting Type"::Depreciation:
                "Part of Book Value" := true;
            "FA Posting Type"::"Write-Down",
            "FA Posting Type"::Appreciation,
            "FA Posting Type"::"Custom 1",
            "FA Posting Type"::"Custom 2":
                "Part of Book Value" := FAPostingTypeSetup."Part of Book Value";
        end;
    end;

    OnAfterSetFAPostingType(FALedgEntry, FAPostingTypeSetup);
end;

Fixed code (with annotation):

local procedure SetFAPostingType(var FALedgEntry: Record "FA Ledger Entry")
begin
    with FALedgEntry do begin
        UpdateDebitCredit(FALedgEntry);
        "Part of Book Value" := false;
        "Part of Depreciable Basis" := false;
        // >>>> Start >>>>>>>>>>>>>>>>
        // -> Inverted condition so that "OnAfterSetFAPostingType" is always called.
        // -> Indentation increased for readability.
        if "FA Posting Category" = "FA Posting Category"::" " then begin
        // <<<< End <<<<<<<<<<<<<<<<
            case "FA Posting Type" of
                "FA Posting Type"::"Write-Down":
                    FAPostingTypeSetup.Get(
                        DeprBookCode, FAPostingTypeSetup."FA Posting Type"::"Write-Down");
                "FA Posting Type"::Appreciation:
                    FAPostingTypeSetup.Get(
                        DeprBookCode, FAPostingTypeSetup."FA Posting Type"::Appreciation);
                "FA Posting Type"::"Custom 1":
                    FAPostingTypeSetup.Get(
                        DeprBookCode, FAPostingTypeSetup."FA Posting Type"::"Custom 1");
                "FA Posting Type"::"Custom 2":
                    FAPostingTypeSetup.Get(
                        DeprBookCode, FAPostingTypeSetup."FA Posting Type"::"Custom 2");
            end;
            case "FA Posting Type" of
                "FA Posting Type"::"Acquisition Cost",
                "FA Posting Type"::"Salvage Value":
                    "Part of Depreciable Basis" := true;
                "FA Posting Type"::"Write-Down",
                "FA Posting Type"::Appreciation,
                "FA Posting Type"::"Custom 1",
                "FA Posting Type"::"Custom 2":
                    "Part of Depreciable Basis" := FAPostingTypeSetup."Part of Depreciable Basis";
            end;
            case "FA Posting Type" of
                "FA Posting Type"::"Acquisition Cost",
                "FA Posting Type"::Depreciation:
                    "Part of Book Value" := true;
                "FA Posting Type"::"Write-Down",
                "FA Posting Type"::Appreciation,
                "FA Posting Type"::"Custom 1",
                "FA Posting Type"::"Custom 2":
                    "Part of Book Value" := FAPostingTypeSetup."Part of Book Value";
            end;
        // >>>> Start >>>>>>>>>>>>>>>>
        end;
        // <<<< End <<<<<<<<<<<<<<<<
    end;

    OnAfterSetFAPostingType(FALedgEntry, FAPostingTypeSetup);
end;

Codey42 avatar Mar 29 '22 12:03 Codey42

Thanks for reporting this. We agree, and we’ll publish a fix asap, either in an update for the current version or in the next major release. Please do not reply to this, as we do not monitor closed issues. If you have follow-up questions or requests, please create a new issue where you reference this one.

JesperSchulz avatar Apr 21 '22 05:04 JesperSchulz