Search in sources :

Example 21 with MLocator

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

the class InventoryTestException method assertMTransaction.

private void assertMTransaction(MMDocument doc, String trxName) {
    final MLocator locator = InventoryUtil.getCreateLocator(-1, doc.LocatorValue, doc.LocatorValue);
    final MProduct product = InventoryUtil.getCreateProduct(doc);
    final int M_ASI_ID;
    if (Util.isEmpty(doc.ASI, true)) {
        M_ASI_ID = -1;
    } else {
        M_ASI_ID = doc.scenario.getM_ASI_ID(doc.ASI);
    }
    //
    ArrayList<Object> params = new ArrayList<Object>();
    String whereClause = MTransaction.COLUMNNAME_M_Product_ID + "=?" + " AND " + MTransaction.COLUMNNAME_M_Locator_ID + "=?";
    params.add(product.get_ID());
    params.add(locator.get_ID());
    if (M_ASI_ID > 0) {
        whereClause += " AND " + MTransaction.COLUMNNAME_M_AttributeSetInstance_ID + "=?";
        params.add(M_ASI_ID);
    }
    //
    MTransaction trx = new Query(getCtx(), MTransaction.Table_Name, whereClause, trxName).setParameters(params).setOrderBy(// fetch lasts first
    MTransaction.COLUMNNAME_M_Transaction_ID + " DESC").first();
    //
    assertNotNull("No MTransaction found", trx);
    assertEquals("MTransaction.MovementQty not match", doc.Qty, trx.getMovementQty());
    if (doc.Date != null) {
        assertEquals("MTransaction.MovementDate not match", doc.Date, trx.getMovementDate());
    }
//
// TODO: check MCostDetail...
}
Also used : MProduct(org.compiere.model.MProduct) Query(org.compiere.model.Query) MLocator(org.compiere.model.MLocator) ArrayList(java.util.ArrayList) MTransaction(org.compiere.model.MTransaction)

Example 22 with MLocator

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

the class CalloutDistributionOrder method setLocatorTo.

/**
	 * Set Default Locator To
	 * @param ctx
	 * @param WindowNo
	 * @param mTab
	 * @param mField
	 * @param value
	 * @return
	 */
public String setLocatorTo(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) {
    I_DD_OrderLine line = GridTabWrapper.create(mTab, I_DD_OrderLine.class);
    if (value != null) {
        MProduct product = MProduct.get(ctx, (Integer) value);
        if (line.getC_UOM_ID() <= 0) {
            line.setC_UOM_ID(product.getC_UOM_ID());
        }
    }
    MWarehouse[] ws = MWarehouse.getForOrg(ctx, line.getAD_Org_ID());
    if (ws == null && ws.length < 0) {
        return "";
    }
    MLocator locator_to = MLocator.getDefault(ws[0]);
    if (locator_to != null) {
        line.setM_LocatorTo_ID(locator_to.getM_Locator_ID());
    }
    return "";
}
Also used : MProduct(org.compiere.model.MProduct) MLocator(org.compiere.model.MLocator) MWarehouse(org.compiere.model.MWarehouse)

Example 23 with MLocator

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

the class CostDimension method isSameCostDimension.

public static boolean isSameCostDimension(MAcctSchema as, MTransaction trxFrom, MTransaction trxTo) {
    if (trxFrom.getM_Product_ID() != trxTo.getM_Product_ID()) {
        throw new AdempiereException("Same product is needed - " + trxFrom + ", " + trxTo);
    }
    MProduct product = MProduct.get(trxFrom.getCtx(), trxFrom.getM_Product_ID());
    String CostingLevel = product.getCostingLevel(as, trxFrom.getAD_Org_ID());
    MLocator locatorFrom = MLocator.get(trxFrom.getCtx(), trxFrom.getM_Locator_ID());
    MLocator locatorTo = MLocator.get(trxTo.getCtx(), trxTo.getM_Locator_ID());
    int Org_ID = locatorFrom.getAD_Org_ID();
    int Org_ID_To = locatorTo.getAD_Org_ID();
    int ASI_ID = trxFrom.getM_AttributeSetInstance_ID();
    int ASI_ID_To = trxTo.getM_AttributeSetInstance_ID();
    if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel)) {
        Org_ID = 0;
        Org_ID_To = 0;
        ASI_ID = 0;
        ASI_ID_To = 0;
    } else if (MAcctSchema.COSTINGLEVEL_Organization.equals(CostingLevel)) {
        ASI_ID = 0;
        ASI_ID_To = 0;
    } else if (MAcctSchema.COSTINGLEVEL_Warehouse.equals(CostingLevel)) {
        ASI_ID = 0;
        ASI_ID_To = 0;
    } else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel)) {
        Org_ID = 0;
        Org_ID_To = 0;
    }
    //
    return Org_ID == Org_ID_To && ASI_ID == ASI_ID_To;
}
Also used : MProduct(org.compiere.model.MProduct) AdempiereException(org.adempiere.exceptions.AdempiereException) MLocator(org.compiere.model.MLocator)

