IDEMPIERE-1208 Add API for execution of document action workflow.

This commit is contained in:
Heng Sin Low 2013-07-29 17:26:03 +08:00
parent d70244f8bc
commit 87dba26de2
3 changed files with 40 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import org.compiere.model.PO;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Ini;
@ -140,6 +141,8 @@ public class ProcessInfo implements Serializable
/** Row count */
private int m_rowCount;
private transient PO m_po = null;
/**
* String representation
* @return String representation
@ -773,4 +776,11 @@ public class ProcessInfo implements Serializable
return m_rowCount;
}
public void setPO(PO po) {
m_po = po;
}
public PO getPO() {
return m_po;
}
} // ProcessInfo

View File

@ -108,6 +108,8 @@ public class MWFProcess extends X_AD_WF_Process
// Document
setAD_Table_ID(wf.getAD_Table_ID());
setRecord_ID(pi.getRecord_ID());
if (pi.getPO() != null)
m_po = pi.getPO();
if (getPO() == null)
{
setTextMsg("No PO with ID=" + pi.getRecord_ID());

View File

@ -27,11 +27,16 @@ import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.exceptions.DBException;
import org.compiere.model.MColumn;
import org.compiere.model.MMenu;
import org.compiere.model.MProduct;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Workflow;
import org.compiere.process.DocAction;
import org.compiere.process.ProcessInfo;
import org.compiere.process.ServerProcessCtl;
import org.compiere.process.StateEngine;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
@ -951,4 +956,27 @@ public class MWorkflow extends X_AD_Workflow
return true;
}
/**
*
* @param po
* @param docAction
* @return ProcessInfo
*/
public static ProcessInfo runDocumentActionWorkflow(PO po, String docAction)
{
int AD_Table_ID = po.get_Table_ID();
MTable table = MTable.get(Env.getCtx(), AD_Table_ID);
MColumn column = table.getColumn("DocAction");
if (column == null)
return null;
if (!docAction.equals(po.get_Value(column.getColumnName())))
{
po.set_ValueOfColumn(column.getColumnName(), docAction);
}
ProcessInfo processInfo = new ProcessInfo (((DocAction)po).getDocumentInfo(),column.getAD_Process_ID(),po.get_Table_ID(),po.get_ID());
processInfo.setTransactionName(po.get_TrxName());
processInfo.setPO(po);
ServerProcessCtl.process(processInfo, Trx.get(processInfo.getTransactionName(), false));
return processInfo;
}
} // MWorkflow_ID