Search in sources :

Example 36 with MLocator

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

the class InventoryUtil method createInventory.

public static MInventory createInventory(MMDocument doc, String trxName) {
    Properties ctx = Env.getCtx();
    int AD_Org_ID = getFirst_Org_ID();
    MProduct product = getCreateProduct(doc);
    MLocator locator = getCreateLocator(AD_Org_ID, doc.LocatorValue, doc.LocatorValue);
    //
    MInventory inv = new MInventory(ctx, 0, trxName);
    inv.setAD_Org_ID(AD_Org_ID);
    //inv.setIsInternalUseInventory(true); // TODO: arhipac: teo_sarca - add this column to trunk
    inv.setMovementDate(doc.Date);
    inv.setM_Warehouse_ID(locator.getM_Warehouse_ID());
    setGeneratedTag(inv);
    inv.saveEx();
    //
    MInventoryLine line = new MInventoryLine(inv, locator.get_ID(), product.get_ID(), 0, null, null);
    line.setQtyInternalUse(doc.Qty);
    line.setC_Charge_ID(getCreateCharge("junit-charge").get_ID());
    line.saveEx();
    //
    doc.document = inv;
    processDocument(doc, MInventory.DOCACTION_Complete, MInventory.DOCSTATUS_Completed);
    if (!Util.isEmpty(doc.ASI)) {
        line.load(trxName);
        doc.scenario.registerASICode(doc.ASI, line.getM_AttributeSetInstance_ID(), line.getQtyInternalUse().signum() <= 0);
    }
    checkLineCosts(doc, line, doc.Qty.signum() >= 0);
    return inv;
}
Also used : MProduct(org.compiere.model.MProduct) MInventory(org.compiere.model.MInventory) MInventoryLine(org.compiere.model.MInventoryLine) MLocator(org.compiere.model.MLocator) Properties(java.util.Properties)

Example 37 with MLocator

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

the class InventoryUtil method createOrder.

public static MOrder createOrder(MMDocument doc, String trxName) {
    Properties ctx = Env.getCtx();
    int M_PriceList_ID;
    boolean isSOTrx;
    if (MDocType.DOCBASETYPE_SalesOrder.equals(doc.DocBaseType)) {
        M_PriceList_ID = Env.getContextAsInt(ctx, "SO_PriceList_ID");
        isSOTrx = true;
    } else if (MDocType.DOCBASETYPE_PurchaseOrder.equals(doc.DocBaseType)) {
        M_PriceList_ID = Env.getContextAsInt(ctx, "PO_PriceList_ID");
        isSOTrx = false;
    } else {
        throw new IllegalArgumentException("DocBaseType not supported - " + doc);
    }
    //
    int AD_Org_ID = getFirst_Org_ID();
    MLocator locator = getCreateLocator(AD_Org_ID, doc.LocatorValue, doc.LocatorValue);
    //
    MOrder order = new MOrder(ctx, 0, trxName);
    order.setAD_Org_ID(AD_Org_ID);
    order.setIsSOTrx(isSOTrx);
    order.setC_DocTypeTarget_ID();
    order.setDateOrdered(doc.Date);
    order.setDateAcct(doc.Date);
    order.setDatePromised(doc.Date);
    order.setBPartner(getCreatePartner(doc.BPValue));
    order.setM_PriceList_ID(M_PriceList_ID);
    order.setM_Warehouse_ID(locator.getM_Warehouse_ID());
    setGeneratedTag(order);
    order.saveEx();
    // 
    MProduct product = getCreateProduct(doc);
    MOrderLine line = new MOrderLine(order);
    line.setProduct(product);
    line.setQty(doc.Qty);
    //anca_bradau 
    line.setPrice(doc.Price);
    line.saveEx();
    //
    doc.document = order;
    processDocument(doc, MOrder.DOCACTION_Complete, MOrder.DOCSTATUS_Completed);
    return order;
}
Also used : MOrder(org.compiere.model.MOrder) MProduct(org.compiere.model.MProduct) MLocator(org.compiere.model.MLocator) MOrderLine(org.compiere.model.MOrderLine) Properties(java.util.Properties)

Example 38 with MLocator

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

the class OrderDistribution method generate.

//	saveSelection
public String generate(IStatusBar statusBar, String docActionSelected) {
    String info = "";
    log.info("M_Locator_ID=" + m_M_Locator_ID);
    String trxName = Trx.createTrxName("IMG");
    Trx trx = Trx.get(trxName, true);
    //  prevents from being called twice
    setSelectionActive(false);
    statusBar.setStatusLine(Msg.translate(Env.getCtx(), "M_Movement_ID"));
    statusBar.setStatusDB(String.valueOf(getSelection().size()));
    //	Prepare Process
    int AD_Process_ID = MProcess.getProcess_ID("M_Generate Movement", trxName);
    MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
    if (!instance.save()) {
        info = Msg.getMsg(Env.getCtx(), "ProcessNoInstance");
        return info;
    }
    DB.createT_Selection(instance.getAD_PInstance_ID(), getSelection(), null);
    //call process
    ProcessInfo pi = new ProcessInfo("VOrderDistribution", AD_Process_ID);
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    //	Add Parameter - Selection=Y
    MPInstancePara ip = new MPInstancePara(instance, 10);
    ip.setParameter("Selection", "Y");
    ip.saveEx();
    MLocator locator = MLocator.get(Env.getCtx(), Integer.parseInt(m_M_Locator_ID.toString()));
    //	Add Parameter - M_Warehouse_ID=x
    ip = new MPInstancePara(instance, 20);
    ip.setParameter("M_Warehouse_ID", locator.getM_Warehouse_ID());
    ip.saveEx();
    setTrx(trx);
    setProcessInfo(pi);
    return info;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) MLocator(org.compiere.model.MLocator) Trx(org.compiere.util.Trx) ProcessInfo(org.compiere.process.ProcessInfo)