Example 24 with MLocator

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

the class CostDimension method isSameCostDimension.

public static boolean isSameCostDimension(MAcctSchema as, IDocumentLine model) {
    MProduct product = MProduct.get(model.getCtx(), model.getM_Product_ID());
    MLocator locator = MLocator.get(model.getCtx(), model.getM_LocatorTo_ID());
    String CostingLevel = product.getCostingLevel(as, model.getAD_Org_ID());
    int Org_ID = model.getAD_Org_ID();
    int Org_ID_To = locator.getAD_Org_ID();
    int ASI_ID = model.getM_AttributeSetInstance_ID();
    int ASI_ID_To = model.getM_AttributeSetInstance_ID();
    if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel)) {
        Org_ID = 0;
        Org_ID_To = 0;
        ASI_ID = 0;
        ASI_ID_To = 0;
    } else if (MAcctSchema.COSTINGLEVEL_Organization.equals(CostingLevel)) {
        ASI_ID = 0;
        ASI_ID_To = 0;
    } else if (MAcctSchema.COSTINGLEVEL_Warehouse.equals(CostingLevel)) {
        ASI_ID = 0;
        ASI_ID_To = 0;
    } else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel)) {
        Org_ID = 0;
        Org_ID_To = 0;
    }
    //
    return Org_ID == Org_ID_To && ASI_ID == ASI_ID_To;
}
Also used : MProduct(org.compiere.model.MProduct) MLocator(org.compiere.model.MLocator)

Example 25 with MLocator

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

the class InOutCreateFrom method doIt.

