Search in sources :

Example 46 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 47 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 48 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 49 with MLocator

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

the class MovementGenerate method createLine.

//	generate
/**************************************************************************
	 * 	Create Line
	 *	@param Distribution order order
	 *	@param orderLine line
	 *	@param qty qty
	 *	@param storages storage info
	 *	@param force force delivery
	 */
private void createLine(MDDOrder order, MDDOrderLine orderLine, BigDecimal qty, MStorage[] storages, boolean force) {
    //	Complete last Shipment - can have multiple shipments
    if (m_lastC_BPartner_Location_ID != order.getC_BPartner_Location_ID())
        completeMovement();
    m_lastC_BPartner_Location_ID = order.getC_BPartner_Location_ID();
    //	Create New Shipment
    if (m_movement == null) {
        MLocator locator = MLocator.get(getCtx(), orderLine.getM_Locator_ID());
        m_movement = createMovement(order, m_movementDate);
        m_movement.setAD_Org_ID(locator.getAD_Org_ID());
        //m_movement.setM_Warehouse_ID(orderLine.getM_Warehouse_ID());	//	sets Org too
        m_movement.setIsInTransit(true);
        m_movement.setDD_Order_ID(order.getDD_Order_ID());
        if (order.getC_BPartner_ID() != order.getC_BPartner_ID())
            m_movement.setC_BPartner_ID(order.getC_BPartner_ID());
        if (order.getC_BPartner_Location_ID() != order.getC_BPartner_Location_ID())
            m_movement.setC_BPartner_Location_ID(order.getC_BPartner_Location_ID());
        //Look the document type based on organization
        int docTypeDO_ID = getDocType(MDocType.DOCBASETYPE_MaterialMovement, m_movement.getAD_Org_ID());
        if (docTypeDO_ID > 0)
            m_movement.setC_DocType_ID(docTypeDO_ID);
        if (!m_movement.save())
            throw new IllegalStateException("Could not create Movement");
    }
    //	Non Inventory Lines
    if (storages == null) {
        MMovementLine line = new MMovementLine(m_movement);
        line.setOrderLine(orderLine, Env.ZERO, false);
        //	Correct UOM
        line.setMovementQty(qty);
        if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0)
            line.setMovementQty(qty.multiply(orderLine.getQtyEntered()).divide(orderLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP));
        line.setLine(m_line + orderLine.getLine());
        if (!line.save())
            throw new IllegalStateException("Could not create Shipment Line");
        log.fine(line.toString());
        return;
    }
    //	Product
    MProduct product = orderLine.getProduct();
    boolean linePerASI = false;
    if (product.getM_AttributeSet_ID() != 0) {
        MAttributeSet mas = MAttributeSet.get(getCtx(), product.getM_AttributeSet_ID());
        linePerASI = mas.isInstanceAttribute();
    }
    //	Inventory Lines
    ArrayList<MMovementLine> list = new ArrayList<MMovementLine>();
    BigDecimal toDeliver = qty;
    for (int i = 0; i < storages.length; i++) {
        MStorage storage = storages[i];
        BigDecimal deliver = toDeliver;
        //	Not enough On Hand
        if (deliver.compareTo(storage.getQtyOnHand()) > 0 && //	positive storage
        storage.getQtyOnHand().signum() >= 0) {
            if (//	Adjust to OnHand Qty  
            !force || //	if force not on last location
            (force && i + 1 != storages.length))
                deliver = storage.getQtyOnHand();
        }
        if (//	zero deliver
        deliver.signum() == 0)
            continue;
        int M_Locator_ID = storage.getM_Locator_ID();
        //
        MMovementLine line = null;
        if (//	find line with Locator
        !linePerASI) {
            for (int ll = 0; ll < list.size(); ll++) {
                MMovementLine test = (MMovementLine) list.get(ll);
                if (test.getM_Locator_ID() == M_Locator_ID) {
                    line = test;
                    break;
                }
            }
        }
        if (//	new line
        line == null) {
            line = new MMovementLine(m_movement);
            line.setOrderLine(orderLine, deliver, false);
            line.setMovementQty(deliver);
            list.add(line);
        } else
            //	existing line
            line.setMovementQty(line.getMovementQty().add(deliver));
        if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0)
            line.setMovementQty(line.getMovementQty().multiply(orderLine.getQtyEntered()).divide(orderLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP));
        line.setLine(m_line + orderLine.getLine());
        if (linePerASI)
            line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
        if (!line.save())
            throw new IllegalStateException("Could not create Shipment Line");
        log.fine("ToDeliver=" + qty + "/" + deliver + " - " + line);
        toDeliver = toDeliver.subtract(deliver);
        //	Temp adjustment
        storage.setQtyOnHand(storage.getQtyOnHand().subtract(deliver));
        //
        if (toDeliver.signum() == 0)
            break;
    }
    if (toDeliver.signum() != 0)
        throw new IllegalStateException("Not All Delivered - Remainder=" + toDeliver);
}
Also used : MProduct(org.compiere.model.MProduct) MLocator(org.compiere.model.MLocator) ArrayList(java.util.ArrayList) MMovementLine(org.compiere.model.MMovementLine) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) MAttributeSet(org.compiere.model.MAttributeSet)

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