IDEMPIERE-3599 allow DocActions to be selected in a more flexible way

This commit is contained in:
Carlos Ruiz 2018-01-08 21:58:22 +01:00
parent 0e6ff739b3
commit 0ec3576fe2
5 changed files with 64 additions and 13 deletions

View File

@ -91,6 +91,9 @@ public interface IEventTopics {
public static final String PREF_AFTER_LOAD = "adempiere/pref/afterLoad";
/** Called after next document actions are set */
public static final String DOCACTION = "adempiere/docAction";
public static final String BROADCAST_MESSAGE = "idempiere/broadcastMsg";
public static final String REQUEST_SEND_EMAIL = "idempiere/requestSendEMail";

View File

@ -0,0 +1,33 @@
package org.compiere.process;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import org.compiere.model.PO;
public class DocActionEventData {
public String docStatus;
public Object processing;
public String orderType;
public String isSOTrx;
public int AD_Table_ID;
public ArrayList<String> docAction;
public ArrayList<String> options;
public AtomicInteger indexObj;
public PO po;
public DocActionEventData(String docStatus, Object processing, String orderType, String isSOTrx,
int AD_Table_ID, ArrayList<String> docAction, ArrayList<String> options, AtomicInteger indexObj, PO po) {
this.docStatus = docStatus;
this.processing = processing;
this.orderType = orderType;
this.isSOTrx = isSOTrx;
this.AD_Table_ID = AD_Table_ID;
this.docAction = docAction;
this.options = options;
this.indexObj = indexObj;
this.po = po;
}
}

View File

@ -22,9 +22,14 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import org.adempiere.base.event.EventManager;
import org.adempiere.base.event.EventProperty;
import org.adempiere.base.event.IEventTopics;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.acct.Doc;
import org.compiere.model.MAcctSchema;
@ -55,6 +60,7 @@ import org.eevolution.model.I_DD_Order;
import org.eevolution.model.I_HR_Process;
import org.eevolution.model.I_PP_Cost_Collector;
import org.eevolution.model.I_PP_Order;
import org.osgi.service.event.Event;
/**
* Document Action Engine
@ -907,7 +913,7 @@ public class DocumentEngine implements DocAction
* @return Number of valid options
*/
public static int getValidActions(String docStatus, Object processing,
String orderType, String isSOTrx, int AD_Table_ID, String[] docAction, String[] options, boolean periodOpen)
String orderType, String isSOTrx, int AD_Table_ID, String[] docAction, String[] options, boolean periodOpen, PO po)
{
if (options == null)
throw new IllegalArgumentException("Option array parameter is null");
@ -1214,6 +1220,25 @@ public class DocumentEngine implements DocAction
options[index++] = DocumentEngine.ACTION_Void;
}
}
if (po instanceof DocOptions)
index = ((DocOptions) po).customizeValidActions(docStatus, processing, orderType, isSOTrx,
AD_Table_ID, docAction, options, index);
AtomicInteger indexObj = new AtomicInteger(index);
ArrayList<String> docActionsArray = new ArrayList<String>(Arrays.asList(docAction));
ArrayList<String> optionsArray = new ArrayList<String>(Arrays.asList(options));
DocActionEventData eventData = new DocActionEventData(docStatus, processing, orderType, isSOTrx, AD_Table_ID, docActionsArray, optionsArray, indexObj, po);
Event event = EventManager.newEvent(IEventTopics.DOCACTION,
new EventProperty(EventManager.EVENT_DATA, eventData),
new EventProperty("tableName", po.get_TableName()));
EventManager.getInstance().sendEvent(event);
index = indexObj.get();
for (int i = 0; i < optionsArray.size(); i++)
options[i] = optionsArray.get(i);
for (int i = 0; i < docActionsArray.size(); i++)
docAction[i] = docActionsArray.get(i);
return index;
}

View File

@ -42,7 +42,6 @@ import org.compiere.model.MProduction;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.process.DocAction;
import org.compiere.process.DocOptions;
import org.compiere.process.DocumentEngine;
import org.compiere.swing.CComboBox;
import org.compiere.swing.CDialog;
@ -245,11 +244,7 @@ public class VDocAction extends CDialog
String[] docActionHolder = new String[] {DocAction};
index = DocumentEngine.getValidActions(DocStatus, Processing, OrderType, IsSOTrx, m_AD_Table_ID,
docActionHolder, options, periodOpen);
if (po instanceof DocOptions)
index = ((DocOptions) po).customizeValidActions(DocStatus, Processing, OrderType, IsSOTrx,
m_AD_Table_ID, docActionHolder, options, index);
docActionHolder, options, periodOpen, po);
Integer doctypeId = (Integer)m_mTab.getValue("C_DocType_ID");
if(doctypeId==null || doctypeId.intValue()==0){

View File

@ -46,7 +46,6 @@ import org.compiere.model.MProduction;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.process.DocAction;
import org.compiere.process.DocOptions;
import org.compiere.process.DocumentEngine;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
@ -172,11 +171,7 @@ public class WDocActionPanel extends Window implements EventListener<Event>, Dia
String[] docActionHolder = new String[]{DocAction};
index = DocumentEngine.getValidActions(DocStatus, Processing, OrderType, IsSOTrx,
m_AD_Table_ID, docActionHolder, options, periodOpen);
if (po instanceof DocOptions)
index = ((DocOptions) po).customizeValidActions(DocStatus, Processing, OrderType, IsSOTrx,
m_AD_Table_ID, docActionHolder, options, index);
m_AD_Table_ID, docActionHolder, options, periodOpen, po);
Integer doctypeId = (Integer)gridTab.getValue("C_DocTypeTarget_ID");
if(doctypeId==null || doctypeId.intValue()==0){