Search in sources :

Example 16 with MAttributeSet

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

the class VPAttributeDialog method saveSelection.

//	cmd_zoom
/**
	 *	Save Selection
	 *	@return true if saved
	 */
private boolean saveSelection() {
    if (!m_readWrite)
        return true;
    log.info("");
    MAttributeSet as = m_masi.getMAttributeSet();
    if (as == null)
        return true;
    //
    m_changed = false;
    String mandatory = "";
    if ((!m_productWindow || !m_productASI) && as.isLot()) {
        log.fine("Lot=" + fieldLotString.getText());
        String text = fieldLotString.getText();
        m_masi.setLot(text);
        if (as.isLotMandatory() && (text == null || text.length() == 0))
            mandatory += " - " + Msg.translate(Env.getCtx(), "Lot");
        m_changed = true;
    }
    //	Lot
    if ((!m_productWindow || !m_productASI) && as.isSerNo()) {
        log.fine("SerNo=" + fieldSerNo.getText());
        String text = fieldSerNo.getText();
        m_masi.setSerNo(text);
        if (as.isSerNoMandatory() && (text == null || text.length() == 0))
            mandatory += " - " + Msg.translate(Env.getCtx(), "SerNo");
        m_changed = true;
    }
    //	SerNo
    if ((!m_productWindow || !m_productASI) && as.isGuaranteeDate()) {
        log.fine("GuaranteeDate=" + fieldGuaranteeDate.getValue());
        Timestamp ts = (Timestamp) fieldGuaranteeDate.getValue();
        m_masi.setGuaranteeDate(ts);
        if (as.isGuaranteeDateMandatory() && ts == null)
            mandatory += " - " + Msg.translate(Env.getCtx(), "GuaranteeDate");
        m_changed = true;
    }
    //	New Instance
    if (m_changed || m_masi.getM_AttributeSetInstance_ID() == 0) {
        m_masi.save();
        m_M_AttributeSetInstance_ID = m_masi.getM_AttributeSetInstance_ID();
        m_M_AttributeSetInstanceName = m_masi.getDescription();
    }
    //  Save attributes
    if (m_M_AttributeSetInstance_ID > 0 && m_readWrite) {
        //	Save Instance Attributes
        MAttribute[] attributes = as.getMAttributes(!m_productASI);
        for (int i = 0; i < attributes.length; i++) {
            if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attributes[i].getAttributeValueType())) {
                CComboBox editor = (CComboBox) m_editors.get(i);
                MAttributeValue value = (MAttributeValue) editor.getSelectedItem();
                log.fine(attributes[i].getName() + "=" + value);
                if (attributes[i].isMandatory() && value == null)
                    mandatory += " - " + attributes[i].getName();
                attributes[i].setMAttributeInstance(m_M_AttributeSetInstance_ID, value);
            } else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributes[i].getAttributeValueType())) {
                VNumber editor = (VNumber) m_editors.get(i);
                BigDecimal value = (BigDecimal) editor.getValue();
                log.fine(attributes[i].getName() + "=" + value);
                if (attributes[i].isMandatory() && value == null)
                    mandatory += " - " + attributes[i].getName();
                //setMAttributeInstance doesn't work without decimal point
                if (value != null && value.scale() == 0)
                    value = value.setScale(1, BigDecimal.ROUND_HALF_UP);
                attributes[i].setMAttributeInstance(m_M_AttributeSetInstance_ID, value);
            } else {
                VString editor = (VString) m_editors.get(i);
                String value = editor.getText();
                log.fine(attributes[i].getName() + "=" + value);
                if (attributes[i].isMandatory() && (value == null || value.length() == 0))
                    mandatory += " - " + attributes[i].getName();
                attributes[i].setMAttributeInstance(m_M_AttributeSetInstance_ID, value);
            }
        }
        m_changed = true;
    }
    //	Save Model
    if (m_changed) {
        m_masi.setDescription();
        m_masi.save();
    }
    m_M_AttributeSetInstance_ID = m_masi.getM_AttributeSetInstance_ID();
    m_M_AttributeSetInstanceName = m_masi.getDescription();
    //
    if (mandatory.length() > 0) {
        ADialog.error(m_WindowNo, this, "FillMandatory", mandatory);
        return false;
    }
    return true;
}
Also used : CComboBox(org.compiere.swing.CComboBox) MAttributeValue(org.compiere.model.MAttributeValue) Timestamp(java.sql.Timestamp) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) BigDecimal(java.math.BigDecimal) MAttributeSet(org.compiere.model.MAttributeSet) MAttribute(org.compiere.model.MAttribute)

Example 17 with MAttributeSet

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

the class ExpressReceiptScanBar method isSerNo.

public boolean isSerNo() {
    if (isSerNo == null) {
        MAttributeSet attributeUse = null;
        if (product.getM_AttributeSet_ID() > 0) {
            attributeUse = (MAttributeSet) product.getM_AttributeSet();
            isSerNo = attributeUse.isSerNo();
            isSerNoMandotory = attributeUse.isSerNoMandatory();
        } else
            isSerNo = false;
    }
    return isSerNo;
}
Also used : MAttributeSet(org.compiere.model.MAttributeSet)

