May be this could be analized too.
We have had problems with ASI with products that use guaranteedate.
then we create a function to verify if exists return the same m_attributesetinstance_ID
This is the function.
public static int getMAttributeSetInstanceId(int m_attrinuteset_id, String guarantedate){
int returnValue=0;
int VLSValue=0;
String consulta = "SELECT coalesce(max(at.m_attributesetinstance_id),0) as M_AttributeSetinstance_ID " +
" FROM ADEMPIERE.m_attributesetinstance at " +
" WHERE " +
" at.m_attributeset_id = " +m_attrinuteset_id+
" AND at.guaranteedate = '" +guarantedate+
"' AND at.ad_client_id = " + Env.getAD_Client_ID(Env.getCtx()) +
"AND at.isactive = 'Y' " ;
try {
PreparedStatement pstmt = DB.prepareStatement(consulta, null);
//pstmt.setInt(1, Env.getAD_Client_ID(Env.getCtx()));
ResultSet rs = pstmt.executeQuery();
//System.out.println("getMAtributeSetInstanceId: " + consulta);
while (rs.next()) {
VLSValue=rs.getInt("M_AttributeSetinstance_ID");
}
rs.close();
pstmt.close();
} catch (SQLException ex) {
Logger.getLogger(FLC_Utils.class.getName()).log(Level.SEVERE, null, ex);
}
if(VLSValue>0)
return VLSValue;
else
return returnValue;
}