use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class CostResult method createMaterialReceipt.
public MInOut createMaterialReceipt(Timestamp movementDate, BigDecimal qtyMovement, int C_OrderLine_ID) {
// Create Material Receipt
MInOut receipt = new MInOut(getCtx(), 0, trxName);
receipt.setAD_Org_ID(Env.getAD_Org_ID(getCtx()));
receipt.setC_DocType_ID(MDocType.getDocType(MDocType.DOCBASETYPE_MaterialReceipt));
receipt.setC_BPartner_ID(bp.getC_BPartner_ID());
receipt.setC_BPartner_Location_ID(bpls[0].getC_BPartner_Location_ID());
receipt.setMovementDate(movementDate);
receipt.setDateAcct(movementDate);
receipt.setIsSOTrx(false);
receipt.setM_Warehouse_ID(w.getM_Warehouse_ID());
receipt.setMovementType(MInOut.MOVEMENTTYPE_VendorReceipts);
receipt.saveEx();
// Create Material Receipt Line
MInOutLine receiptLine = new MInOutLine(receipt);
receiptLine.setC_OrderLine_ID(C_OrderLine_ID);
receiptLine.setM_Product_ID(product.getM_Product_ID());
receiptLine.setMovementQty(qtyMovement);
receiptLine.setM_Locator_ID(qtyMovement);
receiptLine.saveEx();
// Complete Receipt
receipt.setDocStatus(DocAction.STATUS_Drafted);
receipt.setDocAction(DocAction.ACTION_Complete);
receipt.processIt(DocAction.ACTION_Complete);
receipt.saveEx();
return receipt;
}
use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class ModelValidator method docValidate.
public String docValidate(PO po, int timing) {
log.info(po.get_TableName() + " Timing: " + timing);
String result = null;
// TABLE C_Invoice
String tableName = po.get_TableName();
if (tableName.equals(MInvoice.Table_Name)) {
// Invoice - Validate Fixed Assets Invoice (LRO)
if (timing == TIMING_AFTER_PREPARE) {
MInvoice invoice = (MInvoice) po;
validateFixedAssetsInvoice_LRO(invoice);
}
if (timing == TIMING_AFTER_COMPLETE) {
MInvoice mi = (MInvoice) po;
if (mi.isSOTrx()) {
MInvoiceLine[] mils = mi.getLines();
for (MInvoiceLine mil : mils) {
if (mil.isA_CreateAsset() && !mil.isA_Processed()) {
MAssetDisposed.createAssetDisposed(mil);
}
}
}
}
if (timing == TIMING_AFTER_VOID) {
MInvoice invoice = (MInvoice) po;
String error = afterVoid(invoice);
if (error != null)
return error;
}
if (timing == TIMING_BEFORE_REVERSECORRECT) {
MInvoice invoice = (MInvoice) po;
String error = beforeReverseCorrect(invoice);
if (error != null)
return error;
}
}
if (tableName.equals(MInOut.Table_Name)) {
if (timing == TIMING_AFTER_COMPLETE) {
MInOut inOut = (MInOut) po;
for (MInOutLine inOutLine : inOut.getLines()) {
MProduct product = inOutLine.getProduct();
// Create Asset for SO
if (product != null && inOut.isSOTrx() && product.isCreateAsset() && !product.getM_Product_Category().getA_Asset_Group().isFixedAsset() && inOutLine.getMovementQty().signum() > 0 && !inOut.isReversal()) {
log.fine("Asset");
//info.append("@A_Asset_ID@: ");
int noAssets = inOutLine.getMovementQty().intValue();
if (!product.isOneAssetPerUOM())
noAssets = 1;
for (int i = 0; i < noAssets; i++) {
//if (i > 0)
// info.append(" - ");
int deliveryCount = i + 1;
if (!product.isOneAssetPerUOM())
deliveryCount = 0;
MAsset asset = new MAsset(inOut, inOutLine, deliveryCount);
if (!asset.save(inOut.get_TrxName())) {
//return DocAction.STATUS_Invalid;
throw new IllegalStateException("Could not create Asset");
}
//info.append(asset.getValue());
}
}
}
// Asset
}
if (timing == TIMING_AFTER_REVERSECORRECT) {
MInOut inOut = (MInOut) po;
I_M_InOut inOutReversal = inOut.getReversal();
for (MInOutLine inOutLine : inOut.getLines()) {
// De-Activate Asset
MAsset asset = MAsset.getFromShipment(inOut.getCtx(), inOutLine.getM_InOutLine_ID(), inOut.get_TrxName());
if (asset != null) {
asset.setIsActive(false);
asset.setDescription(asset.getDescription() + " (" + inOutReversal.getDocumentNo() + " #" + inOutLine.getLine() + "<-)");
asset.saveEx();
}
}
}
}
return result;
}
Aggregations