Example 39 with MLocator

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

the class WMRuleFIFO method getLocator.

/**
	 * Get locator
	 * @param ctx
	 * @param warehouseId
	 * @param productId
	 * @param warehouseAreaTypeId
	 * @param warehouseSectionTypeId
	 * @param trxName
     * @return
     */
public List<MLocator> getLocator(Properties ctx, int warehouseId, int productId, int warehouseAreaTypeId, int warehouseSectionTypeId, String trxName) {
    ArrayList<MLocator> locators = new ArrayList();
    List<MWMArea> areas = MWMArea.getByWarehouse(ctx, warehouseId, trxName);
    for (MWMArea area : areas) {
        List<MWMSection> sections = area.getBySectionType(warehouseSectionTypeId);
        for (MWMSection section : sections) {
            locators.addAll(MWMSectionDetail.getLocatorBySection(section));
        }
    }
    return locators;
}
Also used : MWMArea(org.eevolution.model.MWMArea) MLocator(org.compiere.model.MLocator) ArrayList(java.util.ArrayList) MWMSection(org.eevolution.model.MWMSection)

Example 40 with MLocator

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

the class InventoryTestException method assertStorage.

private void assertStorage(MMDocument doc, String trxName) {
    MLocator locator = InventoryUtil.getCreateLocator(-1, doc.LocatorValue, doc.LocatorValue);
    MProduct product = InventoryUtil.getCreateProduct(doc.ProductValue, null);
    int M_ASI_ID = -1;
    if (!Util.isEmpty(doc.ASI, true)) {
        M_ASI_ID = doc.scenario.getM_ASI_ID(doc.ASI);
    }
    ArrayList<Object> params = new ArrayList<Object>();
    String sql = "SELECT" + " COALESCE(SUM(QtyOnHand),0)" + ",COALESCE(SUM(QtyReserved),0)" + ",COALESCE(SUM(QtyOrdered),0)" + " FROM M_Storage" + " WHERE M_Locator_ID=? AND M_Product_ID=?";
    params.add(locator.get_ID());
    params.add(product.get_ID());
    if (M_ASI_ID >= 0) {
        sql += " AND " + MStorage.COLUMNNAME_M_AttributeSetInstance_ID + "=?";
        params.add(M_ASI_ID);
    }
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    BigDecimal qtyOnHand = Env.ZERO;
    BigDecimal qtyOrdered = Env.ZERO;
    BigDecimal qtyReserved = Env.ZERO;
    try {
        pstmt = DB.prepareStatement(sql, trxName);
        DB.setParameters(pstmt, params);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            qtyOnHand = rs.getBigDecimal(1);
            qtyReserved = rs.getBigDecimal(2);
            qtyOrdered = rs.getBigDecimal(3);
        }
    } catch (SQLException e) {
        throw new DBException(e, sql);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //
    //
    assertEquals("QtyOnHand not match " + doc, doc.Qty, qtyOnHand);
    assertEquals("QtyReserved not match " + doc, doc.QtyReserved, qtyReserved);
    assertEquals("QtyOrdered not match " + doc, doc.QtyOrdered, qtyOrdered);
}
Also used : DBException(org.adempiere.exceptions.DBException) MProduct(org.compiere.model.MProduct) SQLException(java.sql.SQLException) MLocator(org.compiere.model.MLocator) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) BigDecimal(java.math.BigDecimal)

Aggregations

MLocator (org.compiere.model.MLocator)49 MProduct (org.compiere.model.MProduct)18 BigDecimal (java.math.BigDecimal)16 MWarehouse (org.compiere.model.MWarehouse)12 MStorage (org.compiere.model.MStorage)9 ArrayList (java.util.ArrayList)8 Properties (java.util.Properties)8 Query (org.compiere.model.Query)7 AdempiereException (org.adempiere.exceptions.AdempiereException)6 MMovementLine (org.compiere.model.MMovementLine)6 KeyNamePair (org.compiere.util.KeyNamePair)6 ResultSet (java.sql.ResultSet)5 Timestamp (java.sql.Timestamp)5 MBPartner (org.compiere.model.MBPartner)5 MMovement (org.compiere.model.MMovement)5 MOrderLine (org.compiere.model.MOrderLine)5 MDDOrderLine (org.eevolution.model.MDDOrderLine)5 ListItem (org.adempiere.webui.component.ListItem)4 MDDOrder (org.eevolution.model.MDDOrder)4 PreparedStatement (java.sql.PreparedStatement)3