Search in sources :

Example 76 with MProduct

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

the class myJTree method addParent.

public void addParent(MProductBOM bom, DefaultMutableTreeNode parent) {
    MProduct M_Product = MProduct.get(getCtx(), bom.getM_Product_ID());
    Vector<Object> line = new Vector<Object>(17);
    //  0 Select
    line.add(new Boolean(false));
    //  1 IsActive
    line.add(new Boolean(M_Product.isActive()));
    // 2 Line
    line.add(new Integer(bom.getLine()));
    KeyNamePair pp = new KeyNamePair(M_Product.getM_Product_ID(), M_Product.getValue().concat("_").concat(M_Product.getName()));
    //  3 M_Product_ID
    line.add(pp);
    MUOM u = new MUOM(M_Product.getCtx(), M_Product.getC_UOM_ID(), M_Product.get_TrxName());
    KeyNamePair uom = new KeyNamePair(M_Product.getC_UOM_ID(), u.getUOMSymbol());
    //  6 C_UOM_ID
    line.add(uom);
    //  9 QtyBOM
    line.add((BigDecimal) ((bom.getBOMQty() != null) ? bom.getBOMQty() : new BigDecimal(0)));
    dataBOM.add(line);
    DefaultMutableTreeNode child = new DefaultMutableTreeNode(line);
    parent.add(child);
    if (reload)
        return;
    for (MProductBOM bomline : getParentBOMs(bom.getM_Product_ID())) {
        addParent(bomline, child);
    }
//dataBOM.add(line);
}
Also used : MProduct(org.compiere.model.MProduct) MUOM(org.compiere.model.MUOM) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MProductBOM(org.compiere.model.MProductBOM) KeyNamePair(org.compiere.util.KeyNamePair) Vector(java.util.Vector) BigDecimal(java.math.BigDecimal)

Example 77 with MProduct

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

the class myJTree method action_loadBOM.

//	actionPerformed
/**
	 * 	Action: Fill Tree with all nodes
	 */
private void action_loadBOM() {
    //m_frame.setBusy(true);
    m_frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    reload = false;
    int M_Product_ID = getM_Product_ID();
    if (M_Product_ID == 0)
        return;
    MProduct M_Product = MProduct.get(getCtx(), M_Product_ID);
    treeInfo.setText("    Current Selection: " + M_Product.getValue());
    Vector<Object> line = new Vector<Object>(17);
    //  0 Select
    line.add(new Boolean(false));
    //  1 IsActive
    line.add(new Boolean(M_Product.isActive()));
    // 2 Line
    line.add(new Integer(0));
    KeyNamePair pp = new KeyNamePair(M_Product.getM_Product_ID(), M_Product.getValue().concat("_").concat(M_Product.getName()));
    //  3 M_Product_ID
    line.add(pp);
    MUOM u = new MUOM(M_Product.getCtx(), M_Product.getC_UOM_ID(), M_Product.get_TrxName());
    KeyNamePair uom = new KeyNamePair(M_Product.getC_UOM_ID(), u.getUOMSymbol());
    //  4 C_UOM_ID
    line.add(uom);
    //  5 QtyBOM
    line.add(Env.ONE);
    DefaultMutableTreeNode parent = new DefaultMutableTreeNode(line);
    m_root = (DefaultMutableTreeNode) parent.getRoot();
    dataBOM.clear();
    if (isImplosion()) {
        for (MProductBOM bomline : getParentBOMs(M_Product_ID)) {
            addParent(bomline, parent);
        }
        m_tree = new myJTree(parent);
        m_tree.addMouseListener(mouseListener);
    } else {
        for (MProductBOM bom : getChildBOMs(M_Product_ID, true)) {
            addChild(bom, parent);
        }
        m_tree = new myJTree(parent);
        m_tree.addMouseListener(mouseListener);
    }
    /*		MouseListener ml = new MouseAdapter() {
		     public void mousePressed(MouseEvent e) {
		         int selRow = m_tree.getRowForLocation(e.getX(), e.getY());
		         TreePath selPath = m_tree.getPathForLocation(e.getX(), e.getY());
		         if(selRow != -1) {
		             if(e.getClickCount() == 1) {
		                 mySingleClick(selRow, selPath);
		             }
//		             else if(e.getClickCount() == 2) {
//		                 myDoubleClick(selRow, selPath);
//		             }
		         }
		     }

			private void mySingleClick(int selRow, TreePath selPath) {
				// TODO Auto-generated method stub
				
			}
		};
		m_tree.addMouseListener(ml);
*/
    m_tree.addTreeSelectionListener(this);
    treePane.getViewport().add(m_tree, null);
    loadTableBOM();
    dataPane.getViewport().add(tableBOM, null);
    // 4Layers - Set divider location
    splitPane.setDividerLocation(DIVIDER_LOCATION);
    // 4Layers - end
    //	Popup
    //		if (m_selected_id != 0)
    //		{
    //		}
    //m_frame.setBusy(false);
    m_frame.setCursor(Cursor.getDefaultCursor());
}
Also used : MProduct(org.compiere.model.MProduct) MUOM(org.compiere.model.MUOM) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MProductBOM(org.compiere.model.MProductBOM) KeyNamePair(org.compiere.util.KeyNamePair) Vector(java.util.Vector)

