use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class PromotionRule method addDiscountLine.
private static void addDiscountLine(MOrder order, MOrderLine ol, BigDecimal discount, BigDecimal qty, int C_Charge_ID, I_M_Promotion promotion) throws Exception {
MOrderLine nol;
if (discount.scale() > 2)
discount = discount.setScale(2, BigDecimal.ROUND_HALF_UP);
String description = promotion.getName();
if (ol != null)
description += (", " + ol.getName());
//Look for same order line. If found, just update qty
nol = new Query(Env.getCtx(), MTable.get(order.getCtx(), MOrderLine.Table_ID), "C_OrderLine.C_Order_ID=? AND C_Charge_ID=? AND M_Promotion_ID=? AND priceactual=? AND Description='" + description + "'" + " AND C_OrderLine.IsActive='Y'", order.get_TrxName()).setParameters(ol.getC_Order_ID(), C_Charge_ID, promotion.getM_Promotion_ID(), discount.negate()).firstOnly();
if (nol != null) {
// just add one to he Order line
nol.setQty(nol.getQtyEntered().add(qty));
nol.saveEx();
return;
}
// SHW: new order line
nol = new MOrderLine(order.getCtx(), 0, order.get_TrxName());
nol.setC_Order_ID(order.getC_Order_ID());
nol.setOrder(order);
nol.setC_Charge_ID(C_Charge_ID);
nol.setQty(qty);
nol.setPriceActual(discount.negate());
// SHW
nol.setC_UOM_ID(ol.getC_UOM_ID());
if (ol != null && Integer.toString(ol.getLine()).endsWith("0")) {
for (int i = 0; i < 9; i++) {
int line = ol.getLine() + i + 1;
int r = DB.getSQLValue(order.get_TrxName(), "SELECT C_OrderLine_ID FROM C_OrderLine WHERE C_Order_ID = ? AND Line = ?", order.getC_Order_ID(), line);
if (r <= 0) {
nol.setLine(line);
break;
}
}
}
nol.setDescription(description);
nol.set_ValueOfColumn("M_Promotion_ID", promotion.getM_Promotion_ID());
if (promotion.getC_Campaign_ID() > 0) {
nol.setC_Campaign_ID(promotion.getC_Campaign_ID());
}
if (!nol.save())
throw new AdempiereException("Failed to add discount line to order");
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class CostResult method createSalesOrder.
public MOrder createSalesOrder(Timestamp orderDate, BigDecimal qty, BigDecimal price) {
MDocType salesType = null;
for (MDocType dt : MDocType.getOfDocBaseType(getCtx(), MDocType.DOCBASETYPE_SalesOrder)) {
if (MDocType.DOCSUBTYPESO_OnCreditOrder.equals(dt.getDocSubTypeSO())) {
salesType = dt;
break;
}
}
//Create Sales Order
MOrder salesOrder = new MOrder(getCtx(), 0, trxName);
salesOrder.setAD_Org_ID(Env.getAD_Org_ID(getCtx()));
salesOrder.setC_BPartner_ID(bp.getC_BPartner_ID());
salesOrder.setIsSOTrx(true);
salesOrder.setDateOrdered(orderDate);
salesOrder.setDateAcct(orderDate);
salesOrder.setM_Warehouse_ID(w.getM_Warehouse_ID());
salesOrder.setSalesRep_ID(u.getAD_User_ID());
salesOrder.setC_DocTypeTarget_ID(salesType.getC_DocType_ID());
salesOrder.saveEx();
// Create Line
MOrderLine salesOrderLine = new MOrderLine(salesOrder);
salesOrderLine.setM_Product_ID(product.getM_Product_ID());
salesOrderLine.setPrice(price);
salesOrderLine.setQtyEntered(qty);
salesOrderLine.setQtyOrdered(qty);
salesOrderLine.saveEx();
// Complete Purchase Order
salesOrder.setDocAction(DocAction.ACTION_Complete);
salesOrder.setDocStatus(DocAction.STATUS_Drafted);
salesOrder.processIt(DocAction.ACTION_Complete);
salesOrder.saveEx();
return salesOrder;
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class CostResult method createBusinessCaseTest.
/**
* create Business Test Case
* @param trxName
*/
void createBusinessCaseTest(String trxName) {
createDataMaster();
generateHistoryCost();
Timestamp dateAcct;
//First Purchase Receipt
dateAcct = today;
MOrder purchase1 = createPurchaseOrder(dateAcct, new BigDecimal(100), new BigDecimal(36));
MInOut receipt1 = null;
for (MOrderLine line : purchase1.getLines()) {
receipt1 = createMaterialReceipt(dateAcct, new BigDecimal(10), line.getC_OrderLine_ID());
}
for (MInOutLine line : receipt1.getLines()) {
CostResult costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("47.7292"), // cumulateQty
new BigDecimal("30"), //cumulateAmt
new BigDecimal("1431.8748"), //cdAmt
new BigDecimal("477.2920"), //cdAdjutment
new BigDecimal("0"), //cdQty
new BigDecimal("10"), //cdCurrentCostPrice
new BigDecimal("53.5937"), //cdCumulateQty
new BigDecimal("20"), //cdCumulateAmt
new BigDecimal("1071.8748"), dateAcct);
assertCostReceipt(costResult, line.getM_InOutLine_ID(), as, trxName);
}
//Create Sales Order Order Credit by 5
dateAcct = TimeUtil.addDays(today, 15);
MOrder sales1 = createSalesOrder(dateAcct, new BigDecimal(5), new BigDecimal(45));
for (MOrderLine line : sales1.getLines()) {
CostResult costResult = new CostResult(product.getM_Product_ID(), new BigDecimal("47.7292"), new BigDecimal("25"), new BigDecimal("1193.2288"), new BigDecimal("238.6460"), new BigDecimal("0"), new BigDecimal("-5"), new BigDecimal("47.7292"), new BigDecimal("30"), new BigDecimal("1431.8748"), dateAcct);
assertCostShipment(costResult, line.getC_OrderLine_ID(), as, trxName);
}
//Second Purchase Receipt 7 day forward
dateAcct = TimeUtil.addDays(today, 31);
MOrder purchase2 = createPurchaseOrder(dateAcct, new BigDecimal(100), new BigDecimal(34));
MInOut receipt2 = null;
for (MOrderLine line : purchase2.getLines()) {
receipt2 = createMaterialReceipt(dateAcct, new BigDecimal(10), line.getC_OrderLine_ID());
}
for (MInOutLine line : receipt2.getLines()) {
CostResult costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("43.8065"), // cumulateQty
new BigDecimal("35"), //cumulateAmt
new BigDecimal("1533.2288"), //cdAmt
new BigDecimal("438.0650"), //cdAdjutment
new BigDecimal("0"), //cdQty
new BigDecimal("10"), //cdCurrentCostPrice
new BigDecimal("47.7292"), //cdCumulateQty
new BigDecimal("25"), //cdCumulateAmt
new BigDecimal("1193.2288"), dateAcct);
assertCostReceipt(costResult, line.getM_InOutLine_ID(), as, trxName);
}
//Create Sales Order Order Credit by 5
dateAcct = TimeUtil.addDays(today, 60);
MOrder sales2 = createSalesOrder(dateAcct, new BigDecimal(10), new BigDecimal(45));
for (MOrderLine line : sales2.getLines()) {
CostResult costResult = new CostResult(product.getM_Product_ID(), new BigDecimal("43.8065"), new BigDecimal("25"), new BigDecimal("1095.1638"), new BigDecimal("438.0650"), new BigDecimal("0"), new BigDecimal("-10"), new BigDecimal("43.8065"), new BigDecimal("35"), new BigDecimal("1533.2288"), dateAcct);
assertCostShipment(costResult, line.getC_OrderLine_ID(), as, trxName);
}
dateAcct = receipt1.getDateAcct();
int M_InOutLine_ID = 0;
for (MInOutLine line : receipt1.getLines()) {
M_InOutLine_ID = line.getM_InOutLine_ID();
MInvoice invoice = createInvoiceVendor(dateAcct, new BigDecimal(10), new BigDecimal(38), line.getM_InOutLine_ID());
}
CostResult costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("44.2827"), // cumulateQty
new BigDecimal("25"), //cumulateAmt
new BigDecimal("1107.0688"), //cdAmt
new BigDecimal("380.0000"), //cdAdjutment
new BigDecimal("20.0000"), //cdQty
new BigDecimal("10"), //cdCurrentCostPrice
new BigDecimal("53.5937"), //cdCumulateQty
new BigDecimal("20"), //cdCumulateAmt
new BigDecimal("1071.8748"), dateAcct);
assertCostInvoice(costResult, M_InOutLine_ID, as, trxName);
dateAcct = Timestamp.valueOf("2010-01-16 00:00:00.0");
for (MOrderLine line : sales1.getLines()) {
costResult = new CostResult(line.getM_Product_ID(), new BigDecimal("44.2827"), new BigDecimal("25"), new BigDecimal("1107.0688"), new BigDecimal("241.9790"), new BigDecimal("0"), new BigDecimal("-5"), new BigDecimal("48.3958"), new BigDecimal("30"), new BigDecimal("1451.8748"), dateAcct);
assertCostShipmentAdjust(costResult, line.getC_OrderLine_ID(), as, trxName);
}
//Reverse Material Receipt
dateAcct = today;
receipt1.processIt(DocAction.ACTION_Reverse_Correct);
receipt1.saveEx();
for (MInOutLine line : receipt1.getLines(true)) {
costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("44.2827"), // cumulateQty
new BigDecimal("25"), //cumulateAmt
new BigDecimal("1107.0688"), //cdAmt
new BigDecimal("380.0000"), //cdAdjutment
new BigDecimal("20.0000"), //cdQty
new BigDecimal("10"), //cdCurrentCostPrice
new BigDecimal("53.5937"), //cdCumulateQty
new BigDecimal("20"), //cdCumulateAmt
new BigDecimal("1071.8748"), dateAcct);
assertCostReceiptReversal(costResult, line.getM_InOutLine_ID(), as, trxName);
}
MInOut reversal = new MInOut(getCtx(), receipt1.getReversal_ID(), trxName);
for (MInOutLine line : reversal.getLines(true)) {
costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("46.8373"), // cumulateQty
new BigDecimal("19"), //cumulateAmt
new BigDecimal("889.9081"), //cdAmt
new BigDecimal("380"), //cdAdjutment
new BigDecimal("20"), //cdQty
new BigDecimal("-10"), //cdCurrentCostPrice
new BigDecimal("49.0073"), //cdCumulateQty
new BigDecimal("34"), //cdCumulateAmt
new BigDecimal("1666.2496"), dateAcct);
assertCostReceiptReversal(costResult, line.getM_InOutLine_ID(), as, trxName);
}
//Second Purchase Receipt 7 day forward
dateAcct = TimeUtil.addDays(today, 7);
MOrder purchase3 = createPurchaseOrder(dateAcct, new BigDecimal(100), new BigDecimal(37));
MInOut receipt3 = null;
for (MOrderLine line : purchase3.getLines()) {
receipt3 = createMaterialReceipt(dateAcct, new BigDecimal(20), line.getC_OrderLine_ID());
}
for (MInOutLine line : receipt3.getLines()) {
costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("42.0489"), // cumulateQty
new BigDecimal("45"), //cumulateAmt
new BigDecimal("1892.1983"), //cdAmt
new BigDecimal("876.7500"), //cdAdjutment
new BigDecimal("0"), //cdQty
new BigDecimal("20"), //cdCurrentCostPrice
new BigDecimal("48.3958"), //cdCumulateQty
new BigDecimal("30"), //cdCumulateAmt
new BigDecimal("1451.8748"), dateAcct);
assertCostReceipt(costResult, line.getM_InOutLine_ID(), as, trxName);
}
dateAcct = TimeUtil.addDays(today, 65);
MMovement move = createMovement(dateAcct, new BigDecimal("5"));
for (MMovementLine line : move.getLines(true)) {
costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("53.5938"), // cumulateQty
new BigDecimal("9"), //cumulateAmt
new BigDecimal("482.3442"), //cdAmt
new BigDecimal("267.9690"), //cdAdjutment
new BigDecimal("0"), //cdQty
new BigDecimal("5"), //cdCurrentCostPrice
new BigDecimal("53.5938"), //cdCumulateQty
new BigDecimal("4"), //cdCumulateAmt
new BigDecimal("214.3752"), dateAcct);
assertCostMovement(costResult, line.getM_MovementLine_ID(), as, trxName);
}
dateAcct = TimeUtil.addDays(today, 70);
MInventory inventory = createPhisicalInventory(dateAcct, new BigDecimal("20"), costResult.cumulateQty);
for (MInventoryLine line : inventory.getLines(true)) {
costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("42.0488"), // cumulateQty
new BigDecimal("51"), //cumulateAmt
new BigDecimal("2144.4906"), //cdAmt
new BigDecimal("462.5368"), //cdAdjutment
new BigDecimal("0"), //cdQty
new BigDecimal("11"), //cdCurrentCostPrice
new BigDecimal("42.0488"), //cdCumulateQty
new BigDecimal("40"), //cdCumulateAmt
new BigDecimal("1681.9538"), dateAcct);
assertCostPhisicalInventory(costResult, line.getM_InventoryLine_ID(), as, trxName);
break;
}
dateAcct = TimeUtil.addDays(today, 80);
inventory = createInvetoryInternalUse(dateAcct, new BigDecimal("-5"));
for (MInventoryLine line : inventory.getLines(true)) {
costResult = new CostResult(product.getM_Product_ID(), //currentCostPrice
new BigDecimal("42.0488"), // cumulateQty
new BigDecimal("56"), //cumulateAmt
new BigDecimal("2354.7346"), //cdAmt
new BigDecimal("210.2440"), //cdAdjutment
new BigDecimal("0"), //cdQty
new BigDecimal("5"), //cdCurrentCostPrice
new BigDecimal("42.0488"), //cdCumulateQty
new BigDecimal("51"), //cdCumulateAmt
new BigDecimal("2144.4906"), dateAcct);
assertCostPhisicalInventory(costResult, line.getM_InventoryLine_ID(), as, trxName);
;
}
createTrxAndInventoryValuationReport();
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class InventoryUtil method createInOut.
public static MInOut createInOut(MMDocument doc, String trxName) {
MOrder order;
if (MDocType.DOCBASETYPE_MaterialReceipt.equals(doc.DocBaseType)) {
order = (MOrder) doc.scenario.get(MDocType.DOCBASETYPE_PurchaseOrder, doc.PODocumentNo).document;
} else if (MDocType.DOCBASETYPE_MaterialDelivery.equals(doc.DocBaseType)) {
order = (MOrder) doc.scenario.get(MDocType.DOCBASETYPE_SalesOrder, doc.PODocumentNo).document;
} else {
throw new IllegalArgumentException("DocBaseType not supported - " + doc);
}
// if (trxName != null && trxName.equals(order.get_TrxName()))
// throw new AdempiereException("Internal exception - not same trxName");
MInOut io = new MInOut(order, 0, doc.Date);
setGeneratedTag(io);
io.saveEx();
//
MInOutLine iol = null;
for (MOrderLine oline : order.getLines(true, null)) {
iol = new MInOutLine(io);
iol.setOrderLine(oline, 0, doc.Qty);
iol.setQty(doc.Qty);
iol.saveEx();
break;
}
final boolean checkPrice = (doc.Price != null && doc.Price.signum() != 0);
// Check Receipt Price Match
if (checkPrice && !io.isSOTrx()) {
BigDecimal receiptPrice = iol.getPriceActual();
if (doc.Price.compareTo(receiptPrice) != 0) {
throw new RuntimeException("MMR - Price Not Match - target=" + doc.Price + ", actual=" + iol.getPriceActual());
}
}
//
doc.document = io;
processDocument(doc, MInOut.DOCACTION_Complete, MInOut.DOCSTATUS_Completed);
if (!Util.isEmpty(doc.ASI)) {
iol.load(trxName);
doc.scenario.registerASICode(doc.ASI, iol.getM_AttributeSetInstance_ID(), !io.isSOTrx());
}
checkLineCosts(doc, iol, io.isSOTrx());
return io;
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class LiberoValidator method modelChange.
// initialize
public String modelChange(PO po, int type) throws Exception {
log.info(po.get_TableName() + " Type: " + type);
boolean isChange = (TYPE_AFTER_NEW == type || (TYPE_AFTER_CHANGE == type && MPPMRP.isChanged(po)));
boolean isDelete = (TYPE_BEFORE_DELETE == type);
boolean isReleased = false;
boolean isVoided = false;
//Update MRP Change Net
if (MPPMRP.isChanged(po) && (TYPE_AFTER_CHANGE == type || TYPE_AFTER_NEW == type)) {
MPPMRP.setIsRequired(po, MPPProductPlanning.COLUMNNAME_IsRequiredMRP, true, po.get_TrxName());
}
DocAction doc = null;
if (po instanceof DocAction) {
doc = (DocAction) po;
} else if (po instanceof MOrderLine) {
doc = ((MOrderLine) po).getParent();
}
if (doc != null) {
String docStatus = doc.getDocStatus();
isReleased = DocAction.STATUS_InProgress.equals(docStatus) || DocAction.STATUS_Completed.equals(docStatus);
isVoided = DocAction.STATUS_Voided.equals(docStatus);
}
// Can we change M_Product.C_UOM_ID ?
if (po instanceof MProduct && TYPE_BEFORE_CHANGE == type && po.is_ValueChanged(MProduct.COLUMNNAME_C_UOM_ID) && MPPMRP.hasProductRecords((MProduct) po)) {
throw new AdempiereException("@SaveUomError@");
}
//
if (isDelete || isVoided || !po.isActive()) {
if (MOrder.Table_Name.equals(po.get_TableName()) || MOrderLine.Table_Name.equals(po.get_TableName()) || MPPOrder.Table_Name.equals(po.get_TableName()) || MPPOrderBOMLine.Table_Name.equals(po.get_TableName()) || MDDOrder.Table_Name.equals(po.get_TableName()) || MDDOrderLine.Table_Name.equals(po.get_TableName()) || MRequisition.Table_Name.equals(po.get_TableName()) || MRequisitionLine.Table_Name.equals(po.get_TableName()) || MForecast.Table_Name.equals(po.get_TableName()) || MForecastLine.Table_Name.equals(po.get_TableName()))
MPPMRP.deleteMRP(po);
} else if (po instanceof MOrder) {
MOrder order = (MOrder) po;
// or when you change DatePromised or DocStatus and is Purchase Order
if (isChange && !order.isSOTrx()) {
MPPMRP.C_Order(order);
} else // or you change DatePromised
if (type == TYPE_AFTER_CHANGE && order.isSOTrx()) {
if (isReleased || MPPMRP.isChanged(order)) {
MPPMRP.C_Order(order);
}
}
} else //
if (po instanceof MOrderLine && isChange) {
MOrderLine ol = (MOrderLine) po;
MOrder order = ol.getParent();
// Create/Update a planning supply when isPurchase Order or you change relevant fields
if (!order.isSOTrx()) {
MPPMRP.C_OrderLine(ol);
} else // you change relevant fields
if (order.isSOTrx() && isReleased) {
MPPMRP.C_OrderLine(ol);
}
} else //
if (po instanceof MRequisition && isChange) {
MRequisition r = (MRequisition) po;
MPPMRP.M_Requisition(r);
} else //
if (po instanceof MRequisitionLine && isChange) {
MRequisitionLine rl = (MRequisitionLine) po;
MPPMRP.M_RequisitionLine(rl);
} else //
if (po instanceof MForecast && isChange) {
MForecast fl = (MForecast) po;
MPPMRP.M_Forecast(fl);
} else //
if (po instanceof MForecastLine && isChange) {
MForecastLine fl = (MForecastLine) po;
MPPMRP.M_ForecastLine(fl);
} else if (po instanceof MDDOrder && isChange) {
MDDOrder order = (MDDOrder) po;
MPPMRP.DD_Order(order);
} else //
if (po instanceof MDDOrderLine && isChange) {
MDDOrderLine ol = (MDDOrderLine) po;
MPPMRP.DD_OrderLine(ol);
} else //
if (po instanceof MPPOrder && isChange) {
MPPOrder order = (MPPOrder) po;
MPPMRP.PP_Order(order);
} else //
if (po instanceof MPPOrderBOMLine && isChange) {
MPPOrderBOMLine obl = (MPPOrderBOMLine) po;
MPPMRP.PP_Order_BOMLine(obl);
}
//
return null;
}
Aggregations