Search in sources :

Example 6 with MAttributeInstance

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("&nbsp;");
        } else {
            sb.append("<br>");
        }
    }
    return sb.toString();
}
Also used : MAttributeInstance(org.compiere.model.MAttributeInstance) MAttributeValue(org.compiere.model.MAttributeValue) StorageReasoner(org.eevolution.model.reasoner.StorageReasoner) BigDecimal(java.math.BigDecimal) MAttributeSet(org.compiere.model.MAttributeSet) MAttribute(org.compiere.model.MAttribute)

Example 7 with MAttributeInstance

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;
}
Also used : MProduct(org.compiere.model.MProduct) MAttributeInstance(org.compiere.model.MAttributeInstance) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) MAttributeSet(org.compiere.model.MAttributeSet) MAttribute(org.compiere.model.MAttribute)

Example 8 with MAttributeInstance

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++;
        }
    }
}
Also used : X_I_Product_ASI(org.eevolution.model.X_I_Product_ASI) MAttributeInstance(org.compiere.model.MAttributeInstance)

Aggregations

MAttributeInstance (org.compiere.model.MAttributeInstance)8 MAttributeValue (org.compiere.model.MAttributeValue)5 MAttribute (org.compiere.model.MAttribute)4 BigDecimal (java.math.BigDecimal)3 MAttributeSet (org.compiere.model.MAttributeSet)3 MAttributeSetInstance (org.compiere.model.MAttributeSetInstance)2 Font (java.awt.Font)1 Label (org.adempiere.webui.component.Label)1 ListItem (org.adempiere.webui.component.ListItem)1 Listbox (org.adempiere.webui.component.Listbox)1 NumberBox (org.adempiere.webui.component.NumberBox)1 Row (org.adempiere.webui.component.Row)1 Textbox (org.adempiere.webui.component.Textbox)1 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)1 MProduct (org.compiere.model.MProduct)1 CComboBox (org.compiere.swing.CComboBox)1 CLabel (org.compiere.swing.CLabel)1 X_I_Product_ASI (org.eevolution.model.X_I_Product_ASI)1 StorageReasoner (org.eevolution.model.reasoner.StorageReasoner)1