BF [ 2025680 ] Import java.math in MHRProcess
* organized imports * more logging, useful for debugging rule engines * use MRole instead of X_AD_Rule * minor bug fixing
This commit is contained in:
parent
c6dbb8dc7a
commit
b1e41cdaf1
|
@ -15,18 +15,28 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.eevolution.model;
|
package org.eevolution.model;
|
||||||
|
|
||||||
import java.util.*;
|
import java.io.File;
|
||||||
import java.sql.*;
|
import java.math.BigDecimal;
|
||||||
import java.math.*;
|
import java.sql.PreparedStatement;
|
||||||
import java.util.logging.*;
|
import java.sql.ResultSet;
|
||||||
import java.io.*;
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.process.*;
|
import org.compiere.model.MBPartner;
|
||||||
import org.compiere.util.*;
|
import org.compiere.model.MDocType;
|
||||||
import org.compiere.model.*;
|
import org.compiere.model.MPeriod;
|
||||||
import org.compiere.wf.*;
|
import org.compiere.model.MRule;
|
||||||
import org.compiere.print.*;
|
import org.compiere.model.ModelValidationEngine;
|
||||||
import org.compiere.util.TimeUtil.*;
|
import org.compiere.model.ModelValidator;
|
||||||
|
import org.compiere.model.Scriptlet;
|
||||||
|
import org.compiere.print.ReportEngine;
|
||||||
|
import org.compiere.process.DocAction;
|
||||||
|
import org.compiere.process.DocumentEngine;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Order Model.
|
* Order Model.
|
||||||
|
@ -182,11 +192,7 @@ public class MHRProcess extends X_HR_Process implements DocAction {
|
||||||
org.compiere.model.MDocType dt = MDocType.get(getCtx(), getC_DocTypeTarget_ID());
|
org.compiere.model.MDocType dt = MDocType.get(getCtx(), getC_DocTypeTarget_ID());
|
||||||
|
|
||||||
// Std Period open?
|
// Std Period open?
|
||||||
if (!MPeriod.isOpen(getCtx(), period.getDateAcct(), dt.getDocBaseType()))
|
MPeriod.testPeriodOpen(getCtx(), period.getDateAcct(), dt.getDocBaseType()); // arhipac: teo_sarca
|
||||||
{
|
|
||||||
m_processMsg = "@PeriodClosed@";
|
|
||||||
return DocAction.STATUS_Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// New or in Progress/Invalid
|
// New or in Progress/Invalid
|
||||||
if (DOCSTATUS_Drafted.equals(getDocStatus()) || DOCSTATUS_InProgress.equals(getDocStatus())
|
if (DOCSTATUS_Drafted.equals(getDocStatus()) || DOCSTATUS_InProgress.equals(getDocStatus())
|
||||||
|
@ -259,7 +265,10 @@ public class MHRProcess extends X_HR_Process implements DocAction {
|
||||||
|
|
||||||
m_attribute = DB.getSQLValue(get_TrxName(),attSql);
|
m_attribute = DB.getSQLValue(get_TrxName(),attSql);
|
||||||
if (m_attribute < 0 || concept.isRegistered())
|
if (m_attribute < 0 || concept.isRegistered())
|
||||||
|
{
|
||||||
|
log.info("Skip concept "+concept+" - attribute not found");
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
X_HR_Attribute att = new X_HR_Attribute(Env.getCtx(),m_attribute,get_TrxName());
|
X_HR_Attribute att = new X_HR_Attribute(Env.getCtx(),m_attribute,get_TrxName());
|
||||||
|
|
||||||
if(!concept.getType().equals("E")) // Not Rule Engine - Only put HashTable
|
if(!concept.getType().equals("E")) // Not Rule Engine - Only put HashTable
|
||||||
|
@ -288,23 +297,30 @@ public class MHRProcess extends X_HR_Process implements DocAction {
|
||||||
}
|
}
|
||||||
else // Rule Engine, Process and put HashTable
|
else // Rule Engine, Process and put HashTable
|
||||||
{
|
{
|
||||||
X_AD_Rule rulee = new X_AD_Rule(Env.getCtx(),att.getAD_Rule_ID(),get_TrxName());
|
MRule rulee = MRule.get(getCtx(), att.getAD_Rule_ID());
|
||||||
Object result = null;
|
Object result = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String text = "";
|
String text = "";
|
||||||
if(rulee.getScript() != null)
|
if(rulee.getScript() != null)
|
||||||
text = rulee.getScript().trim().replace("get", "org.eevolution.model.MHRProcess.get");
|
text = rulee.getScript().trim().replace("get", "org.eevolution.model.MHRProcess.get");
|
||||||
String execute = (" import org.compiere.util.DB; import java.sql.*; double result = 0;"+ text);
|
String execute =
|
||||||
|
" import org.compiere.util.DB;"
|
||||||
|
+" import java.math.*;"
|
||||||
|
+" import java.sql.*;"
|
||||||
|
+" double result = 0;"
|
||||||
|
+ text;
|
||||||
Scriptlet m_script = new Scriptlet (Scriptlet.VARIABLE, ";", Env.getCtx(), 0);
|
Scriptlet m_script = new Scriptlet (Scriptlet.VARIABLE, ";", Env.getCtx(), 0);
|
||||||
m_script.setScript(execute);
|
m_script.setScript(execute);
|
||||||
m_script.execute();
|
Exception ex = m_script.execute();
|
||||||
|
if (ex != null)
|
||||||
|
throw ex;
|
||||||
result = m_script.getResult(false);
|
result = m_script.getResult(false);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
m_processMsg = e.toString();
|
m_processMsg = e.toString() + ", @AD_Rule_ID@="+rulee.getValue();
|
||||||
return DocAction.STATUS_Invalid;
|
return DocAction.STATUS_Invalid;
|
||||||
}
|
}
|
||||||
if(result.toString() == null)
|
if(result == null)
|
||||||
{
|
{
|
||||||
System.err.println("Esta cosa esta NULL");
|
System.err.println("Esta cosa esta NULL");
|
||||||
continue;
|
continue;
|
||||||
|
@ -357,6 +373,10 @@ public class MHRProcess extends X_HR_Process implements DocAction {
|
||||||
if (!m.save())
|
if (!m.save())
|
||||||
throw new IllegalStateException("Could not create HR Movement");
|
throw new IllegalStateException("Could not create HR Movement");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log.fine("Skip saving "+m);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // employee
|
} // employee
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue