Cost Engine/Case I

From ADempiere
Jump to: navigation, search
This Wiki is read-only for reference purposes to avoid broken links.
Note.gif Note:

This Single Organisation Use Case is based on Libero's Cost Engine/Testing and its JUnit on AverageInvoiceCostTest. See next case.

Fig.1 - Transaction Value Report automatically generated at the end of the test case, stored in your PC temp folder.

Testing Goals

  1. Test Generate Cost Transaction to produce Cost Details from past transaction records.
  2. Test Purchases, Material Receipts, Credit Sales (with Shipments), Reversal of Receipts, View Sales Shipments, Movements, Physical Inventory and Internal Use.
  3. Test Transactions under Average Invoice for Material Cost Element.
  4. Test generating of Transaction Valuation Report and Inventory Valuation Report saved in PDF format.
  5. Test comparison with Standard Cost on same Test Data as control. (TODO).

Setting Up

  • Using ExpDat.dmp from LiberoCE.jar which is a fresh 360LTS DB upgraded from Libero Cost Engine code and DB changes.
  • Then run the Fitnesse Costing Engine suite:
    • Standard Cost is deactivated and Transaction Update is executed on Oak item.
    • Transactions carried out according to CostEngineTestStory shown below.
    • A Transaction Valuation Report and a InventoryValuation Report are produced.
  • You can download the ExpDat.dmp, Libero jars, and Fitnesse suite at the Download section.
  • All source and documentation are committed under SVN/branches/FitnesseSlim
Fig.2 - Test Run completed in success. Expand the folders or scroll down to see details.

Testing Tool

  • FitnesseSlim framework is used to take input parameters or data for testing the Cost Engine.
  • As each Testing Step row below is executed, the respective Cost Detail output is asserted green when repeated as true.
  • This can then be repeated after every change of code or function in the Cost Engine.
  • The full test takes about 42 secs to excute on a 2Mb RAM MacBook Pro running on Java6 and PostgreSQL 8.

Input Parameters

Fig. 3 - Business Case Story Test, with correct asserts. Non-colored are the input params. You can modify it and save as another StoryTest. See this spreadsheet example

User Setup Data

  • Client:GardenWorld
  • Calendar:Default
  • Currency:USD
  • Product: Oak
  • Vendor: SeedFarm
  • CostType: Average Costing
  • Starting Date: Jan 1, 2010

(You can see the setup data screen here)

Transaction Input

  • Days from Today: Added to Starting Date
  • Qty: Quantity in transaction
  • Price: Purchase or Sales Price
  • Transaction Type:
    • Purchase/Receipt - Purchase Order and Material Receipt of the same order
    • Credit Sales - Sales Order which results in immediate Shipment
    • Invoice Receipt - Invoice Vendor of a previous Material Receipt
    • View Shipment - Access of a previous Sales Shipment record
    • Reverse Receipt - Reverse-Correct of a previous Material Receipt
    • Movement - creation of an Inventory Movement
    • Physical Inventory - creation of a Physical Inventory with Book Qty taken from the last Cost Detail's Accumulated Qty
    • Internal Use - taking from inventory for internal use, minus qty is the qty taken
  • Ref: Reference count of previous transactions passed to present transaction
  • Initiate Transaction - Assert of Transaction success.

Output Format

From MCost table

  • Current Cost Price
  • Cumulative Qty
  • Cumulative Amt

From CostDetail table

  • Cost Detail Amt
  • CD Adjust
  • CD Qty
  • CD Current Cost
  • CD Cumulative Qty
  • CD Cumulative Amt
Fig. 4 - StoryTest Steps, each row for each event.

Testing Steps

(see Fig. 4)

  1. Purchase of 10 Oaks at $36 each and Material Receipt all of them
  2. Credit Sales of 5 Oaks at $45
  3. Purchase of 10 Oaks at $34 each and Material Receipt all of them
  4. Credit Sales of 5 Oaks at $45
  5. Invoice Vendor issued on the first receipt of 10 Oaks at $38 each
  6. View Shipment of first Sales Order
  7. Reverse the first Material Receipt
  8. View the Reversal Record
  9. Purchase of 10 Oaks at $37 each and Material Receipt all of them
  10. Movement of 5 Oaks from HQ to Store
  11. Physical Inventory count of 20 Oaks and book qty from Movement Cost.accumulatedQty
  12. Internal Use of 5 Oaks


(please see Fig. 1,2,3)


  • Movement is not giving right figures and affects Physical Inventory's Cost Details. (reviewing with Victor)
    • Resolved by Victor's subsequent patch.
Fig. 5 - Tested on a new Product with zero history.

How To Use

  • Is there an easier way? Yes, over here. You get all the files in one go and follow the README.txt inside it.


Setup Cost Engine in ADempiere

  • You should have your own working ADempiere instance setup in a server.
  • Take the LiberoCE.jars, unzip into ADempiereHome/lib folder
  • Take the ExpDatCE.jar, unzip into ADempiereHome/data folder
  • /RUN_silentsetup
  • /utils/RUN_DBRestore

Setup Fitnesse Server

  • Refer to FitnesseSlim till the step of java -jar fitnesse.jar -p 8080.
  • Get your browser to point to http://localhost:8080/CostEngine
  • Edit wiki and put the contents of AverageInvoiceCostTestData.txt in.
  • Save it.
  • Note the paths as shown on the right here. Edit them to point to your instance.
  • Save, and click on Test.

Making Asserts

  • Replace the blank columns in each row with the same figures or corrected figures and the test will compare and colour the values with green if true and red if false.

Reported Test Cases

The following are test cases submitted in SourceForge forums as referenced in Cost Engine/Testing. If you have more test cases you think are significant and needed please post in SourceForge and add to the wiki reference. - Redhuan D. Oon

Yogan Naidoo's Case

!|Costing Transaction for |
|Item|Days from today|Qty|Price|Transaction Type|Ref|Initiate Transaction?|Current Cost 
Price?|Cumulative Qty?|Cumulative Amt?|Cost Detail Amt?|CD Adjust?|CD Qty?|CD Current Cost?|CD 
Cumulative Qty?|CD Cumulative Amt?|Get Account?|
|1  |0  |10  |40  |Purchase/Receipt  |0  |true  |40.0000  |10  |400  |400.0000  |0  |10  |0  |0  |0  |true|
|2 |1 |30 |20 |Purchase/Receipt |0 |true |25.0000 |40 |1000 |750.0000 |0 |30 |40.0000 |10 |400 |true|
|3 |2 |5 |80 |Credit Sales |0 |true |25.0000 |35 |875.0000 |125.0000 |0 |-5 |25.0000 |40 |1000 |true|
|4 |0 |0 |0 |Reverse Receipt |1 |true |20.0000 |25 |500.0000 |400.0000 |0 |10 |0 |0 |0 |true|

Yogan Naidoo's case tested on the new Cost Engine using same Testing Framework module
  • The output here gives a correct result confirmed back by Yogan.

Accounting Consequence

  • To achieve this, you have to Login as SystemAdmin and manually setup CLIENT_ACCOUNTING as I - Immediate.
Accounts Posting as accounting consequence from the last test
  • Fitnesse can also obtain black box information for Accounting Consequence during the transactions.
  • They are placed in an array and produced at the end of the test.
  • Above is the sample output based on the above Yogan Naidoo's case.
  • Below is the accounting consequence of the complete CASE I test.
Accounts Posting for the CASE I above