From 9ff1e954c779c5eacff8715e7206447dcc4c6a32 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Mon, 7 Dec 2009 21:30:27 +0000 Subject: [PATCH] BF [2910289] - More on RMA Stabilization https://sourceforge.net/tracker/?func=detail&aid=2910289&group_id=176962&atid=879332 Refactor for a better approach (update directly via SQL to avoid overload of change log and all the stuff of PO - like invoiceline) --- base/src/org/compiere/model/MRMALine.java | 48 +++++++++++++---------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/base/src/org/compiere/model/MRMALine.java b/base/src/org/compiere/model/MRMALine.java index a5f0e47559..29ba691622 100644 --- a/base/src/org/compiere/model/MRMALine.java +++ b/base/src/org/compiere/model/MRMALine.java @@ -36,7 +36,7 @@ public class MRMALine extends X_M_RMALine /** * */ - private static final long serialVersionUID = -4939372209739721247L; + private static final long serialVersionUID = 7542507297588438252L; /** * Standard Constructor @@ -291,15 +291,7 @@ public class MRMALine extends X_M_RMALine return success; } - MRMA rma = getParent(); - rma.updateAmount(); - - if (!rma.save(get_TrxName())) - { - throw new IllegalStateException("Could not update RMA grand total"); - } - - return true; + return updateHeaderAmt(); } @Override @@ -310,17 +302,33 @@ public class MRMALine extends X_M_RMALine return success; } - MRMA rma = getParent(); - rma.updateAmount(); - - if (!rma.save(get_TrxName())) - { - throw new IllegalStateException("Could not update RMA grand total"); - } - - return true; + return updateHeaderAmt(); } - + + /** + * Update Amount on Header + * @return true if header updated + */ + private boolean updateHeaderAmt() + { + // Update header only if the document is not processed + if (isProcessed() && !is_ValueChanged(COLUMNNAME_Processed)) + return true; + + // Update RMA Header + String sql = "UPDATE M_RMA " + + " SET Amt=" + + "(SELECT COALESCE(SUM(LineNetAmt),0) FROM M_RMALine WHERE M_RMA.M_RMA_ID=M_RMALine.M_RMA_ID) " + + "WHERE M_RMA_ID=?"; + int no = DB.executeUpdateEx(sql, new Object[]{getM_RMA_ID()}, get_TrxName()); + if (no != 1) + log.warning("(1) #" + no); + + m_parent = null; + + return no == 1; + } // updateHeaderTax + /** * Add to Description * @param description text