FR [2799327] - Allow testing of accounting posting in development mode
https://sourceforge.net/tracker/?func=detail&aid=2799327&group_id=176962&atid=879335 Enable PostImmediate + EmbeddedServer
This commit is contained in:
parent
e87a101445
commit
9f395748b1
|
@ -28,6 +28,7 @@ import java.util.Iterator;
|
|||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.db.CConnection;
|
||||
import org.compiere.model.MAccount;
|
||||
import org.compiere.model.MAcctSchema;
|
||||
import org.compiere.model.MAllocationHdr;
|
||||
|
@ -56,6 +57,7 @@ import org.compiere.process.DocumentEngine;
|
|||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Ini;
|
||||
import org.compiere.util.Msg;
|
||||
import org.compiere.util.Trx;
|
||||
|
||||
|
@ -373,7 +375,7 @@ public abstract class Doc
|
|||
* @param defaultDocumentType default document type or null
|
||||
* @param trxName trx
|
||||
*/
|
||||
Doc (MAcctSchema[] ass, Class clazz, ResultSet rs, String defaultDocumentType, String trxName)
|
||||
Doc (MAcctSchema[] ass, Class<?> clazz, ResultSet rs, String defaultDocumentType, String trxName)
|
||||
{
|
||||
p_Status = STATUS_Error;
|
||||
m_ass = ass;
|
||||
|
@ -384,7 +386,7 @@ public abstract class Doc
|
|||
className = className.substring(className.lastIndexOf('.')+1);
|
||||
try
|
||||
{
|
||||
Constructor constructor = clazz.getConstructor(new Class[]{Properties.class, ResultSet.class, String.class});
|
||||
Constructor<?> constructor = clazz.getConstructor(new Class[]{Properties.class, ResultSet.class, String.class});
|
||||
p_po = (PO)constructor.newInstance(new Object[]{m_ctx, rs, trxName});
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -564,7 +566,12 @@ public abstract class Doc
|
|||
sql.append(" AND (Processing='N' OR Processing IS NULL)");
|
||||
if (!repost)
|
||||
sql.append(" AND Posted='N'");
|
||||
if (DB.executeUpdate(sql.toString(), null) == 1) // outside trx
|
||||
// Set transaction to lock record
|
||||
String trxName = null; // outside trx
|
||||
if (Ini.isClient() && CConnection.isServerEmbedded())
|
||||
trxName = getTrxName(); // within trx if server embedded in client
|
||||
//
|
||||
if (DB.executeUpdate(sql.toString(), trxName) == 1)
|
||||
log.info("Locked: " + get_TableName() + "_ID=" + get_ID());
|
||||
else
|
||||
{
|
||||
|
|
|
@ -39,7 +39,7 @@ public class MFactAcct extends X_Fact_Acct
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 5251847162314796574L;
|
||||
private static final long serialVersionUID = -5110168625445057323L;
|
||||
|
||||
/**
|
||||
* Delete Accounting
|
||||
|
@ -135,4 +135,19 @@ public class MFactAcct extends X_Fact_Acct
|
|||
return acct;
|
||||
} // getMAccount
|
||||
|
||||
/**
|
||||
* Check if there are already accounting facts for the document
|
||||
* @param AD_Table_ID table
|
||||
* @param Record_ID record
|
||||
* @param trxName transaction
|
||||
* @return true/false meaning if there are records or not
|
||||
* @throws DBException on database exception
|
||||
*/
|
||||
public static boolean thereAreFacts(int AD_Table_ID, int Record_ID, String trxName) throws DBException
|
||||
{
|
||||
final String sql = "SELECT 1 FROM Fact_Acct WHERE AD_Table_ID=? AND Record_ID=?";
|
||||
int one = DB.getSQLValue(trxName, sql, new Object[]{AD_Table_ID, Record_ID});
|
||||
return (one == 1);
|
||||
}
|
||||
|
||||
} // MFactAcct
|
||||
|
|
|
@ -286,7 +286,8 @@ public class DocumentEngine implements DocAction
|
|||
}
|
||||
status = completeIt();
|
||||
if (m_document != null
|
||||
&& !Ini.isClient()) // Post Immediate if on Server
|
||||
&& ( (Ini.isClient() && CConnection.isServerEmbedded())
|
||||
|| !Ini.isClient())) // Post Immediate if on Server or embedded server
|
||||
{
|
||||
MClient client = MClient.get(m_document.getCtx(), m_document.getAD_Client_ID());
|
||||
if (STATUS_Completed.equals(status) && client.isPostImmediate())
|
||||
|
@ -464,10 +465,13 @@ public class DocumentEngine implements DocAction
|
|||
Server server = CConnection.get().getServer();
|
||||
if (server != null)
|
||||
{
|
||||
String trxName = null;
|
||||
if (Ini.isClient() && CConnection.isServerEmbedded())
|
||||
trxName = m_document.get_TrxName();
|
||||
String error = server.postImmediate(Env.getRemoteCallCtx(Env.getCtx()),
|
||||
m_document.getAD_Client_ID(),
|
||||
m_document.get_Table_ID(), m_document.get_ID(),
|
||||
true, null);
|
||||
true, trxName);
|
||||
m_document.get_Logger().config("Server: " + error == null ? "OK" : error);
|
||||
return error == null;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.compiere.model.MBPartner;
|
|||
import org.compiere.model.MClient;
|
||||
import org.compiere.model.MColumn;
|
||||
import org.compiere.model.MConversionRate;
|
||||
import org.compiere.model.MFactAcct;
|
||||
import org.compiere.model.MMailText;
|
||||
import org.compiere.model.MNote;
|
||||
import org.compiere.model.MOrg;
|
||||
|
@ -57,9 +58,9 @@ import org.compiere.print.ReportEngine;
|
|||
import org.compiere.process.DocAction;
|
||||
import org.compiere.process.ProcessInfo;
|
||||
import org.compiere.process.StateEngine;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Ini;
|
||||
import org.compiere.util.Msg;
|
||||
import org.compiere.util.Trace;
|
||||
import org.compiere.util.Trx;
|
||||
|
@ -78,8 +79,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2104882570953130237L;
|
||||
|
||||
private static final long serialVersionUID = 1584816335412184476L;
|
||||
|
||||
/**
|
||||
* Get Activities for table/record
|
||||
|
@ -1491,6 +1491,11 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
|||
*/
|
||||
private void postImmediate()
|
||||
{
|
||||
String trxName = null;
|
||||
if (Ini.isClient() && CConnection.isServerEmbedded())
|
||||
trxName = m_postImmediate.get_TrxName();
|
||||
if (MFactAcct.thereAreFacts(m_postImmediate.get_Table_ID(), m_postImmediate.get_ID(), trxName))
|
||||
return; // the document was already posted in DocumentEngine.processIt
|
||||
if (CConnection.get().isAppsServerOK(false))
|
||||
{
|
||||
try
|
||||
|
@ -1501,7 +1506,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
|||
String error = server.postImmediate(Env.getRemoteCallCtx(Env.getCtx()),
|
||||
m_postImmediate.getAD_Client_ID(),
|
||||
m_postImmediate.get_Table_ID(), m_postImmediate.get_ID(),
|
||||
true, null);
|
||||
true, trxName);
|
||||
m_postImmediate.get_Logger().config("Server: " + error == null ? "OK" : error);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import javax.ejb.Stateless;
|
|||
import org.adempiere.util.ProcessUtil;
|
||||
import org.compiere.Adempiere;
|
||||
import org.compiere.acct.Doc;
|
||||
import org.compiere.db.CConnection;
|
||||
import org.compiere.interfaces.Server;
|
||||
import org.compiere.interfaces.ServerLocal;
|
||||
import org.compiere.interfaces.ServerRemote;
|
||||
|
@ -43,6 +44,7 @@ import org.compiere.util.CLogger;
|
|||
import org.compiere.util.CacheMgt;
|
||||
import org.compiere.util.EMail;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Ini;
|
||||
|
||||
/**
|
||||
* Adempiere Server Bean.
|
||||
|
@ -97,7 +99,9 @@ public class ServerBean implements ServerRemote, ServerLocal
|
|||
|
||||
m_postCount++;
|
||||
MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(ctx, AD_Client_ID);
|
||||
return Doc.postImmediate(ass, AD_Table_ID, Record_ID, force, null);
|
||||
if (! (Ini.isClient() && CConnection.isServerEmbedded()))
|
||||
trxName = null;
|
||||
return Doc.postImmediate(ass, AD_Table_ID, Record_ID, force, trxName);
|
||||
} // postImmediate
|
||||
|
||||
/*************************************************************************
|
||||
|
|
Loading…
Reference in New Issue