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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations