Search in sources :

Example 21 with MProduct

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

the class PosKeyGenerate method doIt.

/**
	 * Generate keys for each product
	 */
@Override
protected String doIt() throws Exception {
    if (posKeyLayoutId == 0)
        throw new FillMandatoryException("C_POSKeyLayout_ID");
    int count = 0;
    String where = "";
    Object[] params = new Object[] {};
    if (productCategoryId > 0) {
        where = "M_Product_Category_ID = ? ";
        params = new Object[] { productCategoryId };
    }
    Query query = new Query(getCtx(), MProduct.Table_Name, where, get_TrxName()).setParameters(params).setOnlyActiveRecords(true).setOrderBy("Value");
    List<MProduct> products = query.list();
    for (MProduct product : products) {
        MPOSKey key = new MPOSKey(getCtx(), 0, get_TrxName());
        key.setName(product.getName());
        key.setM_Product_ID(product.getM_Product_ID());
        key.setC_POSKeyLayout_ID(posKeyLayoutId);
        key.setSeqNo(count * 10);
        key.setQty(Env.ONE);
        key.saveEx();
        count++;
    }
    return "@Created@ " + count;
}
Also used : MProduct(org.compiere.model.MProduct) Query(org.compiere.model.Query) MPOSKey(org.compiere.model.MPOSKey) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException)

Example 22 with MProduct

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

the class ProductUOMConvert method doIt.

//	prepare
/**
	 * 	Process
	 *	@return message
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    if (p_M_Product_ID == 0 || p_M_Product_To_ID == 0 || p_M_Locator_ID == 0 || p_Qty == null || Env.ZERO.compareTo(p_Qty) == 0)
        throw new AdempiereUserError("Invalid Parameter");
    //
    MProduct product = MProduct.get(getCtx(), p_M_Product_ID);
    MProduct productTo = MProduct.get(getCtx(), p_M_Product_To_ID);
    log.info("Product=" + product + ", ProductTo=" + productTo + ", M_Locator_ID=" + p_M_Locator_ID + ", Qty=" + p_Qty);
    MUOMConversion[] conversions = MUOMConversion.getProductConversions(getCtx(), product.getM_Product_ID());
    MUOMConversion conversion = null;
    for (int i = 0; i < conversions.length; i++) {
        if (conversions[i].getC_UOM_To_ID() == productTo.getC_UOM_ID())
            conversion = conversions[i];
    }
    if (conversion == null)
        throw new AdempiereUserError("@NotFound@: @C_UOM_Conversion_ID@");
    MUOM uomTo = MUOM.get(getCtx(), productTo.getC_UOM_ID());
    BigDecimal qtyTo = p_Qty.divide(conversion.getDivideRate(), uomTo.getStdPrecision(), BigDecimal.ROUND_HALF_UP);
    BigDecimal qtyTo6 = p_Qty.divide(conversion.getDivideRate(), 6, BigDecimal.ROUND_HALF_UP);
    if (qtyTo.compareTo(qtyTo6) != 0)
        throw new AdempiereUserError("@StdPrecision@: " + qtyTo + " <> " + qtyTo6 + " (" + p_Qty + "/" + conversion.getDivideRate() + ")");
    log.info(conversion + " -> " + qtyTo);
    //	Set to Beta
    return "Not completed yet";
}
Also used : MUOMConversion(org.compiere.model.MUOMConversion) MProduct(org.compiere.model.MProduct) MUOM(org.compiere.model.MUOM) AdempiereUserError(org.compiere.util.AdempiereUserError) BigDecimal(java.math.BigDecimal)

Example 23 with MProduct

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

the class ReplenishReport method createMovements.

//	createRequisition
/**
	 * 	Create Inventory Movements
	 */
