Assets: multiple depreciation rates with identical posting profile

Issue:
  • Changing legislation leads to many different depreciation rates depending on the time an asset was acquired.
  • Dynamics Ax requires one value model per depreciation rate, i.e. we need around 30 value models.
  • Each value model requires a specific posting profile. Each posting profile has at least 14 entries. Leading to over 400(!) entries.
  • Every new Asset requires the setting up of a new posting profile (if the depreciation rate is again different).

Solution:

  • Allow the system to fall back to a default posting profile attached to the value model "Std".
  • Make the modification that still allow multiple posting profiles if needed, i.e. first try to use standard functionality, only if failed fall back to a default posting profile.
  • The following methods must be modified:
    • Table AssetLedgerAccounts
      • find
      • findAssetLedgerAccount
      • findAssetLedgerOffsetAccount
      • assetLedgerAccount
      • assetLedgerOffsetAccount
      • exist
    • Class AssetReclassification
      • findNewAssetLedgerAccount
      • findOldAssetLedgerAccount
    • Table AssetDisposalParameters
      • find
      • findPosintingAccound
      • exist
    • Class AssetPostDisposal
      • post
  • The modifications all follow the same pattern: Find the query(ies) in the method and repeat them with BookId == "Std".
    General pseudo code structure:
    found = select1 where BookId == _bookid;
    if (!found)
        found  = select2 where BookId == _bookid;
    //new:
    if (!found)
        found  = select1 where BookId ==  "Std";
    if (!found)
        res = select2 where BookId ==  "Std;

public static boolean exist( //table AssetLedgerAccounts
    AssetBookId         _bookId,
    AssetPostingProfile _postingProfile,
    AssetTransType      _transType,
    AssetTableGroupAll  _accountCode,
    AccountNum          _accountRelation)
{
    boolean found;
    ;

    found = (select firstonly
                RecId
             from
                assetLedgerAccounts
             where
                assetLedgerAccounts.BookId == _bookId &&
                assetLedgerAccounts.PostingProfile == _postingProfile &&
                assetLedgerAccounts.TransType == _transType &&
                assetLedgerAccounts.AccountCode == _accountCode &&
                assetLedgerAccounts.AccountRelation == _accountRelation).RecId != 0;

//bw start
//Changed on 21 May 2007 by TW
/* Description:
Default to the Value Model "Std" if no specific BookId found.
*/

    if (!found)
    {
        found = (select firstonly
                RecId
             from
                assetLedgerAccounts
             where
                assetLedgerAccounts.BookId == "Std" &&
                assetLedgerAccounts.PostingProfile == _postingProfile &&
                assetLedgerAccounts.TransType == _transType &&
                assetLedgerAccounts.AccountCode == _accountCode &&
                assetLedgerAccounts.AccountRelation == _accountRelation).RecId != 0;
    }
//bw end

    return found;
}

  • AssetPostDisposal is the only exception to this simple pattern. As there is a while select loop, the situation needs to be handled slightly different