Example 78 with MProduct

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

the class MProductTest method testMProductCreation.

public void testMProductCreation() {
    // Start time - 20:16
    long startTime = System.currentTimeMillis();
    System.out.println("Start Time(ms) = " + startTime);
    System.out.println("Start Time     = " + new java.util.Date(startTime));
    // The 0 symbol shows a digit or 0 if no digit present 
    // The # symbol shows a digit or nothing if no digit present 
    // -001235
    NumberFormat formatter = new DecimalFormat("00000");
    for (int idx = startIndex; idx < (startIndex + runCount); idx++) {
        //System.out.println("idx = " + idx);
        product = new MProduct(getCtx(), 0, getTrxName());
        String formattedIdx = formatter.format(idx);
        product.setValue("test-product-" + formattedIdx);
        product.setName("Test Product " + formattedIdx);
        product.setAD_Org_ID(AD_Org_ID);
        product.setM_Product_Category_ID(M_Product_Category_ID);
        product.setC_TaxCategory_ID(C_TaxCategory_ID);
        product.setC_UOM_ID(C_UOM_ID);
        product.setProductType(ProductType);
        boolean saveResult = product.save();
        assertTrue("MProduct.save()", saveResult);
        //System.out.println("product.getM_Product_ID: " + product.getM_Product_ID());
        if (singleCommit) {
            try {
                commit();
            } catch (Exception e) {
                fail(e.getLocalizedMessage());
            }
        }
    }
    if (!singleCommit) {
        try {
            commit();
        } catch (Exception e) {
            fail(e.getLocalizedMessage());
        }
    }
    long endTime = System.currentTimeMillis();
    System.out.println("End Time(ms) = " + endTime);
    System.out.println("End Time     = " + new java.util.Date(endTime));
    long time = endTime - startTime;
    System.out.println("Duration(ms) = " + time);
    time = time / 1000;
    System.out.println("Duration(sec.) = " + time);
    if (time > 0) {
        System.out.println("Duration(min.) = " + time / 60);
    }
    System.out.println("Count = " + runCount + "; Time(seconds) = " + time + "; Products/Second = " + ((float) runCount / time) + "; ");
    assertTrue(this.getClass().getName(), true);
}
Also used : MProduct(org.compiere.model.MProduct) DecimalFormat(java.text.DecimalFormat) NumberFormat(java.text.NumberFormat)

Example 79 with MProduct

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

the class SingleMProductTest method testMProductCreation.

