From 361edea3187929e7fb3bb81c8785ceb5ea3ca826 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 2 Jul 2021 04:25:30 +0200 Subject: [PATCH] IDEMPIERE-4578 generic DocAction (#736) * IDEMPIERE-4578 generic DocAction * IDEMPIERE-4578 generic DocAction * IDEMPIERE-4578 generic DocAction Refactor generic docaction implementation to a separate delegate class. This should make it easier for any model class to implement the DocAction interface using the DocActionDelegate class. * IDEMPIERE-4578 generic DocAction add generic type support * IDEMPIERE-4578 generic DocAction generic type should implements DocAction * IDEMPIERE-4578 generic DocAction Co-authored-by: hengsin --- .../adempiere/model/DocActionDelegate.java | 540 ++++++++++++++++++ .../src/org/adempiere/model/GenericPO.java | 216 ++++++- .../src/org/compiere/model/PO.java | 24 +- .../src/org/compiere/process/DocAction.java | 32 +- 4 files changed, 806 insertions(+), 6 deletions(-) create mode 100644 org.adempiere.base/src/org/adempiere/model/DocActionDelegate.java diff --git a/org.adempiere.base/src/org/adempiere/model/DocActionDelegate.java b/org.adempiere.base/src/org/adempiere/model/DocActionDelegate.java new file mode 100644 index 0000000000..3c6a21cdf0 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/model/DocActionDelegate.java @@ -0,0 +1,540 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - Carlos Ruiz * + * - hengsin * + **********************************************************************/ +package org.adempiere.model; + +import java.io.File; +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.Properties; +import java.util.logging.Level; + +import org.adempiere.exceptions.AdempiereException; +import org.adempiere.exceptions.PeriodClosedException; +import org.compiere.model.MDocType; +import org.compiere.model.MPeriod; +import org.compiere.model.ModelValidationEngine; +import org.compiere.model.ModelValidator; +import org.compiere.model.PO; +import org.compiere.process.DocAction; +import org.compiere.process.DocumentEngine; +import org.compiere.util.CLogger; +import org.compiere.util.DB; +import org.compiere.util.TimeUtil; +import org.compiere.util.Util; + +/** + * + * @author hengsin + * + */ +public class DocActionDelegate implements DocAction { + + private T po; + /** Process Message */ + private String m_processMsg = null; + /** Just Prepared Flag */ + private boolean m_justPrepared = false; + + /** Logger */ + protected transient CLogger log = CLogger.getCLogger (getClass()); + + public DocActionDelegate(T po) { + this.po = po; + } + + @Override + public void setDocStatus(String DocStatus) { + po.columnExists(DOC_COLUMNNAME_DocStatus, true); + po.set_ValueOfColumn(DOC_COLUMNNAME_DocStatus, DocStatus); + } + + @Override + public String getDocStatus() { + po.columnExists(DOC_COLUMNNAME_DocStatus, true); + return (String)po.get_Value(DOC_COLUMNNAME_DocStatus); + } + + @Override + public boolean processIt(String action) { + m_processMsg = null; + DocumentEngine engine = new DocumentEngine (po, getDocStatus()); + return engine.processIt (action, getDocAction()); + } + + @Override + public boolean unlockIt() { + if (log.isLoggable(Level.INFO)) log.info("unlockIt - " + po.toString()); + setProcessing(false); + return true; + } + + @Override + public boolean invalidateIt() { + if (log.isLoggable(Level.INFO)) log.info("invalidateIt - " + po.toString()); + setDocAction(DocAction.ACTION_Prepare); + return true; + } + + @Override + public String prepareIt() { + if (log.isLoggable(Level.INFO)) log.info(po.toString()); + m_processMsg = ModelValidationEngine.get().fireDocValidate(po, ModelValidator.TIMING_BEFORE_PREPARE); + if (m_processMsg != null) + return DocAction.STATUS_Invalid; + + int doctype = -1; + if (po.columnExists(DOC_COLUMNNAME_C_DocTypeTarget_ID)) { + doctype = po.get_ValueAsInt(DOC_COLUMNNAME_C_DocTypeTarget_ID); + } else if (po.columnExists(DOC_COLUMNNAME_C_DocType_ID)) { + doctype = po.get_ValueAsInt(DOC_COLUMNNAME_C_DocType_ID); + } + Timestamp date = null; + if (po.columnExists(DOC_COLUMNNAME_DateAcct)) { + date = (Timestamp) po.get_Value(DOC_COLUMNNAME_DateAcct); + } else if (po.columnExists(DOC_COLUMNNAME_DateTrx)) { + date = (Timestamp) po.get_Value(DOC_COLUMNNAME_DateTrx); + } else { + date = TimeUtil.getDay(0); + } + if (doctype >= 0) { + MPeriod.testPeriodOpen(getCtx(), date, doctype, getAD_Org_ID()); + } + + m_processMsg = ModelValidationEngine.get().fireDocValidate(po, ModelValidator.TIMING_AFTER_PREPARE); + if (m_processMsg != null) + return DocAction.STATUS_Invalid; + + m_justPrepared = true; + if (!DocAction.ACTION_Complete.equals(getDocAction())) + setDocAction(DocAction.ACTION_Complete); + return DocAction.STATUS_InProgress; + } + + @Override + public boolean approveIt() { + if (log.isLoggable(Level.INFO)) log.info(po.toString()); + setIsApproved(true); + return true; + } + + @Override + public boolean rejectIt() { + if (log.isLoggable(Level.INFO)) log.info(po.toString()); + setIsApproved(false); + return true; + } + + @Override + public String completeIt() { + // Re-Check + if (!m_justPrepared) + { + String status = prepareIt(); + m_justPrepared = false; + if (!DocAction.STATUS_InProgress.equals(status)) + return status; + } + + if ( po.columnExists(DOC_COLUMNNAME_C_DocTypeTarget_ID) + && po.columnExists(DOC_COLUMNNAME_C_DocType_ID)) { + po.set_ValueOfColumn(DOC_COLUMNNAME_C_DocType_ID, po.get_ValueAsInt(DOC_COLUMNNAME_C_DocTypeTarget_ID)); + } + + // Set the definite document number after completed (if needed) + setDefiniteDocumentNo(); + + m_processMsg = ModelValidationEngine.get().fireDocValidate(po, ModelValidator.TIMING_BEFORE_COMPLETE); + if (m_processMsg != null) + return DocAction.STATUS_Invalid; + + // Implicit Approval + if (!isApproved()) + approveIt(); + if (log.isLoggable(Level.INFO)) log.info(po.toString()); + + // User Validation + String valid = ModelValidationEngine.get().fireDocValidate(po, ModelValidator.TIMING_AFTER_COMPLETE); + if (valid != null) + { + m_processMsg = valid; + return DocAction.STATUS_Invalid; + } + + setProcessed(true); + setDocAction(DocAction.ACTION_Close); + return DocAction.STATUS_Completed; + } + + @Override + public boolean voidIt() { + + if (log.isLoggable(Level.INFO)) log.info(po.toString()); + + if ( DocAction.STATUS_Closed.equals(getDocStatus()) + || DocAction.STATUS_Reversed.equals(getDocStatus()) + || DocAction.STATUS_Voided.equals(getDocStatus())) { + m_processMsg = "Document Closed: " + getDocStatus(); + setDocAction(DocAction.ACTION_None); + return false; + } + + // Not Processed + if ( DocAction.STATUS_Drafted.equals(getDocStatus()) + || DocAction.STATUS_Invalid.equals(getDocStatus()) + || DocAction.STATUS_InProgress.equals(getDocStatus()) + || DocAction.STATUS_Approved.equals(getDocStatus()) + || DocAction.STATUS_NotApproved.equals(getDocStatus())) { + // Before Void + m_processMsg = ModelValidationEngine.get().fireDocValidate(po,ModelValidator.TIMING_BEFORE_VOID); + if (m_processMsg != null) + return false; + } else { + boolean accrual = false; + int doctype = -1; + if (po.columnExists(DOC_COLUMNNAME_C_DocTypeTarget_ID)) { + doctype = po.get_ValueAsInt(DOC_COLUMNNAME_C_DocTypeTarget_ID); + } else if (po.columnExists(DOC_COLUMNNAME_C_DocType_ID)) { + doctype = po.get_ValueAsInt(DOC_COLUMNNAME_C_DocType_ID); + } + Timestamp date = null; + if (po.columnExists(DOC_COLUMNNAME_DateAcct)) { + date = (Timestamp) po.get_Value(DOC_COLUMNNAME_DateAcct); + } else if (po.columnExists(DOC_COLUMNNAME_DateTrx)) { + date = (Timestamp) po.get_Value(DOC_COLUMNNAME_DateTrx); + } else { + date = TimeUtil.getDay(0); + } + if (doctype >= 0) { + try { + MPeriod.testPeriodOpen(getCtx(), date, doctype, getAD_Org_ID()); + } catch (PeriodClosedException e) { + accrual = true; + } + } + + if (accrual) + return reverseAccrualIt(); + else + return reverseCorrectIt(); + } + + // After Void + m_processMsg = ModelValidationEngine.get().fireDocValidate(po,ModelValidator.TIMING_AFTER_VOID); + if (m_processMsg != null) + return false; + + setProcessed(true); + setDocAction(DocAction.ACTION_None); + return true; + } + + @Override + public boolean closeIt() { + if (log.isLoggable(Level.INFO)) log.info(po.toString()); + // Before Close + m_processMsg = ModelValidationEngine.get().fireDocValidate(po,ModelValidator.TIMING_BEFORE_CLOSE); + if (m_processMsg != null) + return false; + + setProcessed(true); + setDocAction(DocAction.ACTION_None); + + // After Close + m_processMsg = ModelValidationEngine.get().fireDocValidate(po,ModelValidator.TIMING_AFTER_CLOSE); + if (m_processMsg != null) + return false; + return true; + } + + @Override + public boolean reverseCorrectIt() { + if (log.isLoggable(Level.INFO)) log.info(po.toString()); + // Before reverseCorrect + m_processMsg = ModelValidationEngine.get().fireDocValidate(po,ModelValidator.TIMING_BEFORE_REVERSECORRECT); + if (m_processMsg != null) + return false; + + // After reverseCorrect + m_processMsg = ModelValidationEngine.get().fireDocValidate(po,ModelValidator.TIMING_AFTER_REVERSECORRECT); + if (m_processMsg != null) + return false; + + return false; // reverse needs to be implemented to create a negative document + } + + @Override + public boolean reverseAccrualIt() { + if (log.isLoggable(Level.INFO)) log.info(po.toString()); + // Before reverseAccrual + m_processMsg = ModelValidationEngine.get().fireDocValidate(po,ModelValidator.TIMING_BEFORE_REVERSEACCRUAL); + if (m_processMsg != null) + return false; + + // After reverseAccrual + m_processMsg = ModelValidationEngine.get().fireDocValidate(po,ModelValidator.TIMING_AFTER_REVERSEACCRUAL); + if (m_processMsg != null) + return false; + + return false; // reverse needs to be implemented to create a negative document + } + + @Override + public boolean reActivateIt() { + if (log.isLoggable(Level.INFO)) log.info(po.toString()); + // Before reActivate + m_processMsg = ModelValidationEngine.get().fireDocValidate(po,ModelValidator.TIMING_BEFORE_REACTIVATE); + if (m_processMsg != null) + return false; + + // After reActivate + m_processMsg = ModelValidationEngine.get().fireDocValidate(po,ModelValidator.TIMING_AFTER_REACTIVATE); + if (m_processMsg != null) + return false; + + setDocAction(DocAction.ACTION_Complete); + setProcessed(false); + return false; // reactivate needs to be implemented to reverse the effect of complete and post + } + + @Override + public String getSummary() { + StringBuilder sb = new StringBuilder(); + sb.append(getDocumentNo()); + String description = null; + if (po.columnExists(DOC_COLUMNNAME_Description)) + description = po.get_ValueAsString(DOC_COLUMNNAME_Description); + if (!Util.isEmpty(description)) + sb.append(" - ").append(description); + return sb.toString(); + } + + @Override + public String getDocumentNo() { + if (po.columnExists(DOC_COLUMNNAME_DocumentNo)) { + return po.get_ValueAsString(DOC_COLUMNNAME_DocumentNo); + } + return null; + } + + @Override + public String getDocumentInfo() { + int doctype = -1; + if (po.columnExists(DOC_COLUMNNAME_C_DocTypeTarget_ID)) { + doctype = po.get_ValueAsInt(DOC_COLUMNNAME_C_DocTypeTarget_ID); + } else if (po.columnExists(DOC_COLUMNNAME_C_DocType_ID)) { + doctype = po.get_ValueAsInt(DOC_COLUMNNAME_C_DocType_ID); + } + MDocType dt = null; + if (doctype > 0) { + dt = MDocType.get(getCtx(), doctype); + } + StringBuilder msgreturn = new StringBuilder().append((dt != null ? dt.getNameTrl() : "")).append(" ").append(getDocumentNo()); + return msgreturn.toString(); + } + + @Override + public File createPDF() { + return null; + } + + @Override + public String getProcessMsg() { + return m_processMsg; + } + + @Override + public int getDoc_User_ID() { + int userid = 0; + if (po.columnExists(DOC_COLUMNNAME_SalesRep_ID)) { + userid = po.get_ValueAsInt(DOC_COLUMNNAME_SalesRep_ID); + } else if (po.columnExists(DOC_COLUMNNAME_AD_User_ID)) { + userid = po.get_ValueAsInt(DOC_COLUMNNAME_AD_User_ID); + } else { + userid = po.getCreatedBy(); + } + return userid; + } + + @Override + public int getC_Currency_ID() { + int currency = 0; + if (po.columnExists(DOC_COLUMNNAME_C_Currency_ID)) { + currency = po.get_ValueAsInt(DOC_COLUMNNAME_C_Currency_ID); + } + return currency; + } + + @Override + public BigDecimal getApprovalAmt() { + return null; + } + + @Override + public int getAD_Client_ID() { + return po.getAD_Client_ID(); + } + + @Override + public int getAD_Org_ID() { + return po.getAD_Org_ID(); + } + + @Override + public String getDocAction() { + po.columnExists(DOC_COLUMNNAME_DocAction, true); + return (String)po.get_Value(DOC_COLUMNNAME_DocAction); + } + + @Override + public boolean save() { + return po.save(); + } + + @Override + public void saveEx() throws AdempiereException { + po.saveEx(); + } + + @Override + public Properties getCtx() { + return po.getCtx(); + } + + @Override + public int get_ID() { + return po.get_ID(); + } + + @Override + public int get_Table_ID() { + return po.get_Table_ID(); + } + + @Override + public CLogger get_Logger() { + return po.get_Logger(); + } + + @Override + public String get_TrxName() { + return po.get_TrxName(); + } + + /** + * Set Document Action. + * @param DocAction The targeted status of the document + */ + public void setDocAction (String DocAction) { + po.columnExists(DOC_COLUMNNAME_DocAction, true); + po.set_ValueOfColumn(DOC_COLUMNNAME_DocAction, DocAction); + } + + /** + * Set Processing Now. + * @param Processing Process Now + */ + public void setProcessing (boolean Processing) + { + po.columnExists(DOC_COLUMNNAME_Processing, true); + po.set_ValueOfColumn(DOC_COLUMNNAME_Processing, Boolean.valueOf(Processing)); + } + + /** + * Set Processed. + * @param Processed The document has been processed + */ + public void setProcessed (boolean Processed) { + po.columnExists(DOC_COLUMNNAME_Processed, true); + po.set_ValueNoCheck (DOC_COLUMNNAME_Processed, Boolean.valueOf(Processed)); + } + + /** + * Get Approved. + * @return Indicates if this document requires approval + */ + public boolean isApproved() { + if (po.columnExists(DOC_COLUMNNAME_IsApproved)) { + Object oo = po.get_Value(DOC_COLUMNNAME_IsApproved); + if (oo != null) { + if (oo instanceof Boolean) + return ((Boolean)oo).booleanValue(); + return "Y".equals(oo); + } + } + return true; + } + + /** + * Set Approved. + * @param IsApproved Indicates if this document requires approval + */ + public void setIsApproved (boolean IsApproved) { + po.columnExists(DOC_COLUMNNAME_IsApproved, true); + po.set_ValueNoCheck (DOC_COLUMNNAME_IsApproved, Boolean.valueOf(IsApproved)); + } + + /** + * Set the definite document number after completed + */ + private void setDefiniteDocumentNo() { + int doctype = -1; + if (po.columnExists(DOC_COLUMNNAME_C_DocType_ID)) { + doctype = po.get_ValueAsInt(DOC_COLUMNNAME_C_DocType_ID); + } + Timestamp dateacct = null; + if (po.columnExists(DOC_COLUMNNAME_DateAcct)) { + dateacct = (Timestamp) po.get_Value(DOC_COLUMNNAME_DateAcct); + } + Timestamp datetrx = null; + if (po.columnExists(DOC_COLUMNNAME_DateTrx)) { + datetrx = (Timestamp) po.get_Value(DOC_COLUMNNAME_DateTrx); + } + if (datetrx == null) { + datetrx = TimeUtil.getDay(0); + } + if (doctype >= 0) { + MPeriod.testPeriodOpen(getCtx(), (dateacct != null ? dateacct : datetrx), doctype, getAD_Org_ID()); + MDocType dt = MDocType.get(doctype); + if (dt.isOverwriteDateOnComplete()) { + if (po.columnExists(DOC_COLUMNNAME_DateTrx)) { + po.set_ValueOfColumn(DOC_COLUMNNAME_DateTrx, TimeUtil.getDay(0)); + } + if (dateacct != null && dateacct.before(datetrx)) { + po.set_ValueOfColumn(DOC_COLUMNNAME_DateAcct, datetrx); + MPeriod.testPeriodOpen(getCtx(), datetrx, doctype, getAD_Org_ID()); + } + } + if (dt.isOverwriteSeqOnComplete()) { + if (po.columnExists(DOC_COLUMNNAME_DocumentNo)) { + String value = DB.getDocumentNo(doctype, get_TrxName(), true, po); + if (value != null) + po.set_ValueOfColumn(DOC_COLUMNNAME_DocumentNo, value); + } + } + } + + } +} diff --git a/org.adempiere.base/src/org/adempiere/model/GenericPO.java b/org.adempiere.base/src/org/adempiere/model/GenericPO.java index 97f397c529..33f40810e0 100644 --- a/org.adempiere.base/src/org/adempiere/model/GenericPO.java +++ b/org.adempiere.base/src/org/adempiere/model/GenericPO.java @@ -20,6 +20,8 @@ // Generic PO. package org.adempiere.model; +import java.io.File; +import java.math.BigDecimal; // import for GenericPO import java.sql.ResultSet; import java.util.Properties; @@ -27,6 +29,7 @@ import java.util.Properties; import org.compiere.model.MTable; import org.compiere.model.PO; import org.compiere.model.POInfo; +import org.compiere.process.DocAction; /** * Generic PO implementation, this can be use together with ModelValidator as alternative to the classic @@ -36,13 +39,14 @@ import org.compiere.model.POInfo; * @author Marco LOMBARDO * @contributor Low Heng Sin */ -public class GenericPO extends PO { - +public class GenericPO extends PO implements DocAction { /** * */ - private static final long serialVersionUID = -6558017105997010172L; - + private static final long serialVersionUID = 3180937588404433030L; + + private DocActionDelegate docActionDelegate = new DocActionDelegate<>(this); + /** * @param tableName * @param ctx @@ -132,6 +136,210 @@ public class GenericPO extends PO { return Integer.parseInt(p_info.getAccessLevel()); } + + + /* METHODS TO USE GenericPO in Documents */ + + /** + * Set Document Status. + * @param DocStatus The current status of the document + */ + @Override + public void setDocStatus(String DocStatus) { + docActionDelegate.setDocStatus(DocStatus); + } + + /** + * Get Document Status. + * @return The current status of the document + */ + @Override + public String getDocStatus() { + return docActionDelegate.getDocStatus(); + } + + /************************************************************************** + * Process document + * @param processAction document action + * @return true if performed + */ + @Override + public boolean processIt (String processAction) { + return docActionDelegate.processIt(processAction); + } // process + + /** + * Unlock Document. + * @return true if success + */ + @Override + public boolean unlockIt() + { + return docActionDelegate.unlockIt(); + } // unlockIt + + /** + * Get Document Action. + * @return The targeted status of the document + */ + @Override + public String getDocAction() { + return docActionDelegate.getDocAction(); + } + + /** + * Invalidate Document + * @return true if success + */ + @Override + public boolean invalidateIt() + { + return docActionDelegate.invalidateIt(); + } // invalidateIt + + /** + * Prepare Document + * @return new status (In Progress or Invalid) + */ + @Override + public String prepareIt() { + return docActionDelegate.prepareIt(); + } // prepareIt + + /** + * Approve Document + * @return true if success + */ + @Override + public boolean approveIt() { + return docActionDelegate.approveIt(); + } // approveIt + + /** + * Reject Approval + * @return true if success + */ + @Override + public boolean rejectIt() { + return docActionDelegate.rejectIt(); + } // rejectIt + + /** + * Complete Document + * @return new status (Complete, In Progress, Invalid, Waiting ..) + */ + @Override + public String completeIt() { + return docActionDelegate.completeIt(); + } // completeIt + + /** + * Void Document. + * @return true if success + */ + @Override + public boolean voidIt() + { + return docActionDelegate.voidIt(); + } // voidIt + + /** + * Close Document. + * @return true if success + */ + @Override + public boolean closeIt() + { + return docActionDelegate.closeIt(); + } // closeIt + + /** + * Reverse Correction - same date + * @return true if success + */ + @Override + public boolean reverseCorrectIt() + { + return docActionDelegate.reverseCorrectIt(); + } // reverseCorrectIt + + /** + * Reverse Accrual - none + * @return false + */ + @Override + public boolean reverseAccrualIt() + { + return docActionDelegate.reverseAccrualIt(); + } // reverseAccrualIt + + /** + * Re-activate. + * @return true if success + */ + @Override + public boolean reActivateIt() + { + return docActionDelegate.reActivateIt(); + } // reActivateIt + + /************************************************************************* + * Get Summary + * @return Summary of Document + */ + @Override + public String getSummary() { + return docActionDelegate.getSummary(); + } // getSummary + + @Override + public String getDocumentNo() { + return docActionDelegate.getDocumentNo(); + } + + /** + * Get Document Info + * @return document info (untranslated) + */ + @Override + public String getDocumentInfo() { + return docActionDelegate.getDocumentInfo(); + } // getDocumentInfo + + @Override + public File createPDF() { + return docActionDelegate.createPDF(); + } + + /** + * Get Process Message + * @return clear text error message + */ + @Override + public String getProcessMsg() { + return docActionDelegate.getProcessMsg(); + } // getProcessMsg + + @Override + public int getDoc_User_ID() { + return docActionDelegate.getDoc_User_ID(); + } + + /** + * Get Currency. + * @return The Currency for this record + */ + @Override + public int getC_Currency_ID() { + return docActionDelegate.getC_Currency_ID(); + } + + + @Override + public BigDecimal getApprovalAmt() { + return docActionDelegate.getApprovalAmt(); + } + } // GenericPO /** diff --git a/org.adempiere.base/src/org/compiere/model/PO.java b/org.adempiere.base/src/org/compiere/model/PO.java index 052d21c115..d3ae39617b 100644 --- a/org.adempiere.base/src/org/compiere/model/PO.java +++ b/org.adempiere.base/src/org/compiere/model/PO.java @@ -112,7 +112,7 @@ public abstract class PO /** * */ - private static final long serialVersionUID = -6130455457377290526L; + private static final long serialVersionUID = 571979727987834997L; public static final String LOCAL_TRX_PREFIX = "POSave"; @@ -5174,4 +5174,26 @@ public abstract class PO return retValue; } + /** + * Verify if a column exists + * @param columnName + * @param throwException - must throw an exception when the column doesn't exist + * @return + */ + public boolean columnExists(String columnName, boolean throwException) { + int idx = get_ColumnIndex(columnName); + if (idx < 0 && throwException) + throw new AdempiereException("Column " + get_TableName() +"." + columnName + " not found"); + return (idx >= 0); + } + + /** + * Verify if a column exists + * @param columnName + * @return boolean + */ + public boolean columnExists(String columnName) { + return columnExists(columnName, false); + } + } // PO diff --git a/org.adempiere.base/src/org/compiere/process/DocAction.java b/org.adempiere.base/src/org/compiere/process/DocAction.java index 9f1ccd6c2f..7a497ad41e 100644 --- a/org.adempiere.base/src/org/compiere/process/DocAction.java +++ b/org.adempiere.base/src/org/compiere/process/DocAction.java @@ -90,7 +90,37 @@ public interface DocAction /** DocAction Ref_List values **/ public static final int AD_REFERENCE_ID = SystemIDs.REFERENCE_DOCUMENTACTION; - + + /* Common Document columns */ + /** Column name DocAction */ + public static final String DOC_COLUMNNAME_DocAction = "DocAction"; + /** Column name DocStatus */ + public static final String DOC_COLUMNNAME_DocStatus = "DocStatus"; + /** Column name Processing */ + public static final String DOC_COLUMNNAME_Processing = "Processing"; + /** Column name C_DocTypeTarget_ID */ + public static final String DOC_COLUMNNAME_C_DocTypeTarget_ID = "C_DocTypeTarget_ID"; + /** Column name C_DocType_ID */ + public static final String DOC_COLUMNNAME_C_DocType_ID = "C_DocType_ID"; + /** Column name DateAcct */ + public static final String DOC_COLUMNNAME_DateAcct = "DateAcct"; + /** Column name DateTrx */ + public static final String DOC_COLUMNNAME_DateTrx = "DateTrx"; + /** Column name IsApproved */ + public static final String DOC_COLUMNNAME_IsApproved = "IsApproved"; + /** Column name Processed */ + public static final String DOC_COLUMNNAME_Processed = "Processed"; + /** Column name DocumentNo */ + public static final String DOC_COLUMNNAME_DocumentNo = "DocumentNo"; + /** Column name Description */ + public static final String DOC_COLUMNNAME_Description = "Description"; + /** Column name SalesRep_ID */ + public static final String DOC_COLUMNNAME_SalesRep_ID = "SalesRep_ID"; + /** Column name AD_User_ID */ + public static final String DOC_COLUMNNAME_AD_User_ID = "AD_User_ID"; + /** Column name C_Currency_ID */ + public static final String DOC_COLUMNNAME_C_Currency_ID = "C_Currency_ID"; + /** * Set Doc Status * @param newStatus new Status