Example 18 with MAttributeSet

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

the class WPAttributeEditor method cmd_dialog.

/**
	 *  Start dialog
	 */
private void cmd_dialog() {
    //
    Integer oldValue = 0;
    try {
        oldValue = (Integer) getValue();
    } catch (Exception npe) {
    // Possible Invalid Cast exception if getValue() return new instance of Object.
    }
    int oldValueInt = oldValue == null ? 0 : oldValue.intValue();
    int M_AttributeSetInstance_ID = oldValueInt;
    int M_Product_ID = 0;
    int M_ProductBOM_ID = 0;
    if (m_GridTab != null) {
        M_Product_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, m_GridTab.getTabNo(), "M_Product_ID");
        M_ProductBOM_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, m_GridTab.getTabNo(), "M_ProductBOM_ID");
    } else {
        M_Product_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_Product_ID");
        M_ProductBOM_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_ProductBOM_ID");
    }
    int M_Locator_ID = -1;
    log.config("M_Product_ID=" + M_Product_ID + "/" + M_ProductBOM_ID + ",M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID);
    //	M_Product.M_AttributeSetInstance_ID = 8418
    boolean productWindow = m_AD_Column_ID == MColumn.getColumn_ID(MProduct.Table_Name, MProduct.COLUMNNAME_M_AttributeSetInstance_ID);
    //	Exclude ability to enter ASI
    boolean exclude = true;
    if (M_Product_ID != 0) {
        MProduct product = MProduct.get(Env.getCtx(), M_Product_ID);
        int M_AttributeSet_ID = product.getM_AttributeSet_ID();
        if (M_AttributeSet_ID != 0) {
            MAttributeSet mas = MAttributeSet.get(Env.getCtx(), M_AttributeSet_ID);
            exclude = mas.excludeEntry(m_AD_Column_ID, Env.isSOTrx(Env.getCtx(), m_WindowNo));
        }
    }
    boolean changed = false;
    if (//	Use BOM Component
    M_ProductBOM_ID != 0)
        M_Product_ID = M_ProductBOM_ID;
    // If the VPAttribute component is in a dialog, use the search
    if (m_searchOnly) {
        // Determine if the component is associated with the InfoProduct window
        Component me = ((Component) this.component.getParent());
        while (me != null) {
            if (me instanceof InfoProductPanel)
                break;
            me = me.getParent();
        }
        //
        InfoPAttributePanel ia = new InfoPAttributePanel((Window) me);
        m_pAttributeWhere = ia.getWhereClause();
        String oldText = getComponent().getText();
        getComponent().setText(ia.getDisplay());
        String curText = getComponent().getText();
        //
        ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldText, curText);
        this.fireValueChange(changeEvent);
    } else {
        if (!productWindow && (M_Product_ID == 0 || exclude)) {
            changed = true;
            getComponent().setText(null);
            M_AttributeSetInstance_ID = 0;
        } else {
            WPAttributeDialog vad = new WPAttributeDialog(M_AttributeSetInstance_ID, M_Product_ID, m_C_BPartner_ID, productWindow, gridField.getAD_Column_ID(), m_WindowNo);
            if (vad.isChanged()) {
                getComponent().setText(vad.getM_AttributeSetInstanceName());
                M_AttributeSetInstance_ID = vad.getM_AttributeSetInstance_ID();
                if (m_GridTab != null && !productWindow && vad.getM_Locator_ID() > 0)
                    m_GridTab.setValue("M_Locator_ID", vad.getM_Locator_ID());
                changed = true;
            }
        }
    }
    //	Set Value
    if (changed) {
        log.finest("Changed M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID);
        //	force re-query display
        m_value = new Object();
        if (M_AttributeSetInstance_ID == 0)
            setValue(null);
        else
            setValue(new Integer(M_AttributeSetInstance_ID));
        // Change Locator
        if (m_GridTab != null && M_Locator_ID > 0) {
            log.finest("Change M_Locator_ID=" + M_Locator_ID);
            m_GridTab.setValue("M_Locator_ID", M_Locator_ID);
        }
        //
        String columnName = "M_AttributeSetInstance_ID";
        if (m_GridField != null) {
            columnName = m_GridField.getColumnName();
        }
        ValueChangeEvent vce = new ValueChangeEvent(this, columnName, new Object(), getValue());
        fireValueChange(vce);
        //
        if (M_AttributeSetInstance_ID == oldValueInt && m_GridTab != null && gridField != null) {
            //  force Change - user does not realize that embedded object is already saved.
            m_GridTab.processFieldChange(gridField);
        }
    }
//	change
}
Also used : MProduct(org.compiere.model.MProduct) WPAttributeDialog(org.adempiere.webui.window.WPAttributeDialog) InfoPAttributePanel(org.adempiere.webui.panel.InfoPAttributePanel) MAttributeSet(org.compiere.model.MAttributeSet) ValueChangeEvent(org.adempiere.exceptions.ValueChangeEvent) InfoProductPanel(org.adempiere.webui.panel.InfoProductPanel) Component(org.zkoss.zk.ui.Component)

