Search in sources :

Example 61 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 62 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 63 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)

Example 64 with MProduct

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

the class MPPOrder method isQtyAvailable.

public static boolean isQtyAvailable(MPPOrder order, I_PP_Order_BOMLine line) {
    MProduct product = MProduct.get(order.getCtx(), line.getM_Product_ID());
    if (product == null || !product.isStocked())
        return true;
    BigDecimal qtyToDeliver = line.getQtyRequired();
    BigDecimal qtyScrap = line.getQtyScrap();
    BigDecimal qtyRequired = qtyToDeliver.add(qtyScrap);
    BigDecimal qtyAvailable = MStorage.getQtyAvailable(order.getM_Warehouse_ID(), 0, line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), order.get_TrxName());
    return qtyAvailable.compareTo(qtyRequired) >= 0;
}
Also used : MProduct(org.compiere.model.MProduct) BigDecimal(java.math.BigDecimal)

Example 65 with MProduct

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

the class MPPOrder method updateMakeToKit.

/**
	 * Create Auto Receipt and Issue based on Quantity
	 * @param qtyShipment
	 */
public void updateMakeToKit(BigDecimal qtyShipment) {
    MPPOrderBOM orderBOM = (MPPOrderBOM) getMPPOrderBOM();
    getLines(true);
    // Auto receipt and issue for kit
    if (MPPOrderBOM.BOMTYPE_Make_To_Kit.equals(orderBOM.getBOMType()) && MPPOrderBOM.BOMUSE_Manufacturing.equals(orderBOM.getBOMUse())) {
        Timestamp today = new Timestamp(System.currentTimeMillis());
        ArrayList[][] issue = new ArrayList[m_lines.length][1];
        for (int i = 0; i < getLines().length; i++) {
            MPPOrderBOMLine line = m_lines[i];
            KeyNamePair id = null;
            if (MPPOrderBOMLine.ISSUEMETHOD_Backflush.equals(line.getIssueMethod())) {
                id = new KeyNamePair(line.get_ID(), "Y");
            } else
                id = new KeyNamePair(line.get_ID(), "N");
            ArrayList<Object> data = new ArrayList<Object>();
            BigDecimal qtyToDeliver = qtyShipment.multiply(line.getQtyMultiplier());
            //0 - MPPOrderBOMLine ID
            data.add(id);
            //1 - Critical
            data.add(line.isCritical());
            MProduct product = (MProduct) line.getM_Product();
            //2 - Value
            data.add(product.getValue());
            KeyNamePair productKey = new KeyNamePair(product.get_ID(), product.getName());
            //3 - KeyNamePair Product
            data.add(productKey);
            //4 - QtyToDeliver			
            data.add(qtyToDeliver);
            //5 - QtyScrapComponent
            data.add(Env.ZERO);
            issue[i][0] = data;
        }
        boolean forceIssue = false;
        MOrderLine orderLine = (MOrderLine) getC_OrderLine();
        if (MOrder.DELIVERYRULE_CompleteLine.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_CompleteOrder.equals(orderLine.getParent().getDeliveryRule())) {
            boolean isCompleteQtyDeliver = MPPOrder.isQtyAvailable(this, issue, today);
            if (!isCompleteQtyDeliver) {
                throw new AdempiereException("@NoQtyAvailable@");
            }
        } else if (MOrder.DELIVERYRULE_Availability.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_AfterReceipt.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_Manual.equals(orderLine.getParent().getDeliveryRule())) {
            throw new AdempiereException("@DeliveryRule@ " + orderLine.getParent().getDeliveryRule() + "@ActionNotSupported@");
        } else if (MOrder.DELIVERYRULE_Force.equals(orderLine.getParent().getDeliveryRule())) {
            forceIssue = true;
        }
        for (int i = 0; i < issue.length; i++) {
            int attributeSetInstanceId = 0;
            KeyNamePair key = (KeyNamePair) issue[i][0].get(0);
            Boolean isCritical = (Boolean) issue[i][0].get(1);
            String value = (String) issue[i][0].get(2);
            KeyNamePair productkey = (KeyNamePair) issue[i][0].get(3);
            int productId = productkey.getKey();
            MProduct product = MProduct.get(getCtx(), productId);
            BigDecimal qtyToDeliver = (BigDecimal) issue[i][0].get(4);
            BigDecimal qtyScrapComponent = (BigDecimal) issue[i][0].get(5);
            MPPOrderBOMLine orderBOMLine = null;
            int orderBOMLineId = (Integer) key.getKey();
            if (orderBOMLineId > 0) {
                orderBOMLine = new MPPOrderBOMLine(getCtx(), orderBOMLineId, get_TrxName());
                //Validate if AttributeSet generate instance
                attributeSetInstanceId = orderBOMLine.getM_AttributeSetInstance_ID();
            }
            MStorage[] storages = MPPOrder.getStorages(getCtx(), productId, getM_Warehouse_ID(), attributeSetInstanceId, today, get_TrxName());
            MPPOrder.createIssue(this, orderBOMLine, today, qtyToDeliver, qtyScrapComponent, Env.ZERO, storages, forceIssue);
        }
        MPPOrder.createReceipt(this, today, getQtyDelivered(), qtyShipment, getQtyScrap(), getQtyReject(), getM_Locator_ID(), getM_AttributeSetInstance_ID());
    }
}
Also used : MProduct(org.compiere.model.MProduct) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) AdempiereException(org.adempiere.exceptions.AdempiereException) KeyNamePair(org.compiere.util.KeyNamePair) MOrderLine(org.compiere.model.MOrderLine)

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