BF [ 2215840 ] MatchPO Bug Collection

This commit is contained in:
armenrz 2008-12-04 17:07:35 +00:00
parent e9ac5e52df
commit 67c15c25cd
2 changed files with 56 additions and 52 deletions

View File

@ -40,9 +40,8 @@ import org.compiere.util.Env;
* *
* @author Bayu Cahya, Sistematika * @author Bayu Cahya, Sistematika
* <li>BF [ 2240484 ] Re MatchingPO, MMatchPO doesn't contains Invoice info * <li>BF [ 2240484 ] Re MatchingPO, MMatchPO doesn't contains Invoice info
* * @author Armen Rizal, Goodwill Consulting
* @author Teo Sarca, www.arhipac.ro * <li>BF [ 2215840 ] MatchPO Bug Collection
* <li>BF [ 2314749 ] MatchPO not considering currency PriceMatchDifference
*/ */
public class MMatchPO extends X_M_MatchPO public class MMatchPO extends X_M_MatchPO
{ {
@ -488,28 +487,10 @@ public class MMatchPO extends X_M_MatchPO
} // getOrderLine } // getOrderLine
/** /**
* Get PriceActual from Invoice and convert it to Order Currency * Before Save
* @return Price Actual in Order Currency * @param newRecord new
* @return true
*/ */
public BigDecimal getInvoicePriceActual()
{
MInvoiceLine iLine = getInvoiceLine();
MInvoice invoice = iLine.getParent();
MOrder order = getOrderLine().getParent();
BigDecimal priceActual = iLine.getPriceActual();
int invoiceCurrency_ID = invoice.getC_Currency_ID();
int orderCurrency_ID = order.getC_Currency_ID();
if (invoiceCurrency_ID != orderCurrency_ID)
{
priceActual = MConversionRate.convert(getCtx(), priceActual, invoiceCurrency_ID, orderCurrency_ID,
invoice.getDateInvoiced(), invoice.getC_ConversionType_ID(),
getAD_Client_ID(), getAD_Org_ID());
}
return priceActual;
}
@Override
protected boolean beforeSave (boolean newRecord) protected boolean beforeSave (boolean newRecord)
{ {
// Set Trx Date // Set Trx Date
@ -580,7 +561,7 @@ public class MMatchPO extends X_M_MatchPO
is_ValueChanged("C_OrderLine_ID") || is_ValueChanged("C_InvoiceLine_ID"))) is_ValueChanged("C_OrderLine_ID") || is_ValueChanged("C_InvoiceLine_ID")))
{ {
BigDecimal poPrice = getOrderLine().getPriceActual(); BigDecimal poPrice = getOrderLine().getPriceActual();
BigDecimal invPrice = getInvoicePriceActual(); BigDecimal invPrice = getInvoiceLine().getPriceActual();
BigDecimal difference = poPrice.subtract(invPrice); BigDecimal difference = poPrice.subtract(invPrice);
if (difference.signum() != 0) if (difference.signum() != 0)
{ {
@ -609,6 +590,17 @@ public class MMatchPO extends X_M_MatchPO
} }
} }
if (newRecord || m_isInOutLineChange)
{
// Elaine 2008/6/20
String err = createMatchPOCostDetail();
if(err != null && err.length() > 0)
{
s_log.warning(err);
return false;
}
}
return true; return true;
} // beforeSave } // beforeSave
@ -619,19 +611,8 @@ public class MMatchPO extends X_M_MatchPO
* @param success success * @param success success
* @return success * @return success
*/ */
@Override
protected boolean afterSave (boolean newRecord, boolean success) protected boolean afterSave (boolean newRecord, boolean success)
{ {
if (newRecord && success)
{
// Elaine 2008/6/20
String err = createMatchPOCostDetail();
if(err != null && err.length() > 0)
{
s_log.warning(err);
return false;
}
}
// Purchase Order Delivered/Invoiced // Purchase Order Delivered/Invoiced
// (Reserved in VMatch and MInOut.completeIt) // (Reserved in VMatch and MInOut.completeIt)
if (success && getC_OrderLine_ID() != 0) if (success && getC_OrderLine_ID() != 0)
@ -712,7 +693,6 @@ public class MMatchPO extends X_M_MatchPO
* Before Delete * Before Delete
* @return true if acct was deleted * @return true if acct was deleted
*/ */
@Override
protected boolean beforeDelete () protected boolean beforeDelete ()
{ {
if (isPosted()) if (isPosted())
@ -731,7 +711,6 @@ public class MMatchPO extends X_M_MatchPO
* @param success success * @param success success
* @return success * @return success
*/ */
@Override
protected boolean afterDelete (boolean success) protected boolean afterDelete (boolean success)
{ {
// Order Delivered/Invoiced // Order Delivered/Invoiced
@ -885,8 +864,7 @@ public class MMatchPO extends X_M_MatchPO
BigDecimal tAmt = Env.ZERO; BigDecimal tAmt = Env.ZERO;
for (int i = 0 ; i < mPO.length ; i++) for (int i = 0 ; i < mPO.length ; i++)
{ {
if (mPO[i].isPosted() if (mPO[i].getM_AttributeSetInstance_ID() == getM_AttributeSetInstance_ID()
&& mPO[i].getM_AttributeSetInstance_ID() == getM_AttributeSetInstance_ID()
&& mPO[i].getM_MatchPO_ID() != get_ID()) && mPO[i].getM_MatchPO_ID() != get_ID())
{ {
BigDecimal qty = (isReturnTrx ? mPO[i].getQty().negate() : mPO[i].getQty()); BigDecimal qty = (isReturnTrx ? mPO[i].getQty().negate() : mPO[i].getQty());
@ -900,14 +878,17 @@ public class MMatchPO extends X_M_MatchPO
tQty = tQty.add(isReturnTrx ? getQty().negate() : getQty()); tQty = tQty.add(isReturnTrx ? getQty().negate() : getQty());
// Different currency // Different currency
String costingMethod = as.getCostingMethod();
if (oLine.getC_Currency_ID() != as.getC_Currency_ID()) if (oLine.getC_Currency_ID() != as.getC_Currency_ID())
{ {
MOrder order = oLine.getParent(); MOrder order = oLine.getParent();
Timestamp dateAcct = order.getDateAcct(); Timestamp dateAcct = order.getDateAcct();
//get costing method for product
MProduct product = new MProduct(getCtx(), getM_Product_ID(), get_TrxName());
String costingMethod = product.getCostingMethod(as);
if (MAcctSchema.COSTINGMETHOD_AveragePO.equals(costingMethod) || if (MAcctSchema.COSTINGMETHOD_AveragePO.equals(costingMethod) ||
MAcctSchema.COSTINGMETHOD_LastPOPrice.equals(costingMethod) ) MAcctSchema.COSTINGMETHOD_LastPOPrice.equals(costingMethod) )
dateAcct = inOut.getDateAcct(); //Movement Date dateAcct = inOut.getDateAcct(); //Movement Date
//
BigDecimal rate = MConversionRate.getRate( BigDecimal rate = MConversionRate.getRate(
order.getC_Currency_ID(), as.getC_Currency_ID(), order.getC_Currency_ID(), as.getC_Currency_ID(),
dateAcct, order.getC_ConversionType_ID(), dateAcct, order.getC_ConversionType_ID(),
@ -962,19 +943,23 @@ public class MMatchPO extends X_M_MatchPO
getC_OrderLine_ID(), getM_AttributeSetInstance_ID(), as.getC_AcctSchema_ID(), get_TrxName()); getC_OrderLine_ID(), getM_AttributeSetInstance_ID(), as.getC_AcctSchema_ID(), get_TrxName());
if (cd != null) if (cd != null)
{ {
BigDecimal price = cd.getAmt().divide(cd.getQty(),12,BigDecimal.ROUND_HALF_UP); if (cd.getQty().compareTo(Env.ZERO) > 0)
cd.setDeltaAmt(price.multiply(getQty().negate()));
cd.setDeltaQty(getQty().negate());
cd.setProcessed(false);
//
cd.setAmt(price.multiply(cd.getQty().subtract(getQty())));
cd.setQty(cd.getQty().subtract(getQty()));
if (!cd.isProcessed())
{ {
MClient client = MClient.get(getCtx(), getAD_Client_ID()); BigDecimal price = cd.getAmt().divide(cd.getQty(),12,BigDecimal.ROUND_HALF_UP);
if (client.isCostImmediate()) cd.setDeltaAmt(price.multiply(getQty().negate()));
cd.process(); cd.setDeltaQty(getQty().negate());
cd.setProcessed(false);
//
cd.setAmt(price.multiply(cd.getQty().subtract(getQty())));
cd.setQty(cd.getQty().subtract(getQty()));
if (!cd.isProcessed())
{
MClient client = MClient.get(getCtx(), getAD_Client_ID());
if (client.isCostImmediate())
cd.process();
}
} }
//after process clean-up
if (cd.getQty().compareTo(Env.ZERO) == 0) if (cd.getQty().compareTo(Env.ZERO) == 0)
{ {
cd.setProcessed(false); cd.setProcessed(false);

View File

@ -25,6 +25,9 @@ import org.compiere.util.*;
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: MatchPODelete.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $ * @version $Id: MatchPODelete.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
*
* @author Armen Rizal, Goodwill Consulting
* <li>BF [ 2215840 ] MatchPO Bug Collection
*/ */
public class MatchPODelete extends SvrProcess public class MatchPODelete extends SvrProcess
{ {
@ -50,8 +53,24 @@ public class MatchPODelete extends SvrProcess
MMatchPO po = new MMatchPO (getCtx(), p_M_MatchPO_ID, get_TrxName()); MMatchPO po = new MMatchPO (getCtx(), p_M_MatchPO_ID, get_TrxName());
if (po.get_ID() == 0) if (po.get_ID() == 0)
throw new AdempiereUserError("@NotFound@ @M_MatchPO_ID@ " + p_M_MatchPO_ID); throw new AdempiereUserError("@NotFound@ @M_MatchPO_ID@ " + p_M_MatchPO_ID);
//
MOrderLine orderLine = null;
boolean isMatchReceipt = (po.getM_InOutLine_ID() != 0);
if (isMatchReceipt)
{
orderLine = new MOrderLine (getCtx(), po.getC_OrderLine_ID(), get_TrxName());
orderLine.setQtyReserved(orderLine.getQtyReserved().add(po.getQty()));
}
//
if (po.delete(true)) if (po.delete(true))
{
if (isMatchReceipt)
{
if (!orderLine.save(get_TrxName()))
throw new AdempiereUserError("Delete MatchPO failed to restore PO's On Ordered Qty");
}
return "@OK@"; return "@OK@";
}
po.save(); po.save();
return "@Error@"; return "@Error@";
} // doIt } // doIt