Costing Engine - Allowing Back to Back Costing

All Case Experiences in Topic format. Easy reading mode for contextual understanding. Quickie snapshot and howtos Files are linked into http://compiere.red1.org/

Costing Engine - Allowing Back to Back Costing

Postby red1 » Sun Sep 03, 2006 8:26 pm

To investigate the accounting process that sprangs from Invoice issuance during a sale. We wish to locate some culprit that has a mind of its own - Accts Variances either in InvoicePrice or PurchasePrice. The guess is that it picks up variances from the cost of an item versus the price its sold. That’s fine but when its using a certain Costing Method such as Average Costing, it will average out all previous purchase costs of that item before giving the variance. Again fine, but in cases where the product is purchased from a supplier and sold back-to-back to a customer, usually in Projects or Contracts, the cost should be actual and not involving any history.

So the purpose of this study is to locate the right spot to place a fix where if there is a corresponding PO to a SO, its actual cost must be from the PO. We have to know how the Costing engine work, and where is such a cost stored and obtained.

Thus we need to first understand if these assumptions are true in Compiere Accounting Engine. The path should reveal to us the workings of ProductCosting Types such as Std, Average, LIFO and FIFO, and hopefully Inventory Stock Valuation too.

1. Starting at Invoice creation stage i.e. where Doc_Invoice.java does posting.

2. It updates the Product_PO table i.e. the fields - PriceLastInv & PriceLastPO. Question is what are these Lasts used for?

3. In that java, in method - ArrayList CreateFacts:
    a) If DocType is APInvoice then proceed (this is taking the AP path);
    b) Debit(DR) Charge, TaxCredit, Expense
    c) Landed Cost or Expense
    d) Set Locations
    e) Credit(CR)Liability - if Acct_ID is PayableServices OR PostServices OR Services
    f) UpdateProductPO:
    i. Lookup last invoice that has same Product sold to get its PriceActual
    ii. Update that price into the ProductPO's PriceLastInv.
    iii. MCostDetail.CreateInvoice new cost detail for AP Invoices for adjustments.

Note: last invoice is obtained in the SQL - ROWNUM=1

There is a check if its isExplicitCostAdjustment() during CreateFacts.

DocInvoice.LandedCost furthers into ProductCost.java. In there an SQL begins to draw out the following accounts:
Code: Select all
SELECT P_Revenue_Acct, P_Expense_Acct, P_Asset_Acct, P_Cogs_Acct,
         P_PurchasePriceVariance_Acct, P_InvoicePriceVariance_Acct,
         P_TradeDiscountRec_Acct, P_TradeDiscountGrant_Acct,         
         P_CostAdjustment_Acct, P_InventoryClearing_Acct                  FROM M_Product_Acct


During CostDetail, if AD_Client.isCostImmediate() then only CostDetail.process(). In Process(), CostElement.Methods checked and CostQueue if LIFO/FIFO

InvoicePriceVariance finalises during shipment and thus in Doc_MatchInv.java where it obtains the difference via ipv = cr.getAcctBalance().add(dr.getAcctBalance()).negate()
The Matching happens during shipments, either Material Receipts or Shipments out. We now have to peer into the codes to confirm its so. And to finally lead to this: which and when is the process that gives the Cost of the product and thus to stop it there when we needed.

We also need to investigate the other mysterious methods that pop up along the way here.
(the journey continues..)
red1
Site Admin
 
Posts: 2760
Joined: Tue Jul 06, 2004 3:01 pm
Location: Kuala Lumpur, Malaysia

Return to Compiere Case Workshop

Who is online

Users browsing this forum: No registered users and 1 guest

cron