Example 19 with MAttributeSet

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

the class InventoryCountCreate method createInventoryLine.

//	doIt
/**
	 * 	Create/Add to Inventory Line
	 *	@param M_Product_ID product
	 *	@param M_Locator_ID locator
	 *	@param M_AttributeSetInstance_ID asi
	 *	@param QtyOnHand qty
	 *	@param M_AttributeSet_ID as
	 *	@return lines added
	 */
private int createInventoryLine(int M_Locator_ID, int M_Product_ID, int M_AttributeSetInstance_ID, BigDecimal QtyOnHand, int M_AttributeSet_ID) {
    boolean oneLinePerASI = false;
    if (M_AttributeSet_ID != 0) {
        MAttributeSet mas = MAttributeSet.get(getCtx(), M_AttributeSet_ID);
        oneLinePerASI = mas.isInstanceAttribute();
    }
    if (oneLinePerASI) {
        MInventoryLine line = new MInventoryLine(m_inventory, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, QtyOnHand, //	book/count
        QtyOnHand);
        if (line.save())
            return 1;
        return 0;
    }
    if (QtyOnHand.signum() == 0)
        M_AttributeSetInstance_ID = 0;
    if (m_line != null && m_line.getM_Locator_ID() == M_Locator_ID && m_line.getM_Product_ID() == M_Product_ID) {
        if (QtyOnHand.signum() == 0)
            return 0;
        //	Same ASI (usually 0)
        if (m_line.getM_AttributeSetInstance_ID() == M_AttributeSetInstance_ID) {
            m_line.setQtyBook(m_line.getQtyBook().add(QtyOnHand));
            m_line.setQtyCount(m_line.getQtyCount().add(QtyOnHand));
            m_line.saveEx();
            return 0;
        } else //	Save Old Line info
        if (m_line.getM_AttributeSetInstance_ID() != 0) {
            MInventoryLineMA ma = new MInventoryLineMA(m_line, m_line.getM_AttributeSetInstance_ID(), m_line.getQtyBook());
            if (!ma.save())
                ;
        }
        m_line.setM_AttributeSetInstance_ID(0);
        m_line.setQtyBook(m_line.getQtyBook().add(QtyOnHand));
        m_line.setQtyCount(m_line.getQtyCount().add(QtyOnHand));
        m_line.saveEx();
        //
        MInventoryLineMA ma = new MInventoryLineMA(m_line, M_AttributeSetInstance_ID, QtyOnHand);
        if (!ma.save())
            ;
        return 0;
    }
    //	new line
    m_line = new MInventoryLine(m_inventory, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, QtyOnHand, //	book/count
    QtyOnHand);
    if (m_line.save())
        return 1;
    return 0;
}
Also used : MInventoryLineMA(org.compiere.model.MInventoryLineMA) MInventoryLine(org.compiere.model.MInventoryLine) MAttributeSet(org.compiere.model.MAttributeSet)

Example 20 with MAttributeSet

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

the class ImportProductASI method getAttributeSet.

private MAttributeSet getAttributeSet(X_I_Product_ASI ip_asi) {
    MAttributeSet attributeSet = new MAttributeSet(getCtx(), ip_asi.getM_AttributeSet_ID(), get_TrxName());
    if (attributeSet == null || attributeSet.get_ID() <= 0) {
        attributeSet = new MAttributeSet(ip_asi.getCtx(), 0, ip_asi.get_TrxName());
        attributeSet.setName(ip_asi.getAttributeSetName());
        attributeSet.setIsLot(ip_asi.isLot());
        attributeSet.setIsLotMandatory(ip_asi.isLotMandatory());
        attributeSet.setIsGuaranteeDate(ip_asi.isGuaranteeDate());
        attributeSet.setIsGuaranteeDateMandatory(ip_asi.isGuaranteeDateMandatory());
        attributeSet.setGuaranteeDays(ip_asi.getGuaranteeDays());
        attributeSet.setMandatoryType(ip_asi.getMandatoryType());
        attributeSet.saveEx();
    }
    return attributeSet;
}
Also used : MAttributeSet(org.compiere.model.MAttributeSet)

Aggregations

MAttributeSet (org.compiere.model.MAttributeSet)22 BigDecimal (java.math.BigDecimal)7 MAttribute (org.compiere.model.MAttribute)7 MProduct (org.compiere.model.MProduct)6 MAttributeSetInstance (org.compiere.model.MAttributeSetInstance)5 Listbox (org.adempiere.webui.component.Listbox)4 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)4 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 Timestamp (java.sql.Timestamp)3 Row (org.adempiere.webui.component.Row)3 MAttributeInstance (org.compiere.model.MAttributeInstance)3 MAttributeValue (org.compiere.model.MAttributeValue)3 KeyNamePair (org.compiere.util.KeyNamePair)3 Dimension (java.awt.Dimension)2 Label (org.adempiere.webui.component.Label)2 ListItem (org.adempiere.webui.component.ListItem)2 NumberBox (org.adempiere.webui.component.NumberBox)2 VComboBox (org.compiere.grid.ed.VComboBox)2 VString (org.compiere.grid.ed.VString)2