public void testMProductCreation() {
    boolean singleCommit = true;
    String trxName = "test";
    m_Ctx.setProperty("#AD_Client_ID", Integer.valueOf(11).toString());
    // Start time - 20:16
    long startTime = System.currentTimeMillis();
    System.out.println("Start Time(ms) = " + startTime);
    System.out.println("Start Time     = " + new java.util.Date(startTime));
    int startCount = 5;
    int count = 1;
    for (int idx = startCount; idx < (startCount + count); idx++) {
        //product = MProduct.get(m_Ctx, int M_Product_ID)
        product = new MProduct(m_Ctx, 0, trxName);
        //
        product.setAD_Org_ID(0);
        product.setValue("Test-Single-Product-" + idx);
        product.setName("Test-Single-Product-" + idx);
        // M_Product_Category
        // TODO - Trifon
        int M_Product_Category_ID = 105;
        product.setM_Product_Category_ID(M_Product_Category_ID);
        // C_TaxCategory
        // TODO - Trifon
        int C_TaxCategory_ID = 107;
        product.setC_TaxCategory_ID(C_TaxCategory_ID);
        // C_UOM
        // TODO - Trifon
        int C_UOM_ID = 100;
        product.setC_UOM_ID(C_UOM_ID);
        // C_UOM
        // TODO - Trifon
        String ProductType = "I";
        product.setProductType(ProductType);
        boolean saveResult = product.save();
        if (!saveResult) {
            assertEquals("Product not updated!", true, saveResult);
        } else {
            //System.out.println("product.getM_Product_ID: " + product.getM_Product_ID());
            if (singleCommit) {
                try {
                    DB.commit(true, trxName);
                } catch (Exception e) {
                    assertEquals("Product not updated!", true, false);
                }
            }
        }
    }
    if (!singleCommit) {
        try {
            DB.commit(true, trxName);
        } catch (Exception e) {
            assertEquals("Product not updated!", true, false);
        }
    }
    long endTime = System.currentTimeMillis();
    System.out.println("End Time(ms) = " + endTime);
    System.out.println("End Time     = " + new java.util.Date(endTime));
    long time = endTime - startTime;
    System.out.println("Duration(ms) = " + time);
    time = time / 1000;
    System.out.println("Duration(sec.) = " + time);
    if (time > 0) {
        System.out.println("Duration(min.) = " + time / 60);
    }
    System.out.println("Count = " + count + "; Time(seconds) = " + time + "; Products/Second = " + ((float) count / time) + "; ");
    assertTrue(this.getClass().getName(), true);
}
Also used : MProduct(org.compiere.model.MProduct)

Example 80 with MProduct

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

the class InventoryTestException method dumpStatus.

private void dumpStatus(MMDocument doc, String trxName) {
    MProduct product = InventoryUtil.getCreateProduct(doc.ProductValue, null);
    MStorage[] storage = MStorage.getOfProduct(getCtx(), product.get_ID(), trxName);
    System.err.println("STORAGE____________________________________________________");
    System.err.println("   " + doc);
    for (MStorage s : storage) {
        System.err.println("" + s);
    }
    //
    System.err.println(doc.scenario.toString());
    //	
    System.err.println("___________________________________________________________");
    System.err.flush();
    System.err.flush();
}
Also used : MProduct(org.compiere.model.MProduct) MStorage(org.compiere.model.MStorage)

Aggregations

MProduct (org.compiere.model.MProduct)180 BigDecimal (java.math.BigDecimal)70 AdempiereException (org.adempiere.exceptions.AdempiereException)30 ArrayList (java.util.ArrayList)29 Query (org.compiere.model.Query)29 ResultSet (java.sql.ResultSet)19 MLocator (org.compiere.model.MLocator)18 PreparedStatement (java.sql.PreparedStatement)17 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)17 KeyNamePair (org.compiere.util.KeyNamePair)17 MCostElement (org.compiere.model.MCostElement)16 MStorage (org.compiere.model.MStorage)16 MAcctSchema (org.compiere.model.MAcctSchema)14 MCost (org.compiere.model.MCost)14 MPPProductBOM (org.eevolution.model.MPPProductBOM)14 MPPProductBOMLine (org.eevolution.model.MPPProductBOMLine)14 SQLException (java.sql.SQLException)13 Timestamp (java.sql.Timestamp)13 MAttributeSetInstance (org.compiere.model.MAttributeSetInstance)13 Vector (java.util.Vector)12