Search in sources :

Example 41 with MLocator

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

the class MStorageTest method createLocator.

private MLocator createLocator(MWarehouse wh, String locatorValue, double qtyOnHand) {
    MLocator loc = new MLocator(wh, wh.getValue() + "-" + locatorValue);
    loc.setXYZ("X" + locatorValue, "Y" + locatorValue, "Z" + locatorValue);
    loc.saveEx();
    //
    BigDecimal targetQty = BigDecimal.valueOf(qtyOnHand).setScale(12, BigDecimal.ROUND_HALF_UP);
    MStorage s1 = MStorage.getCreate(getCtx(), loc.get_ID(), product_id, 0, getTrxName());
    s1.setQtyOnHand(targetQty);
    s1.saveEx();
    //
    BigDecimal qty = MStorage.getQtyAvailable(wh.get_ID(), loc.get_ID(), product_id, 0, getTrxName()).setScale(12, BigDecimal.ROUND_HALF_UP);
    assertEquals("Error on locator " + locatorValue, targetQty, qty);
    //
    return loc;
}
Also used : MLocator(org.compiere.model.MLocator) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal)

Example 42 with MLocator

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

the class InventoryUtil method getCreateLocator.

/**
	 * Helper Method : Create Locator
	 */
public static MLocator getCreateLocator(int AD_Org_ID, String whValue, String value) {
    if (AD_Org_ID <= 0)
        AD_Org_ID = getFirst_Org_ID();
    MWarehouse wh = getCreateWarehouse(AD_Org_ID, whValue);
    MLocator locator = null;
    for (MLocator loc : wh.getLocators(false)) {
        if (loc.getValue().equals(value)) {
            locator = loc;
            break;
        }
    }
    if (locator == null) {
        locator = new MLocator(wh, value);
        locator.setXYZ(value, value, value);
    }
    if (wh.getLocators(false).length == 0) {
        locator.setIsDefault(true);
    }
    locator.saveEx();
    //
    return locator;
}
Also used : MLocator(org.compiere.model.MLocator) MWarehouse(org.compiere.model.MWarehouse)

Example 43 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.ProductValue, null);
    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);
    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);
    }
    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 44 with MLocator

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

the class CPOS method validLocator.

/**
	 * Valid Locator
	 * @return
	 * @return String
	 */
public void validLocator() {
    MWarehouse warehouse = MWarehouse.get(ctx, getM_Warehouse_ID());
    MLocator[] locators = warehouse.getLocators(true);
    for (MLocator mLocator : locators) {
        if (mLocator.isDefault()) {
            return;
        }
    }
    throw new AdempierePOSException("@M_Locator_ID@ @default@ " + "@not.found@ @M_Warehouse_ID@: " + warehouse.getName());
}
Also used : MLocator(org.compiere.model.MLocator) AdempierePOSException(org.adempiere.pos.AdempierePOSException) MWarehouse(org.compiere.model.MWarehouse)

Example 45 with MLocator

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

the class WLocatorEditor method setDefault_Locator_ID.

// getOnly_Product_ID
/**
	 * Set the default locator if this field is mandatory 
	 * and we have a warehouse restriction.
	 * 
	 * @since 3.1.4
	 */
private void setDefault_Locator_ID() {
    if (!isMandatory() || m_mLocator == null) {
        return;
    }
    int M_Warehouse_ID = getOnly_Warehouse_ID();
    if (M_Warehouse_ID <= 0) {
        return;
    }
    MWarehouse wh = MWarehouse.get(Env.getCtx(), M_Warehouse_ID);
    if (wh == null || wh.get_ID() <= 0) {
        return;
    }
    MLocator loc = wh.getDefaultLocator();
    if (loc == null || loc.get_ID() <= 0) {
        return;
    }
    setValue(Integer.valueOf(loc.get_ID()));
}
Also used : MLocator(org.compiere.model.MLocator) MWarehouse(org.compiere.model.MWarehouse)

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