use of org.compiere.model.MProduct 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.ProductValue, null);
MOrderLine line = new MOrderLine(order);
line.setProduct(product);
line.setQty(doc.Qty);
line.saveEx();
//
doc.document = order;
processDocument(doc, MOrder.DOCACTION_Complete, MOrder.DOCSTATUS_Completed);
return order;
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class InventoryUtil method createMovement.
public static MMovement createMovement(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);
MLocator locatorTo = getCreateLocator(AD_Org_ID, doc.LocatorValueTo, doc.LocatorValueTo);
//
MMovement m = new MMovement(ctx, 0, trxName);
m.setAD_Org_ID(AD_Org_ID);
m.setMovementDate(doc.Date);
m.saveEx();
//
MMovementLine line = new MMovementLine(m);
line.setM_Product_ID(product.get_ID());
line.setM_Locator_ID(locator.get_ID());
line.setM_LocatorTo_ID(locatorTo.get_ID());
line.setMovementQty(doc.Qty);
line.saveEx();
//
doc.document = m;
processDocument(doc, MMovement.DOCACTION_Complete, MMovement.DOCSTATUS_Completed);
return m;
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class DistributionRunOrders method groovy1.
public String groovy1(String A_TrxName, Properties A_Ctx, int P_M_Warehouse_ID, int P_M_PriceList_Version_ID, int P_M_DistributionList_ID) {
MDistributionRunLine main = new MDistributionRunLine(A_Ctx, 0, A_TrxName);
MProduct product = MProduct.get(A_Ctx, main.getM_Product_ID());
BigDecimal Qty = main.getTotalQty();
int seq = main.getLine();
int num = 1;
if (product.isBOM() && Qty.signum() > 0) {
seq += 1;
MPPProductBOM bom = MPPProductBOM.getDefault(product, A_TrxName);
//Explotando los componentes
for (MPPProductBOMLine line : bom.getLines()) {
num += 1;
int M_Product_ID = line.getM_Product_ID();
BigDecimal QtyRequired = line.getQtyBOM().multiply(Qty);
BigDecimal QtyAvailable = MStorage.getQtyAvailable(P_M_Warehouse_ID, M_Product_ID, 0, 0, A_TrxName);
BigDecimal QtyOnHand = MPPMRP.getQtyOnHand(A_Ctx, P_M_Warehouse_ID, M_Product_ID, A_TrxName);
BigDecimal QtyToDeliver = QtyRequired;
if (QtyRequired.compareTo(QtyAvailable) > 0)
QtyToDeliver = QtyAvailable;
MDistributionRunLine drl = new MDistributionRunLine(A_Ctx, 0, A_TrxName);
drl.setM_DistributionRun_ID(main.getM_DistributionRun_ID());
drl.setLine(seq);
drl.setM_Product_ID(M_Product_ID);
drl.setM_DistributionList_ID(main.getM_DistributionList_ID());
drl.setDescription(Msg.translate(A_Ctx, "QtyRequired") + " = " + QtyRequired.intValue() + " | " + Msg.translate(A_Ctx, "QtyAvailable") + " = " + QtyAvailable + " | " + Msg.translate(A_Ctx, "QtyOnHand") + " = " + QtyOnHand);
drl.setTotalQty(QtyToDeliver);
drl.saveEx();
}
}
main.setIsActive(false);
return "Componentes del Juego:" + num;
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class WAttributeGrid method getGridElement.
// createGrid
/**
* Get Grid Element
* @param xValue X value
* @param yValue Y value
* @return Panel with Info
*/
private Panel getGridElement(MAttributeValue xValue, MAttributeValue yValue) {
Panel element = new Panel();
element.setStyle("border-width: thin; border-color: black;");
String sql = "SELECT * FROM M_Product WHERE IsActive='Y'";
// Product Attributes
if (xValue != null)
sql += " AND M_AttributeSetInstance_ID IN " + "(SELECT M_AttributeSetInstance_ID " + "FROM M_AttributeInstance " + "WHERE M_Attribute_ID=" + xValue.getM_Attribute_ID() + " AND M_AttributeValue_ID=" + xValue.getM_AttributeValue_ID() + ")";
if (yValue != null)
sql += " AND M_AttributeSetInstance_ID IN " + "(SELECT M_AttributeSetInstance_ID " + "FROM M_AttributeInstance " + "WHERE M_Attribute_ID=" + yValue.getM_Attribute_ID() + " AND M_AttributeValue_ID=" + yValue.getM_AttributeValue_ID() + ")";
sql = MRole.getDefault().addAccessSQL(sql, "M_Product", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
PreparedStatement pstmt = null;
int noProducts = 0;
try {
pstmt = DB.prepareStatement(sql, null);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
MProduct product = new MProduct(Env.getCtx(), rs, null);
addProduct(element, product);
noProducts++;
}
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
}
try {
if (pstmt != null)
pstmt.close();
pstmt = null;
} catch (Exception e) {
pstmt = null;
}
int mode = modeCombo.getSelectedIndex();
// No Products
if (noProducts == 0 && mode == MODE_VIEW) {
// CButton button = ConfirmPanel.createNewButton(true);
// button.addActionListener(this);
// element.add(button);
} else // Additional Elements
{
if (mode == MODE_PRICE) {
// Price Field
} else if (mode == MODE_PO) {
// Qty Field
}
}
return element;
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class WBOMDrop method addBOMLine.
// addBOMLines
/**
* Add BOM Line to this.
* Calls addBOMLines if added product is a BOM
* @param line BOM Line
* @param qty quantity
*/
private void addBOMLine(MProductBOM line, BigDecimal qty) {
log.fine(line.toString());
String bomType = line.getBOMType();
if (bomType == null)
bomType = MProductBOM.BOMTYPE_StandardPart;
//
BigDecimal lineQty = line.getBOMQty().multiply(qty);
MProduct product = line.getProduct();
if (product == null)
return;
if (product.isBOM() && product.isVerified())
// recursive
addBOMLines(product, lineQty);
else
addDisplay(line.getM_Product_ID(), product.getM_Product_ID(), bomType, product.getName(), lineQty);
}
Aggregations