Stock Variance Posting : Pseudo Code
Pseudocode for Finland Stock Variation postings Custom GL Plugin:
Check if SuiteApp License is valid. If not, exit.
If Transaction Type is ITEM RECEIPT:
if Created From is PURCHASE ORDER:
Run an item search and store asset accounts of items with type assembly, inventory, kit, and item group.
Run an account search and get the Stock Value Variation Account (custrecord_stock_variation_account) for each account.
Get Default Account For Stock Variation Postings (account) by searching for account where Default Account For Stock Variation Postings (custrecord_sta_stockvaluevariation_acct) is TRUE
Get Entity’s Purchases Within Fiscal Year Account (account) by getting the value of Purchases Within Fiscal Year Account from the Entity’s record.
Get Default Account For Purchases Within Fiscal Year (account) by searching for account where Default Account For Purchases Within Fiscal Year (custrecord_default_expenses_within_fy) is TRUE
For each GL line:
Get Debit Amount
Get Account.
Get Line Memo
If Debit Amount > 0 and Account is an asset account and Line Memo is 'Cost of Sales Adjustment'.
Get Class, Department, and Location.
If the Stock Value Variation Account is set for the Account, use this as Stock Variation Account for GL line to be added
Else if the Stock Value Variation Account is not set for the Account, use the Default Account For Stock Variation Postings as Stock Variation Account for GL line to be added.
If Purchases Within Fiscal Year Account is set for the Entity:
Use this as expense account for GL line to be added
Use “Purchases from vendor in accounting period.“ as Debit Memo.
Else
Use Default Account For Purchases Within Fiscal Year as expense account for GL line to be added
Use “Ostot tilikauden aikana.“ as Debit Memo.
Add new custom debit GL line
Set Debit Amount
Set expense account from above
Set Debit Memo from above
Set Class, Department, Location from above
Add new custom credit GL line
Set Credit Amount
Set Account as Stock Variation Account from above
Set Class, Department, Location from above
Set Memo as “Varaston muutos.“
If Transaction Type is VENDOR BILL:
For each line in the item sublist:
Run an item search and store asset accounts of items with type assembly, inventory, kit, and item group.
Run an account search and get the Stock Value Variation Account (custrecord_stock_variation_account) for each account.
Get Default Account For Stock Variation Postings (account) by searching for account where Default Account For Stock Variation Postings (custrecord_sta_stockvaluevariation_acct) is TRUE
Get Entity’s Purchases Within Fiscal Year Account (account) by getting the value of Purchases Within Fiscal Year Account from the Entity’s record.
Get Default Account For Purchases Within Fiscal Year (account) by searching for account where Default Account For Purchases Within Fiscal Year (custrecord_default_expenses_within_fy) is TRUE
For each GL line:
Get Debit Amount
Get Account.
If Debit Amount > 0 and Account is an asset account:
Get Class, Department, and Location
If the Stock Value Variation Account is set for the Account, use this as Stock Variation Account for GL line to be added.
Else if the Stock Value Variation Account is not set for the Account, use the Default Account For Stock Variation Postings as Stock Variation Account for GL line to be added.
If Purchases Within Fiscal Year Account is set for the Entity:
Use this as expense account for GL line to be added
Use “Purchases from vendor in accounting period.“ as Debit Memo.
Else
Use Default Account For Purchases Within Fiscal Year as expense account for GL line to be added
Use “Ostot tilikauden aikana.“ as Debit Memo.
Add new custom debit GL line
Set Debit Amount
Set expense account from above
Set Debit Memo from above
Set Department, Location from above
Add new custom credit GL line
Set Credit Amount
Set Account as Stock Variation Account from above
Set Memo as “Varaston muutos.“
Set Class, Department, Location from above
If Transaction Type is ITEM FULFILLMENT:
If Created From Type is VENDOR RETURN AUTHORIZATION:
Run an account search and get the Stock Value Variation Account (custrecord_stock_variation_account) for each account.
Get Default Account For Stock Variation Postings (account) by searching for account where Default Account For Stock Variation Postings (custrecord_sta_stockvaluevariation_acct) is TRUE
Get Entity’s Purchases Within Fiscal Year Account (account) by getting the value of Purchases Within Fiscal Year Account from the Entity’s record.
Get Default Account For Purchases Within Fiscal Year (account) by searching for account where Default Account For Purchases Within Fiscal Year (custrecord_default_expenses_within_fy) is TRUE
For each GL line:
Get Credit Amount
Get Debit Amount
Get Line Memo
If Credit Amount > 0 and Line Memo is “Cost of Sales Adjustment“:
Get Class, Department, Location
Get Account
f the Stock Value Variation Account is set for the Account, use this as Stock Variation Account for GL line to be added.
Else if the Stock Value Variation Account is not set for the Account, use the Default Account For Stock Variation Postings as Stock Variation Account for GL line to be added.
If Purchases Within Fiscal Year Account is set for the Entity:
Use this as expense account for GL line to be added
Use “Purchases from vendor in accounting period.“ as Debit Memo.
Else
Use Default Account For Purchases Within Fiscal Year as expense account for GL line to be added
Use “Ostot tilikauden aikana.“ as Debit Memo.
Add new custom debit GL line
Set Debit Amount
Set Account as Stock Variation Account from above
Set Debit Memo from above
Set Class, Department, Location from above
Add new custom credit GL line
Set Credit Amount
Set Account as expense account from above
Set Memo as “Varaston muutos.“
Set Class, Department, Location from above
If Transaction Type is WORK ORDER ISSUE;
For each GL line:
Get Credit Amount
If Credit Amount > 0:
Get Class, Department, Location
Get Account
Get Default Account For Stock Variation Postings (account) by searching for account where Default Account For Stock Variation Postings (custrecord_sta_stockvaluevariation_acct) is TRUE
Get Default Account For WIP VARIANCE (account) by searching for account where Default Account For WIP Variance (custrecord_default_wip_variance_account) is TRUE
f the Stock Value Variation Account is set for the Account, use this as Stock Variation Account for GL line to be added.
Else if the Stock Value Variation Account is not set for the Account, use the Default Account For Stock Variation Postings as Stock Variation Account for GL line to be added.
Add new custom debit GL line
Set Debit Amount
Set Account as Stock Variation Account from above
Set Debit Memo as “Stock variation of raw materials.“
Set Class, Department, Location from above
Add new custom credit GL line
Set Credit Amount
Set Account as Default Account For WIP VARIANCE
Set Memo as “WIP Stock variation.“
Set Class, Department, Location from above
If Transaction Type is WORK ORDER COMPLETION:
Run an item search and store asset accounts of items with type assembly, inventory, kit, and item group.
For each GL line:
Get Debit Amount
Get Account
If Debit Amount > 0 and Account is an asset account
Get Class, Department, Location
Get Default Account For Stock Variation Postings (account) by searching for account where Default Account For Stock Variation Postings (custrecord_sta_stockvaluevariation_acct) is TRUE
Get Default Account For WIP VARIANCE (account) by searching for account where Default Account For WIP Variance (custrecord_default_wip_variance_account) is TRUE
f the Stock Value Variation Account is set for the Account, use this as Stock Variation Account for GL line to be added.
Else if the Stock Value Variation Account is not set for the Account, use the Default Account For Stock Variation Postings as Stock Variation Account for GL line to be added.
Add new custom debit GL line
Set Debit Amount
Set Account as Default Account For WIP VARIANCE
Set Debit Memo as “Stock variation of WIP .“
Set Class, Department, Location from above
Add new custom credit GL line
Set Credit Amount
Set Account as Stock Variation Account from above
Set Memo as “Stock variation of finished goods“
Set Class, Department, Location from above