use of org.compiere.model.MAttributeInstance in project adempiere by adempiere.
the class HTMLMessenger method getAttributeSetInstanceInfo.
public String getAttributeSetInstanceInfo(MAttributeSetInstance asi, boolean singleRow) {
MAttributeSet as = new MAttributeSet(Env.getCtx(), asi.getM_AttributeSet_ID(), null);
StorageReasoner mr = new StorageReasoner();
int[] ids = mr.getAttributeIDs(asi);
MAttributeInstance ai = null;
MAttribute a = null;
MAttributeValue av = null;
StringBuffer sb = new StringBuffer();
String value = null;
Object[] obj = null;
for (int i = 0; i < ids.length; i++) {
ai = new MAttributeInstance(Env.getCtx(), ids[i], asi.get_ID(), (String) null, null);
ai.load(null);
a = new MAttribute(Env.getCtx(), ai.getM_Attribute_ID(), null);
av = new MAttributeValue(Env.getCtx(), ai.getM_AttributeValue_ID(), null);
// e.g. the list validation type 'L'
if (ai.getValue() == null) {
value = av.getValue();
} else // Takes the value of the M_AttributeInstance itself
{
// Round number values to a scale of 2, if type is 'N'
if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(a.getAttributeValueType())) {
BigDecimal number = ai.getValueNumber();
value = number.setScale(2, BigDecimal.ROUND_HALF_UP).toString();
} else {
value = ai.getValue();
}
}
obj = new Object[] { a.getName(), value };
sb.append(MessageFormat.format(ATTRIBUTE_INFO_PATTERN, obj));
if (singleRow) {
sb.append(" ");
} else {
sb.append("<br>");
}
}
return sb.toString();
}
use of org.compiere.model.MAttributeInstance in project adempiere by adempiere.
the class ImportProductASI method importProductASI.
/**
* Import Product ASI using X_I_Product_ASI table
*
* @param X_I_Product_ASI
* Product ASI
* @return Attribute Instance
* @throws SQLException
*/
private MAttributeInstance importProductASI(X_I_Product_ASI ip_asi) throws SQLException {
MProduct product = (MProduct) ip_asi.getM_Product();
MAttributeSet attributeSet = null;
if (ip_asi.getM_AttributeSet_ID() <= 0) {
attributeSet = getAttributeSet(ip_asi);
product.setM_AttributeSet_ID(attributeSet.get_ID());
product.saveEx();
ip_asi.setM_AttributeSet_ID(attributeSet.getM_AttributeSet_ID());
ip_asi.saveEx();
} else {
attributeSet = (MAttributeSet) product.getM_AttributeSet();
}
// Attribute
MAttribute attribute = null;
if (ip_asi.getM_Attribute_ID() <= 0) {
attribute = getAttribute(ip_asi);
ip_asi.setM_Attribute_ID(attribute.getM_Attribute_ID());
ip_asi.saveEx();
} else
attribute = (MAttribute) ip_asi.getM_Attribute();
// Check Attribute in Attribute Set
checkAttributeUse(attributeSet, attribute);
MAttributeSetInstance asi = (MAttributeSetInstance) product.getM_AttributeSetInstance();
if (asi == null || asi.get_ID() <= 0) {
asi = getAttributeSetInstance(product, attributeSet);
product.setM_AttributeSetInstance_ID(asi.get_ID());
product.saveEx();
ip_asi.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID());
ip_asi.saveEx();
}
MAttributeInstance ai = addAttributeLine(asi, attribute, ip_asi);
ip_asi.saveEx();
commitEx();
return ai;
}
use of org.compiere.model.MAttributeInstance in project adempiere by adempiere.
the class ImportProductASI method importRecords.
// doIt
/**
* import records using I_Product_ASI table
*
* @throws SQLException
*/
private void importRecords() throws SQLException {
for (X_I_Product_ASI ip_asi : getRecords(false, m_IsImportOnlyNoErrors)) {
isImported = false;
MAttributeInstance ai = importProductASI(ip_asi);
if (ai != null || ai.get_ID() > 0)
isImported = true;
if (isImported) {
ip_asi.setI_IsImported(true);
ip_asi.setProcessed(true);
ip_asi.setI_ErrorMsg("");
ip_asi.saveEx();
imported++;
ip_asi.saveEx();
} else {
ip_asi.setI_IsImported(false);
ip_asi.setProcessed(false);
ip_asi.saveEx();
notimported++;
}
}
}
Aggregations