Search in sources :

Example 6 with MAttribute

use of org.compiere.model.MAttribute in project adempiere by adempiere.

the class ImportProductASI method getAttribute.

private MAttribute getAttribute(X_I_Product_ASI ip_asi) {
    MAttribute attribute = null;
    int attributeId = getID(MAttribute.Table_Name, MAttribute.COLUMNNAME_Name + "=?", ip_asi.getAttributeName());
    if (attributeId <= 0) {
        attribute = new MAttribute(ip_asi.getCtx(), 0, ip_asi.get_TrxName());
        attribute.setName(ip_asi.getAttributeName());
        attribute.setIsMandatory(ip_asi.isMandatory());
        attribute.setAttributeValueType(ip_asi.getAttributeValueType());
        attribute.setIsMandatory(ip_asi.isMandatory());
        attribute.saveEx();
    } else {
        attribute = new MAttribute(getCtx(), attributeId, get_TrxName());
    }
    if (ip_asi.getAttributeSearchName() != null) {
        X_M_AttributeSearch attributeSearch = (X_M_AttributeSearch) getAttributeSearch(ip_asi);
        attribute.setM_AttributeSearch_ID(attributeSearch.get_ID());
        attribute.saveEx();
        ip_asi.setM_AttributeSearch_ID(attributeSearch.get_ID());
        ip_asi.saveEx();
    }
    if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(ip_asi.getAttributeValueType())) {
        getAttributeValue(attribute, ip_asi);
    }
    return attribute;
}
Also used : X_M_AttributeSearch(org.compiere.model.X_M_AttributeSearch) MAttribute(org.compiere.model.MAttribute)

Example 7 with MAttribute

use of org.compiere.model.MAttribute in project adempiere by adempiere.

the class MAttributeTest method testQuery.

public void testQuery() throws Exception {
    MAttribute attrib = new MAttribute(getCtx(), 100, getTrxName());
    MAttribute[] attbClient = MAttribute.getOfClient(getCtx(), true, true);
    assertTrue("atrributes must be true", attbClient.length > 0);
    MAttributeValue[] av = attrib.getMAttributeValues();
    assertTrue("atrributes must have values", av.length > 0);
    MAttributeInstance ai = attrib.getMAttributeInstance(100);
    assertTrue("atrributes must have values", ai.isActive());
}
Also used : MAttributeInstance(org.compiere.model.MAttributeInstance) MAttributeValue(org.compiere.model.MAttributeValue) MAttribute(org.compiere.model.MAttribute)

Example 8 with MAttribute

use of org.compiere.model.MAttribute 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 9 with MAttribute

use of org.compiere.model.MAttribute in project adempiere by adempiere.

the class StorageReasoner method equalAttributeInstanceValue.

public boolean equalAttributeInstanceValue(MAttributeInstance ai1, MAttributeInstance ai2) {
    if (ai1.getM_Attribute_ID() != ai2.getM_Attribute_ID()) {
        return false;
    }
    boolean equal = true;
    MAttribute a = new MAttribute(Env.getCtx(), ai1.getM_Attribute_ID(), null);
    if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(a.getAttributeValueType())) {
        if (ai1.getValue() == null) {
            equal = ai2.getValueNumber() == null;
        } else {
            equal = ai1.getValueNumber().compareTo(ai2.getValueNumber()) == 0;
        }
    } else if (MAttribute.ATTRIBUTEVALUETYPE_StringMax40.equals(a.getAttributeValueType())) {
        if (ai1.getValue() == null) {
            equal = ai2.getValue() == null;
        } else {
            equal = ai1.getValue().equals(ai2.getValue());
        }
    } else if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(a.getAttributeValueType())) {
        equal = ai1.getM_AttributeValue_ID() == ai2.getM_AttributeValue_ID();
    }
    return equal;
}
Also used : MAttribute(org.compiere.model.MAttribute)

Example 10 with MAttribute

use of org.compiere.model.MAttribute 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)

Aggregations

MAttribute (org.compiere.model.MAttribute)11 MAttributeSet (org.compiere.model.MAttributeSet)7 BigDecimal (java.math.BigDecimal)4 MAttributeInstance (org.compiere.model.MAttributeInstance)4 MAttributeSetInstance (org.compiere.model.MAttributeSetInstance)4 MAttributeValue (org.compiere.model.MAttributeValue)4 Timestamp (java.sql.Timestamp)2 ListItem (org.adempiere.webui.component.ListItem)2 Listbox (org.adempiere.webui.component.Listbox)2 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)2 CComboBox (org.compiere.swing.CComboBox)2 KeyNamePair (org.compiere.util.KeyNamePair)2 Dimension (java.awt.Dimension)1 Date (java.util.Date)1 Label (org.adempiere.webui.component.Label)1 NumberBox (org.adempiere.webui.component.NumberBox)1 Row (org.adempiere.webui.component.Row)1 Rows (org.adempiere.webui.component.Rows)1 Textbox (org.adempiere.webui.component.Textbox)1 MProduct (org.compiere.model.MProduct)1