@Override
protected String doIt() throws Exception {
    // Valid Record Identifier
    if (getRecord_ID() == 0)
        return "";
    AtomicInteger referenceId = new AtomicInteger(0);
    AtomicInteger created = new AtomicInteger(0);
    //	Get Shipment
    MInOut inout = new MInOut(getCtx(), getRecord_ID(), get_TrxName());
    log.config(inout + ", C_Locator_ID=" + getLocator());
    //	Get Default Locator
    MLocator defaultLocator = MLocator.getDefault((MWarehouse) inout.getM_Warehouse());
    List<Integer> recordIds = getSelectionKeys();
    String createFromType = recordIds.size() > 0 ? getSelectionAsString(recordIds.get(0), "CF_CreateFromType") : null;
    log.fine("CreateFromType=" + createFromType);
    if (createFromType == null || createFromType.length() == 0)
        throw new AdempiereException("@CreateFromType@ @NotFound@");
    //	Loop
    recordIds.stream().forEach(key -> {
        int productId = getSelectionAsInt(key, "CF_M_Product_ID");
        int chargeId = getSelectionAsInt(key, "CF_C_Charge_ID");
        int uomId = getSelectionAsInt(key, "CF_C_UOM_ID");
        int locatorId = getSelectionAsInt(key, "CF_M_Locator_ID");
        BigDecimal qtyEntered = getSelectionAsBigDecimal(key, "CF_QtyEntered");
        locatorId = getValidLocator(locatorId, defaultLocator);
        MInvoiceLine invoiceLine = null;
        int precision = 2;
        if (productId != 0) {
            MProduct product = MProduct.get(getCtx(), productId);
            precision = product.getUOMPrecision();
        }
        qtyEntered = qtyEntered.setScale(precision, BigDecimal.ROUND_HALF_DOWN);
        log.fine("Line QtyEntered=" + qtyEntered + ", Product=" + productId + ", Key=" + key);
        MInOutLine inOutLine = new MInOutLine(inout);
        inOutLine.setM_Product_ID(productId, uomId);
        inOutLine.setQty(qtyEntered);
        if (createFromType.equals(ORDER)) {
            MOrderLine orderLine = new MOrderLine(getCtx(), key, get_TrxName());
            referenceId.set(orderLine.getC_Order_ID());
            inOutLine.setC_OrderLine_ID(key);
            if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0) {
                inOutLine.setMovementQty(qtyEntered.multiply(orderLine.getQtyOrdered()).divide(orderLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
                inOutLine.setC_UOM_ID(orderLine.getC_UOM_ID());
            }
            inOutLine.setM_AttributeSetInstance_ID(orderLine.getM_AttributeSetInstance_ID());
            inOutLine.setDescription(orderLine.getDescription());
            inOutLine.setC_Project_ID(orderLine.getC_Project_ID());
            inOutLine.setC_ProjectPhase_ID(orderLine.getC_ProjectPhase_ID());
            inOutLine.setC_ProjectTask_ID(orderLine.getC_ProjectTask_ID());
            inOutLine.setC_Activity_ID(orderLine.getC_Activity_ID());
            inOutLine.setC_Campaign_ID(orderLine.getC_Campaign_ID());
            inOutLine.setAD_OrgTrx_ID(orderLine.getAD_OrgTrx_ID());
            inOutLine.setUser1_ID(orderLine.getUser1_ID());
            inOutLine.setUser2_ID(orderLine.getUser2_ID());
            inOutLine.setUser3_ID(orderLine.getUser3_ID());
            inOutLine.setUser4_ID(orderLine.getUser4_ID());
        } else if (createFromType.equals(INVOICE)) {
            invoiceLine = new MInvoiceLine(getCtx(), key, get_TrxName());
            MInvoice invoice = invoiceLine.getParent();
            referenceId.getAndSet(invoice.getC_Invoice_ID());
            if (invoice.isCreditMemo()) {
                qtyEntered = qtyEntered.negate();
                inOutLine.setQty(qtyEntered);
            }
            if (invoiceLine.getQtyEntered().compareTo(invoiceLine.getQtyInvoiced()) != 0) {
                inOutLine.setMovementQty(qtyEntered.multiply(invoiceLine.getQtyInvoiced()).divide(invoiceLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
                inOutLine.setC_UOM_ID(invoiceLine.getC_UOM_ID());
            }
            inOutLine.setDescription(invoiceLine.getDescription());
            inOutLine.setC_Project_ID(invoiceLine.getC_Project_ID());
            inOutLine.setC_ProjectPhase_ID(invoiceLine.getC_ProjectPhase_ID());
            inOutLine.setC_ProjectTask_ID(invoiceLine.getC_ProjectTask_ID());
            inOutLine.setC_Activity_ID(invoiceLine.getC_Activity_ID());
            inOutLine.setC_Campaign_ID(invoiceLine.getC_Campaign_ID());
            inOutLine.setAD_OrgTrx_ID(invoiceLine.getAD_OrgTrx_ID());
            inOutLine.setUser1_ID(invoiceLine.getUser1_ID());
            inOutLine.setUser2_ID(invoiceLine.getUser2_ID());
            inOutLine.setUser3_ID(invoiceLine.getUser3_ID());
            inOutLine.setUser4_ID(invoiceLine.getUser4_ID());
        } else if (createFromType.equals(RMA)) {
            MRMALine rmal = new MRMALine(getCtx(), key, get_TrxName());
            referenceId.set(rmal.getM_RMA_ID());
            inOutLine.setM_RMALine_ID(key);
            inOutLine.setQtyEntered(qtyEntered);
            inOutLine.setDescription(rmal.getDescription());
            inOutLine.setM_AttributeSetInstance_ID(rmal.getM_AttributeSetInstance_ID());
            inOutLine.setC_Project_ID(rmal.getC_Project_ID());
            inOutLine.setC_ProjectPhase_ID(rmal.getC_ProjectPhase_ID());
            inOutLine.setC_ProjectTask_ID(rmal.getC_ProjectTask_ID());
            inOutLine.setC_Activity_ID(rmal.getC_Activity_ID());
            inOutLine.setAD_OrgTrx_ID(rmal.getAD_OrgTrx_ID());
            inOutLine.setUser1_ID(rmal.getUser1_ID());
            inOutLine.setUser2_ID(rmal.getUser2_ID());
            inOutLine.setUser3_ID(rmal.getUser3_ID());
            inOutLine.setUser4_ID(rmal.getUser4_ID());
        }
        if (chargeId != 0)
            inOutLine.setC_Charge_ID(chargeId);
        inOutLine.setM_Locator_ID(locatorId);
        inOutLine.saveEx();
        if (invoiceLine != null) {
            invoiceLine.setM_InOutLine_ID(inOutLine.getM_InOutLine_ID());
            invoiceLine.saveEx();
        }
        created.updateAndGet(createNo -> createNo + 1);
    });
    //	Add reference to Order / Invoice / RMA
    addReference(inout, createFromType, referenceId.get());
    //	
    return "@Created@ " + created.get();
}
Also used : MInOut(org.compiere.model.MInOut) MProduct(org.compiere.model.MProduct) MInOutLine(org.compiere.model.MInOutLine) MInvoiceLine(org.compiere.model.MInvoiceLine) MInvoice(org.compiere.model.MInvoice) BigDecimal(java.math.BigDecimal) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AdempiereException(org.adempiere.exceptions.AdempiereException) MLocator(org.compiere.model.MLocator) MOrderLine(org.compiere.model.MOrderLine) MRMALine(org.compiere.model.MRMALine)

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