Sistematika’s Journal

Diberkati untuk memberkati

Accounting Generated for Adempiere Material Receipt activity

Posted by: Bayu Cahya P on: October 10, 2008

Recently, we are doing test case with Adempiere Material Receipt. To test accounting generated by Adempiere, we just created Purchase Order with difference currency than default accounting schema currency.

This is our Adempiere configuration

1. Last version from branches/stable (352a with revision 6642)
2. Accounting Schema Currency was USD
3. Costing method Average PO

And this is our activity

1. Create Purchase Order with IDR currency
2. Material receipt
3. Matching PO-Receipt

Within this activity, there are some nice features while we are doing Material Receipt (we call MR for later). As far as i know, while practicing MR within Lawson/Intentia Movex ERP using PPS300, this program module requires Purchase Order (we call PO for later) as mandatory information while doing MR. Like Movex does MR, Adempiere can do MR with knowing PO.

Fortunately, Adempiere provides material receipt activity without knowing Purchase Order in the beginning. We can built relationship between PO and MR while doing Matching PO-Receipt

Okay, let’s start our Adempiere MR journey with this condition:
- Create Price List IDR
- Price list for this product was IDR 700.000,-
- Buy 1 product (motherboard computer)
- Amended PO price for this product to IDR 710.000,-
- Rate USD 1 equivalen with IDR 10.000,- (for simplicity)

This is our PO line

Adempiere PO line

After completing and posting PO document, we are following it with doing Material Receipt as per this picture

Adempiere Receipt Line

Now, complete and post this MR document. Take a look within below figure

accounting detail generated

The weird thing within Accounting Fact details generated was
- Currency generated using default accounting schema currency (USD and not IDR)
- Because of using default accounting schema currency, source debit and source credit value automatically using IDR converted value

Okay, let’s continue to create another test case

1. Create Second PO with the same product with ammending price to IDR 720.000,-. Post this document.
2. Create third PO with the same product with ammending price to IDR 730.000,-. Post this document.
3. Do Material Receipt for second PO and complete and post this document.
4. Do Material Receipt for third PO and complete and post this document.

While we were doing MR for second and third PO, accounting generated was wrong. Please take a look within below figure

accounting detail generated 2

Adempiere still using the previous price.

How to correct this behavior ?

Don’t worry. With the power of Adempiere community, they can help us to fix the problem. But, it would be better if we can help community with trying to fixing and contribute back.

While diging to Adempiere source code, accounting generated for MR was pointed to Doc_InOut.java (with package org.compiere.acc). We will see this below code. (For simplicity, we just show appropriate source codes)

//  *** Purchasing - Receipt
else if (getDocumentType().equals(DOCTYPE_MatReceipt) && !isSOTrx())
{
 for (int i = 0; i < p_lines.length; i++)
     {
          // Elaine 2008/06/26
          int C_Currency_ID = as.getC_Currency_ID();
          //
          DocLine line = p_lines[i];
          BigDecimal costs = null;
          MProduct product = line.getProduct();
          //get costing method for product
          String costingMethod = product.getCostingMethod(as);
          if (MAcctSchema.COSTINGMETHOD_AveragePO.equals(costingMethod) ||
             MAcctSchema.COSTINGMETHOD_LastPOPrice.equals(costingMethod) )
          {
             int C_OrderLine_ID = line.getC_OrderLine_ID();
             // Low - check if c_orderline_id is valid
             if (C_OrderLine_ID > 0)
             {
                MOrderLine orderLine = new MOrderLine (getCtx(), C_OrderLine_ID, getTrxName());
                costs = orderLine.getPriceCost();
                if (costs == null || costs.signum() == 0)
                costs = orderLine.getPriceActual();
                costs = costs.multiply(line.getQty());
                // Elaine 2008/06/26
                C_Currency_ID = orderLine.getC_Currency_ID();
                //
             }
             else
             {
              costs = line.getProductCosts(as, line.getAD_Org_ID(), false); // current costs
             }

I thought, the main problem with this code was, Adempiere trying to get costs from line.getProductCosts while there are no matching order line. We just want to propose, while there are no matching order line, just raise some exception. After doing some Matching PO-Receipt, then Adempiere will get the proper currency and price.

This our patching source codes

//  *** Purchasing - Receipt
else if (getDocumentType().equals(DOCTYPE_MatReceipt) && !isSOTrx())
{
 for (int i = 0; i < p_lines.length; i++)
     {
          // Elaine 2008/06/26
          int C_Currency_ID = as.getC_Currency_ID();
          //
          DocLine line = p_lines[i];
          BigDecimal costs = null;
          MProduct product = line.getProduct();
          //get costing method for product
          String costingMethod = product.getCostingMethod(as);
          if (MAcctSchema.COSTINGMETHOD_AveragePO.equals(costingMethod) ||
             MAcctSchema.COSTINGMETHOD_LastPOPrice.equals(costingMethod) )
          {
             int C_OrderLine_ID = line.getC_OrderLine_ID();
             // Low - check if c_orderline_id is valid
             if (C_OrderLine_ID > 0)
             {
                MOrderLine orderLine = new MOrderLine (getCtx(), C_OrderLine_ID, getTrxName());
                costs = orderLine.getPriceCost();
                if (costs == null || costs.signum() == 0)
                costs = orderLine.getPriceActual();
                costs = costs.multiply(line.getQty());
                // Elaine 2008/06/26
                C_Currency_ID = orderLine.getC_Currency_ID();
                //
             }
             else
             {
                 // costs = line.getProductCosts(as, line.getAD_Org_ID(), false);       //      current costs

                 // Bayu Sistematika
                 // While C_OrderLine_ID <= 0 or null, its better to sent errors.
                 // If we are using getProductCosts, we will using acc schema currency,
                 // even thought the purchase order using different currency.
                 // We prefer using amt and currency from PO while we are doing PO matching
                 p_Error = "Resubmit - No Costs for " + product.getName();
                 log.log(Level.WARNING, p_Error);
                 return null;
                 // Bayu end

             }

With this approach, we can make accounting generated consistency.

And finally, this is our Adempiere accounting generated for next test while applying our proposed fixing. Check for IDR currency generated

accounting detail generated 3

That’s all. You can access and get full source code within this Adempiere bug track

4 Responses to "Accounting Generated for Adempiere Material Receipt activity"

1 | Redhuan D. Oon

October 10th, 2008 at 11:05 pm

This is very nice cosy place to have an ADempiere tutorial! Syabas and keep up your great work Bayu!

Peace!
red1

2 | Lokune

July 22nd, 2009 at 8:49 pm

Am looking at adempiere accounting and this came in handy coz am assured when i get down to work,I will be releaved of some stressing issues.Thank u very much Bayu!!

3 | Vinay

September 23rd, 2009 at 3:41 pm

Hi…..
I am working on adempiere last 1 year.But still i not getting knowledge about accounting how adempiere handles it.
But i read ur documnet its really understandable.
Thanks

4 | Ayaz Ahmed

June 23rd, 2010 at 5:33 pm

Hi

I have same problem in average invoice costing method. When I create 2nd or 3rd Material Receipt system gets average cost instead of invoice amount. Can you assistance me for this issue I will be very thank full to you.

Ayaz Ahmed

Comment Form

SEO Powered by Platinum SEO from Techblissonline