BF [1920179] - VPayment completing documents outside of Trx

https://sourceforge.net/tracker/?func=detail&atid=879332&aid=1920179&group_id=176962
Thanks to Tobi (tobi42)
This commit is contained in:
Carlos Ruiz 2009-08-13 16:38:58 +00:00
parent 2b7ed729bc
commit ca2ee0aa5b
1 changed files with 37 additions and 20 deletions

View File

@ -70,6 +70,8 @@ import org.compiere.util.Env;
import org.compiere.util.KeyNamePair; import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg; import org.compiere.util.Msg;
import org.compiere.util.TimeUtil; import org.compiere.util.TimeUtil;
import org.compiere.util.Trx;
import org.compiere.util.TrxRunnable;
import org.compiere.util.ValueNamePair; import org.compiere.util.ValueNamePair;
/** /**
@ -909,8 +911,22 @@ public class VPayment extends CDialog
* Save Changes * Save Changes
* @return true, if Window can exit * @return true, if Window can exit
*/ */
private boolean saveChanges() private boolean saveChanges() {
{
// BF [ 1920179 ] perform the save in a trx's context.
final boolean[] success = new boolean[] { false };
final TrxRunnable r = new TrxRunnable() {
public void run(String trxName) {
success[0] = saveChangesInTrx(trxName);
}
};
Trx.run(Trx.createTrxName("VPayment"), r);
return success[0];
} // saveChanges
private boolean saveChangesInTrx(final String trxName){
ValueNamePair vp = (ValueNamePair)paymentCombo.getSelectedItem(); ValueNamePair vp = (ValueNamePair)paymentCombo.getSelectedItem();
String newPaymentRule = vp.getValue(); String newPaymentRule = vp.getValue();
log.info("New Rule: " + newPaymentRule); log.info("New Rule: " + newPaymentRule);
@ -1029,7 +1045,7 @@ public class VPayment extends CDialog
log.fine("Old Payment(1) - " + m_mPaymentOriginal); log.fine("Old Payment(1) - " + m_mPaymentOriginal);
m_mPaymentOriginal.setDocAction(DocAction.ACTION_Reverse_Correct); m_mPaymentOriginal.setDocAction(DocAction.ACTION_Reverse_Correct);
boolean ok = m_mPaymentOriginal.processIt(DocAction.ACTION_Reverse_Correct); boolean ok = m_mPaymentOriginal.processIt(DocAction.ACTION_Reverse_Correct);
m_mPaymentOriginal.save(); m_mPaymentOriginal.saveEx(trxName);
if (ok) if (ok)
log.info( "Payment Canecelled - " + m_mPaymentOriginal); log.info( "Payment Canecelled - " + m_mPaymentOriginal);
else else
@ -1044,7 +1060,7 @@ public class VPayment extends CDialog
{ {
m_mPaymentOriginal.setDocAction(DocAction.ACTION_Reverse_Correct); m_mPaymentOriginal.setDocAction(DocAction.ACTION_Reverse_Correct);
boolean ok = m_mPaymentOriginal.processIt(DocAction.ACTION_Reverse_Correct); boolean ok = m_mPaymentOriginal.processIt(DocAction.ACTION_Reverse_Correct);
m_mPaymentOriginal.save(); m_mPaymentOriginal.saveEx(trxName);
if (ok) // Cancel Payment if (ok) // Cancel Payment
{ {
log.fine("PaymentCancelled " + m_mPayment.getDocumentNo ()); log.fine("PaymentCancelled " + m_mPayment.getDocumentNo ());
@ -1069,12 +1085,12 @@ public class VPayment extends CDialog
MInvoice invoice = null; MInvoice invoice = null;
if (C_Invoice_ID != 0) if (C_Invoice_ID != 0)
{ {
invoice = new MInvoice (Env.getCtx(), C_Invoice_ID, null); invoice = new MInvoice (Env.getCtx(), C_Invoice_ID, trxName);
negateAmt = invoice.isCreditMemo(); negateAmt = invoice.isCreditMemo();
} }
MOrder order = null; MOrder order = null;
if (invoice == null && C_Order_ID != 0) if (invoice == null && C_Order_ID != 0)
order = new MOrder (Env.getCtx(), C_Order_ID, null); order = new MOrder (Env.getCtx(), C_Order_ID, trxName);
BigDecimal payAmount = m_Amount; BigDecimal payAmount = m_Amount;
@ -1108,7 +1124,7 @@ public class VPayment extends CDialog
//m_cashLine.setAmount(payAmount); //m_cashLine.setAmount(payAmount);
m_cashLine.setAmount((BigDecimal) bAmountField.getValue()); m_cashLine.setAmount((BigDecimal) bAmountField.getValue());
// ADialog.info(m_WindowNo, this, "m_cashLine - Changed Amount", "Amount: "+m_cashLine.getAmount()); // ADialog.info(m_WindowNo, this, "m_cashLine - Changed Amount", "Amount: "+m_cashLine.getAmount());
if (m_cashLine.save()) m_cashLine.saveEx(trxName);
log.config("CashAmt Changed"); log.config("CashAmt Changed");
} }
// Different Date/CashBook // Different Date/CashBook
@ -1118,7 +1134,7 @@ public class VPayment extends CDialog
{ {
log.config("Changed CashBook/Date: " + m_C_CashBook_ID + "->" + newC_CashBook_ID); log.config("Changed CashBook/Date: " + m_C_CashBook_ID + "->" + newC_CashBook_ID);
MCashLine reverse = m_cashLine.createReversal(); MCashLine reverse = m_cashLine.createReversal();
if (!reverse.save()) if (!reverse.save(trxName))
ADialog.error(m_WindowNo, this, "PaymentError", "CashNotCancelled"); ADialog.error(m_WindowNo, this, "PaymentError", "CashNotCancelled");
m_cashLine = null; m_cashLine = null;
} }
@ -1134,9 +1150,9 @@ public class VPayment extends CDialog
C_Currency_ID = order.getC_Currency_ID(); C_Currency_ID = order.getC_Currency_ID();
MCash cash = null; MCash cash = null;
if (newC_CashBook_ID != 0) if (newC_CashBook_ID != 0)
cash = MCash.get (Env.getCtx(), newC_CashBook_ID, newDateAcct, null); cash = MCash.get (Env.getCtx(), newC_CashBook_ID, newDateAcct, trxName);
else // Default else // Default
cash = MCash.get (Env.getCtx(), m_AD_Org_ID, newDateAcct, C_Currency_ID, null); cash = MCash.get (Env.getCtx(), m_AD_Org_ID, newDateAcct, C_Currency_ID, trxName);
if (cash == null || cash.get_ID() == 0) if (cash == null || cash.get_ID() == 0)
ADialog.error(m_WindowNo, this, "PaymentError", CLogger.retrieveErrorString("CashNotCreated")); ADialog.error(m_WindowNo, this, "PaymentError", CLogger.retrieveErrorString("CashNotCreated"));
else else
@ -1148,28 +1164,28 @@ public class VPayment extends CDialog
cl.setInvoice(invoice); // overrides amount cl.setInvoice(invoice); // overrides amount
if (order != null) if (order != null)
{ {
cl.setOrder(order, null); // overrides amount cl.setOrder(order, trxName); // overrides amount
m_needSave = true; m_needSave = true;
} }
cl.setAmount((BigDecimal)bAmountField.getValue()); cl.setAmount((BigDecimal)bAmountField.getValue());
if (cl.save()) if (cl.save(trxName))
{ {
log.config("CashCreated"); log.config("CashCreated");
if (invoice == null && C_Invoice_ID != 0) if (invoice == null && C_Invoice_ID != 0)
{ {
invoice = new MInvoice (Env.getCtx(), C_Invoice_ID, null); invoice = new MInvoice (Env.getCtx(), C_Invoice_ID, trxName);
} }
if (invoice != null) { if (invoice != null) {
invoice.setC_CashLine_ID(cl.getC_CashLine_ID()); invoice.setC_CashLine_ID(cl.getC_CashLine_ID());
invoice.save(); invoice.saveEx(trxName);
} }
if (order == null && C_Order_ID != 0) if (order == null && C_Order_ID != 0)
{ {
order = new MOrder (Env.getCtx(), C_Order_ID, null); order = new MOrder (Env.getCtx(), C_Order_ID, trxName);
} }
if (order != null) { if (order != null) {
order.setC_CashLine_ID(cl.getC_CashLine_ID()); order.setC_CashLine_ID(cl.getC_CashLine_ID());
order.save(); order.saveEx(trxName);
} }
log.config("Update Order & Invoice with CashLine"); log.config("Update Order & Invoice with CashLine");
} }
@ -1275,7 +1291,7 @@ public class VPayment extends CDialog
m_mTab.setValue("C_CashLine_ID", new Integer(newC_CashLine_ID)); m_mTab.setValue("C_CashLine_ID", new Integer(newC_CashLine_ID));
} }
return true; return true;
} // saveChanges }
/** /**
* Check Mandatory * Check Mandatory
@ -1540,3 +1556,4 @@ public class VPayment extends CDialog
} // needSave } // needSave
} // VPayment } // VPayment
;