private void createMovements() {
    int noMoves = 0;
    String info = "";
    //
    MClient client = null;
    MMovement move = null;
    int M_Warehouse_ID = 0;
    int M_WarehouseSource_ID = 0;
    MWarehouse whSource = null;
    MWarehouse wh = null;
    X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NOT NULL");
    for (int i = 0; i < replenishs.length; i++) {
        X_T_Replenish replenish = replenishs[i];
        if (whSource == null || whSource.getM_WarehouseSource_ID() != replenish.getM_WarehouseSource_ID())
            whSource = MWarehouse.get(getCtx(), replenish.getM_WarehouseSource_ID());
        if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
            wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
        if (client == null || client.getAD_Client_ID() != whSource.getAD_Client_ID())
            client = MClient.get(getCtx(), whSource.getAD_Client_ID());
        //
        if (move == null || M_WarehouseSource_ID != replenish.getM_WarehouseSource_ID() || M_Warehouse_ID != replenish.getM_Warehouse_ID()) {
            M_WarehouseSource_ID = replenish.getM_WarehouseSource_ID();
            M_Warehouse_ID = replenish.getM_Warehouse_ID();
            move = new MMovement(getCtx(), 0, get_TrxName());
            move.setC_DocType_ID(p_C_DocType_ID);
            move.setDescription(Msg.getMsg(getCtx(), "Replenishment") + ": " + whSource.getName() + "->" + wh.getName());
            //	Set Org
            move.setAD_Org_ID(whSource.getAD_Org_ID());
            if (!move.save())
                return;
            log.fine(move.toString());
            noMoves++;
            info += " - " + move.getDocumentNo();
        }
        //	To
        int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID();
        //	From: Look-up Storage
        MProduct product = MProduct.get(getCtx(), replenish.getM_Product_ID());
        String MMPolicy = product.getMMPolicy();
        MStorage[] storages = MStorage.getWarehouse(getCtx(), whSource.getM_Warehouse_ID(), replenish.getM_Product_ID(), 0, 0, true, null, MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
        //
        BigDecimal target = replenish.getQtyToOrder();
        for (int j = 0; j < storages.length; j++) {
            MStorage storage = storages[j];
            if (storage.getQtyOnHand().signum() <= 0)
                continue;
            BigDecimal moveQty = target;
            if (storage.getQtyOnHand().compareTo(moveQty) < 0)
                moveQty = storage.getQtyOnHand();
            //
            MMovementLine line = new MMovementLine(move);
            line.setM_Product_ID(replenish.getM_Product_ID());
            line.setMovementQty(moveQty);
            if (replenish.getQtyToOrder().compareTo(moveQty) != 0)
                line.setDescription("Total: " + replenish.getQtyToOrder());
            //	from
            line.setM_Locator_ID(storage.getM_Locator_ID());
            line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
            //	to
            line.setM_LocatorTo_ID(M_LocatorTo_ID);
            line.setM_AttributeSetInstanceTo_ID(storage.getM_AttributeSetInstance_ID());
            line.saveEx();
            //
            target = target.subtract(moveQty);
            if (target.signum() == 0)
                break;
        }
    }
    if (replenishs.length == 0) {
        m_info = "No Source Warehouse";
        log.warning(m_info);
    } else {
        m_info = "#" + noMoves + info;
        log.info(m_info);
    }
}
Also used : MProduct(org.compiere.model.MProduct) X_T_Replenish(org.compiere.model.X_T_Replenish) MMovementLine(org.compiere.model.MMovementLine) MMovement(org.compiere.model.MMovement) MStorage(org.compiere.model.MStorage) MWarehouse(org.compiere.model.MWarehouse) BigDecimal(java.math.BigDecimal) MClient(org.compiere.model.MClient)

Example 24 with MProduct

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

the class CalloutBOM method getdefaults.

//	qty
/**
	 *	getdefaults   
	 *  get defaults for Product (search key, name, description, help and UOM)
	 *  @param ctx      Context
	 *  @param WindowNo current Window No
	 *  @param mTab     Model Tab
	 *  @param mField   Model Field
	 *  @param value    The new value
	 */
public String getdefaults(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) {
    if (isCalloutActive() || value == null)
        return "";
    int M_Product_ID = (Integer) value;
    if (M_Product_ID <= 0)
        return "";
    MProduct product = MProduct.get(ctx, M_Product_ID);
    I_PP_Product_BOM bom = GridTabWrapper.create(mTab, I_PP_Product_BOM.class);
    bom.setValue(product.getValue());
    bom.setName(product.getName());
    bom.setDescription(product.getDescription());
    bom.setHelp(product.getHelp());
    bom.setC_UOM_ID(product.getC_UOM_ID());
    if (product.getEnvAttributeSetInstance(ctx, WindowNo) != null)
        bom.setM_AttributeSetInstance_ID(product.getEnvAttributeSetInstance(ctx, WindowNo));
    return "";
}
Also used : MProduct(org.compiere.model.MProduct)

Example 25 with MProduct

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

the class MPPOrder method explotion.

/**
	 * Create PP_Order_BOM from PP_Product_BOM.
	 * Create PP_Order_Workflow from AD_Workflow.
	 */
private void explotion() {
    // Create BOM Head
    final MPPProductBOM PP_Product_BOM = MPPProductBOM.get(getCtx(), getPP_Product_BOM_ID());
    // Product from Order should be same as product from BOM - teo_sarca [ 2817870 ] 
    if (getM_Product_ID() != PP_Product_BOM.getM_Product_ID()) {
        throw new AdempiereException("@NotMatch@ @PP_Product_BOM_ID@ , @M_Product_ID@");
    }
    // Product BOM Configuration should be verified - teo_sarca [ 2817870 ]
    final MProduct product = MProduct.get(getCtx(), PP_Product_BOM.getM_Product_ID());
    if (!product.isVerified()) {
        // TODO: translate
        throw new AdempiereException("Product BOM Configuration not verified. Please verify the product first - " + product.getValue());
    }
    if (PP_Product_BOM.isValidFromTo(getDateStartSchedule())) {
        MPPOrderBOM PP_Order_BOM = new MPPOrderBOM(PP_Product_BOM, getPP_Order_ID(), get_TrxName());
        PP_Order_BOM.setAD_Org_ID(getAD_Org_ID());
        PP_Order_BOM.saveEx();
        for (MPPProductBOMLine PP_Product_BOMline : PP_Product_BOM.getLines(true)) {
            if (PP_Product_BOMline.isValidFromTo(getDateStartSchedule())) {
                MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(PP_Product_BOMline, getPP_Order_ID(), PP_Order_BOM.get_ID(), getM_Warehouse_ID(), get_TrxName());
                PP_Order_BOMLine.setAD_Org_ID(getAD_Org_ID());
                PP_Order_BOMLine.setM_Warehouse_ID(getM_Warehouse_ID());
                PP_Order_BOMLine.setM_Locator_ID(getM_Locator_ID());
                PP_Order_BOMLine.setQtyOrdered(getQtyOrdered());
                PP_Order_BOMLine.saveEx();
            } else // end if valid From / To    
            {
                log.fine("BOM Line skiped - " + PP_Product_BOMline);
            }
        }
    // end Create Order BOM
    } else // end if From / To parent
    {
        throw new BOMExpiredException(PP_Product_BOM, getDateStartSchedule());
    }
    // Create Workflow (Routing & Process)
    final MWorkflow AD_Workflow = MWorkflow.get(getCtx(), getAD_Workflow_ID());
    // Workflow should be validated first - teo_sarca [ 2817870 ]
    if (!AD_Workflow.isValid()) {
        // TODO: translate
        throw new AdempiereException("Routing is not valid. Please validate it first - " + AD_Workflow.getValue());
    }
    if (AD_Workflow.isValidFromTo(getDateStartSchedule())) {
        MPPOrderWorkflow PP_Order_Workflow = new MPPOrderWorkflow(AD_Workflow, get_ID(), get_TrxName());
        PP_Order_Workflow.setAD_Org_ID(getAD_Org_ID());
        PP_Order_Workflow.saveEx();
        for (MWFNode AD_WF_Node : AD_Workflow.getNodes(false, getAD_Client_ID())) {
            if (AD_WF_Node.isValidFromTo(getDateStartSchedule())) {
                MPPOrderNode PP_Order_Node = new MPPOrderNode(AD_WF_Node, PP_Order_Workflow, getQtyOrdered(), get_TrxName());
                PP_Order_Node.setAD_Org_ID(getAD_Org_ID());
                PP_Order_Node.saveEx();
                for (MWFNodeNext AD_WF_NodeNext : AD_WF_Node.getTransitions(getAD_Client_ID())) {
                    MPPOrderNodeNext nodenext = new MPPOrderNodeNext(AD_WF_NodeNext, PP_Order_Node);
                    nodenext.setAD_Org_ID(getAD_Org_ID());
                    nodenext.saveEx();
                }
                for (MPPWFNodeProduct wfnp : MPPWFNodeProduct.forAD_WF_Node_ID(getCtx(), AD_WF_Node.get_ID())) {
                    MPPOrderNodeProduct nodeOrderProduct = new MPPOrderNodeProduct(wfnp, PP_Order_Node);
                    nodeOrderProduct.setAD_Org_ID(getAD_Org_ID());
                    nodeOrderProduct.saveEx();
                }
                for (MPPWFNodeAsset wfna : MPPWFNodeAsset.forAD_WF_Node_ID(getCtx(), AD_WF_Node.get_ID())) {
                    MPPOrderNodeAsset nodeorderasset = new MPPOrderNodeAsset(wfna, PP_Order_Node);
                    nodeorderasset.setAD_Org_ID(getAD_Org_ID());
                    nodeorderasset.saveEx();
                }
            }
        // for node 
        }
        // Update transitions nexts and set first node
        // requery
        PP_Order_Workflow.getNodes(true);
        for (MPPOrderNode orderNode : PP_Order_Workflow.getNodes(false, getAD_Client_ID())) {
            // set workflow start node
            if (PP_Order_Workflow.getAD_WF_Node_ID() == orderNode.getAD_WF_Node_ID()) {
                PP_Order_Workflow.setPP_Order_Node_ID(orderNode.getPP_Order_Node_ID());
            }
            // set node next
            for (MPPOrderNodeNext next : orderNode.getTransitions(getAD_Client_ID())) {
                next.setPP_Order_Next_ID();
                next.saveEx();
            }
        }
        PP_Order_Workflow.saveEx();
    } else // workflow valid from/to
    {
        throw new RoutingExpiredException(AD_Workflow, getDateStartSchedule());
    }
}
Also used : MProduct(org.compiere.model.MProduct) MWorkflow(org.compiere.wf.MWorkflow) BOMExpiredException(org.eevolution.exceptions.BOMExpiredException) MWFNode(org.compiere.wf.MWFNode) MWFNodeNext(org.compiere.wf.MWFNodeNext) RoutingExpiredException(org.eevolution.exceptions.RoutingExpiredException) AdempiereException(org.adempiere.exceptions.AdempiereException)

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