void post() //class AssetPostDisposal
{
    AssetAmount                 assetAmount;
    AssetDisposalParameters     assetDisposalParameters;
    AssetDisposalParameters     l_assetDisposalParameters;
    AssetPostType               assetPostType;
    AssetSoldScrap              soldScrap;
    CurrencyCode                companyCurrency = CompanyInfo::standardCurrency();
    LedgerVoucherTransObject    ledgerVoucherTransObject;
    boolean                     useStd = false; //bw
    ;

    ttsbegin;

    […]

    select assetDisposalParameters
          where assetDisposalParameters.PostValue       == AssetPostValue::NBV  &&
                assetDisposalParameters.SoldScrap       == soldScrap            &&
                assetDisposalParameters.PostingProfile  == assetTrans.PostingProfile   &&
                assetDisposalParameters.BookId          == assetTrans.BookId    &&
                (assetDisposalParameters.ValueType      == assetPostType ||
                 assetDisposalParameters.ValueType      == AssetPostType::All)  &&
                ((assetDisposalParameters.AssetCode     == TableGroupAll::Table   &&
                  assetDisposalParameters.AssetRelation == assetTrans.AssetId) ||
                 (assetDisposalParameters.AssetCode     == TableGroupAll::GroupId &&
                  assetDisposalParameters.AssetRelation == AssetTable::find(assetTrans.AssetId).AssetGroup) ||
                  assetDisposalParameters.AssetCode     == TableGroupAll::All);
//bw start
//Changed on 21 May 2007 by TW
/* Description:
Default to the Value Model "Std" if no specific BookId found.
*/
    if (!assetDisposalParameters)
    {
        useStd = true;
        select assetDisposalParameters
          where assetDisposalParameters.PostValue       == AssetPostValue::NBV  &&
                assetDisposalParameters.SoldScrap       == soldScrap            &&
                assetDisposalParameters.PostingProfile  == assetTrans.PostingProfile   &&
                assetDisposalParameters.BookId          == "Std"    &&
                (assetDisposalParameters.ValueType      == assetPostType ||
                 assetDisposalParameters.ValueType      == AssetPostType::All)  &&
                ((assetDisposalParameters.AssetCode     == TableGroupAll::Table   &&
                  assetDisposalParameters.AssetRelation == assetTrans.AssetId) ||
                 (assetDisposalParameters.AssetCode     == TableGroupAll::GroupId &&
                  assetDisposalParameters.AssetRelation == AssetTable::find(assetTrans.AssetId).AssetGroup) ||
                  assetDisposalParameters.AssetCode     == TableGroupAll::All);
    }
//bw end
    if (!assetDisposalParameters.RecId)
    {
            throw error(strfmt("@SYS24602","@SYS67345" + ‘/’ + "@SYS67538", "@SYS67500"));
    }

    while select assetDisposalParameters
        group by PostValue
        where assetDisposalParameters.SoldScrap       == soldScrap                    &&
              assetDisposalParameters.PostingProfile  == assetTrans.PostingProfile    &&
//bw start
//Changed on 21 May 2007 by TW
/* Description:
if mod was needed above use Std else use BookId
*/
              assetDisposalParameters.BookId          == (useStd?"Std":assetTrans.BookId)            &&
//bw end
              (assetDisposalParameters.ValueType      == assetPostType                ||
               assetDisposalParameters.ValueType      == AssetPostType::All)
    {
        l_assetDisposalParameters = AssetDisposalParameters::findPostingAccount(assetTrans.AssetId,
                                                                                assetDisposalParameters.SoldScrap,
                                                                                assetDisposalParameters.PostingProfile,
                                                                                assetDisposalParameters.BookId,
                                                                                assetDisposalParameters.ValueType,
                                                                                assetDisposalParameters.PostValue);

        assetAmount = this.postValue(l_assetDisposalParameters.PostValue);
        if (assetAmount)
        {
            ledgerVoucherTransObject = LedgerVoucherTransObject::newCreateTrans(
                                                                    ledgerVoucher.findLedgerVoucherObject(),
                                                                    LedgerPostingType::FixedAssetsDebit,
                                                                    l_assetDisposalParameters.Account,
                                                                    assetTrans.Dimension,
                                                                    companyCurrency, //assetTrans.currencyCode,
                                                                    -assetAmount,
                                                                    assetTrans.TableId,
                                                                    assetTrans.RecId,
                                                                    0);
            ledgerVoucherTransObject.parmOperationsTax(LedgerVoucher::operationsTax(AssetBookTable::find(assetTrans.BookId).CurrentOperationsTax));
            ledgerVoucherTransObject.parmTransTxt(assetTrans.Txt);
            ledgerVoucher.addTrans(ledgerVoucherTransObject);

            ledgerVoucherTransObject = LedgerVoucherTransObject::newCreateTrans(
                                                                    ledgerVoucher.findLedgerVoucherObject(),
                                                                    LedgerPostingType::FixedAssetsDebit,
                                                                    l_assetDisposalParameters.OffsetAccount,
                                                                    assetTrans.Dimension,
                                                                    companyCurrency, //assetTrans.currencyCode,
                                                                    assetAmount,
                                                                    assetTrans.TableId,
                                                                    assetTrans.RecId,
                                                                    0);
            ledgerVoucherTransObject.parmOperationsTax(LedgerVoucher::operationsTax(AssetBookTable::find(assetTrans.BookId).CurrentOperationsTax));
            ledgerVoucherTransObject.parmTransTxt(assetTrans.Txt);
            ledgerVoucher.addTrans(ledgerVoucherTransObject);
        }
    }
    ttscommit;
}

Advertisements