#1002861 Product Costing in Bizidum. Fixed wrong cost calculation for average po costing. Auto post the reversal matching doc. IDEMPIERE-1180 IDEMPIERE-1188
This commit is contained in:
parent
266e55afc8
commit
4d36bcb679
|
@ -174,7 +174,7 @@ public class Doc_MatchPO extends Doc
|
||||||
boolean isReturnTrx = inOut.getMovementType().equals(X_M_InOut.MOVEMENTTYPE_VendorReturns);
|
boolean isReturnTrx = inOut.getMovementType().equals(X_M_InOut.MOVEMENTTYPE_VendorReturns);
|
||||||
|
|
||||||
// calculate po cost
|
// calculate po cost
|
||||||
poCost = poCost.multiply(getQty()); // Delivered so far
|
BigDecimal deliveredCost = poCost.multiply(getQty()); // Delivered so far
|
||||||
|
|
||||||
Map<Integer, BigDecimal> landedCostMap = new LinkedHashMap<Integer, BigDecimal>();
|
Map<Integer, BigDecimal> landedCostMap = new LinkedHashMap<Integer, BigDecimal>();
|
||||||
BigDecimal landedCost = BigDecimal.ZERO;
|
BigDecimal landedCost = BigDecimal.ZERO;
|
||||||
|
@ -216,7 +216,7 @@ public class Doc_MatchPO extends Doc
|
||||||
}
|
}
|
||||||
landedCostMap.put(elementId, elementAmt);
|
landedCostMap.put(elementId, elementAmt);
|
||||||
}
|
}
|
||||||
BigDecimal totalCost = poCost.add(landedCost);
|
BigDecimal totalCost = deliveredCost.add(landedCost);
|
||||||
|
|
||||||
// Different currency
|
// Different currency
|
||||||
if (m_oLine.getC_Currency_ID() != as.getC_Currency_ID())
|
if (m_oLine.getC_Currency_ID() != as.getC_Currency_ID())
|
||||||
|
@ -394,10 +394,25 @@ public class Doc_MatchPO extends Doc
|
||||||
MInOut inOut = m_ioLine.getParent();
|
MInOut inOut = m_ioLine.getParent();
|
||||||
boolean isReturnTrx = inOut.getMovementType().equals(X_M_InOut.MOVEMENTTYPE_VendorReturns);
|
boolean isReturnTrx = inOut.getMovementType().equals(X_M_InOut.MOVEMENTTYPE_VendorReturns);
|
||||||
|
|
||||||
|
// Create Cost Detail Matched PO using Total Amount and Total Qty based on OrderLine
|
||||||
|
MMatchPO[] mPO = MMatchPO.getOrderLine(getCtx(), m_oLine.getC_OrderLine_ID(), getTrxName());
|
||||||
|
BigDecimal tQty = Env.ZERO;
|
||||||
|
BigDecimal tAmt = Env.ZERO;
|
||||||
|
for (int i = 0 ; i < mPO.length ; i++)
|
||||||
|
{
|
||||||
|
if (mPO[i].getM_AttributeSetInstance_ID() == mMatchPO.getM_AttributeSetInstance_ID()
|
||||||
|
&& mPO[i].getM_MatchPO_ID() != mMatchPO.getM_MatchPO_ID())
|
||||||
|
{
|
||||||
|
BigDecimal qty = (isReturnTrx ? mPO[i].getQty().negate() : mPO[i].getQty());
|
||||||
|
tQty = tQty.add(qty);
|
||||||
|
tAmt = tAmt.add(poCost.multiply(qty));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
poCost = poCost.multiply(getQty()); // Delivered so far
|
poCost = poCost.multiply(getQty()); // Delivered so far
|
||||||
BigDecimal tAmt = isReturnTrx ? poCost.negate() : poCost;
|
tAmt = tAmt.add(isReturnTrx ? poCost.negate() : poCost);
|
||||||
BigDecimal tQty = isReturnTrx ? getQty().negate() : getQty();
|
tQty = tQty.add(isReturnTrx ? getQty().negate() : getQty());
|
||||||
|
|
||||||
// Set Total Amount and Total Quantity from Matched PO
|
// Set Total Amount and Total Quantity from Matched PO
|
||||||
if (!MCostDetail.createOrder(as, m_oLine.getAD_Org_ID(),
|
if (!MCostDetail.createOrder(as, m_oLine.getAD_Org_ID(),
|
||||||
getM_Product_ID(), mMatchPO.getM_AttributeSetInstance_ID(),
|
getM_Product_ID(), mMatchPO.getM_AttributeSetInstance_ID(),
|
||||||
|
|
|
@ -2213,6 +2213,9 @@ public class MInOut extends X_M_InOut implements DocAction
|
||||||
reversal.setReversal_ID(getM_InOut_ID());
|
reversal.setReversal_ID(getM_InOut_ID());
|
||||||
reversal.saveEx(get_TrxName());
|
reversal.saveEx(get_TrxName());
|
||||||
//
|
//
|
||||||
|
reversal.docsPostProcess = this.docsPostProcess;
|
||||||
|
this.docsPostProcess = new ArrayList<PO>();
|
||||||
|
//
|
||||||
if (!reversal.processIt(DocAction.ACTION_Complete)
|
if (!reversal.processIt(DocAction.ACTION_Complete)
|
||||||
|| !reversal.getDocStatus().equals(DocAction.STATUS_Completed))
|
|| !reversal.getDocStatus().equals(DocAction.STATUS_Completed))
|
||||||
{
|
{
|
||||||
|
@ -2253,6 +2256,7 @@ public class MInOut extends X_M_InOut implements DocAction
|
||||||
log.log(Level.SEVERE, "Failed to create reversal for match invoice " + mMatchInv.getDocumentNo());
|
log.log(Level.SEVERE, "Failed to create reversal for match invoice " + mMatchInv.getDocumentNo());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
addDocsPostProcess(new MMatchInv(Env.getCtx(), mMatchInv.getReversal_ID(), get_TrxName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MMatchPO[] mMatchPOList = MMatchPO.getInOut(getCtx(), getM_InOut_ID(), get_TrxName());
|
MMatchPO[] mMatchPOList = MMatchPO.getInOut(getCtx(), getM_InOut_ID(), get_TrxName());
|
||||||
|
@ -2269,6 +2273,7 @@ public class MInOut extends X_M_InOut implements DocAction
|
||||||
log.log(Level.SEVERE, "Failed to create reversal for match purchase order " + mMatchPO.getDocumentNo());
|
log.log(Level.SEVERE, "Failed to create reversal for match purchase order " + mMatchPO.getDocumentNo());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
addDocsPostProcess(new MMatchPO(Env.getCtx(), mMatchPO.getReversal_ID(), get_TrxName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -2342,6 +2342,7 @@ public class MInvoice extends X_C_Invoice implements DocAction
|
||||||
m_processMsg = "Could not Reverse MatchInv";
|
m_processMsg = "Could not Reverse MatchInv";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
addDocsPostProcess(new MMatchInv(Env.getCtx(), mInv[i].getReversal_ID(), get_TrxName()));
|
||||||
}
|
}
|
||||||
MMatchPO[] mPO = MMatchPO.getInvoice(getCtx(), getC_Invoice_ID(), get_TrxName());
|
MMatchPO[] mPO = MMatchPO.getInvoice(getCtx(), getC_Invoice_ID(), get_TrxName());
|
||||||
for (int i = 0; i < mPO.length; i++)
|
for (int i = 0; i < mPO.length; i++)
|
||||||
|
@ -2356,6 +2357,7 @@ public class MInvoice extends X_C_Invoice implements DocAction
|
||||||
m_processMsg = "Could not Reverse MatchPO";
|
m_processMsg = "Could not Reverse MatchPO";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
addDocsPostProcess(new MMatchPO(Env.getCtx(), mPO[i].getReversal_ID(), get_TrxName()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2405,6 +2407,9 @@ public class MInvoice extends X_C_Invoice implements DocAction
|
||||||
reversal.setReversal_ID(getC_Invoice_ID());
|
reversal.setReversal_ID(getC_Invoice_ID());
|
||||||
reversal.saveEx(get_TrxName());
|
reversal.saveEx(get_TrxName());
|
||||||
//
|
//
|
||||||
|
reversal.docsPostProcess = this.docsPostProcess;
|
||||||
|
this.docsPostProcess = new ArrayList<PO>();
|
||||||
|
//
|
||||||
if (!reversal.processIt(DocAction.ACTION_Complete))
|
if (!reversal.processIt(DocAction.ACTION_Complete))
|
||||||
{
|
{
|
||||||
m_processMsg = "Reversal ERROR: " + reversal.getProcessMsg();
|
m_processMsg = "Reversal ERROR: " + reversal.getProcessMsg();
|
||||||
|
|
Loading…
Reference in New Issue