Libero fixing:
* documents should update MRP each time they change * minor refactoring : removed pseudo-static methods like "getLines" (which are not static but are acting like static methods) * improved caching
This commit is contained in:
parent
25c29f07e0
commit
a3d6f0d768
|
@ -60,7 +60,7 @@ public class MPPMRP extends X_PP_MRP
|
|||
* @param PP_MRP_ID id
|
||||
* @param trxName Transaction Name
|
||||
*/
|
||||
public MPPMRP(Properties ctx, int PP_MRP_ID,String trxName)
|
||||
public MPPMRP(Properties ctx, int PP_MRP_ID, String trxName)
|
||||
{
|
||||
super(ctx, PP_MRP_ID,trxName);
|
||||
if (PP_MRP_ID == 0)
|
||||
|
@ -74,17 +74,41 @@ public class MPPMRP extends X_PP_MRP
|
|||
* @param ctx context
|
||||
* @param rs result set
|
||||
*/
|
||||
public MPPMRP(Properties ctx, ResultSet rs,String trxName)
|
||||
public MPPMRP(Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs , trxName);
|
||||
}
|
||||
|
||||
protected boolean afterSave(boolean newRecord, boolean success)
|
||||
|
||||
public void setPP_Order(MPPOrder o)
|
||||
{
|
||||
|
||||
if (!newRecord)
|
||||
return success;
|
||||
return true;
|
||||
setPP_Order_ID(o.getPP_Order_ID());
|
||||
setOrderType(ORDERTYPE_ManufacturingOrder);
|
||||
//
|
||||
setName(o.getDocumentNo());
|
||||
setDescription(o.getDescription());
|
||||
setDatePromised(o.getDatePromised());
|
||||
setDateOrdered(o.getDateOrdered());
|
||||
setDateStartSchedule(o.getDateStartSchedule());
|
||||
setDateFinishSchedule(o.getDateFinishSchedule());
|
||||
setS_Resource_ID(o.getS_Resource_ID());
|
||||
setDocStatus(o.getDocStatus());
|
||||
}
|
||||
|
||||
public void setC_Order(MOrder o)
|
||||
{
|
||||
setC_Order_ID(o.get_ID());
|
||||
setC_BPartner_ID(o.getC_BPartner_ID());
|
||||
setDocStatus(o.getDocStatus());
|
||||
if (o.isSOTrx())
|
||||
{
|
||||
setOrderType(MPPMRP.ORDERTYPE_SalesOrder);
|
||||
setTypeMRP(MPPMRP.TYPEMRP_Demand);
|
||||
}
|
||||
else
|
||||
{
|
||||
setOrderType(MPPMRP.ORDERTYPE_PurchaseOrder);
|
||||
setTypeMRP(MPPMRP.TYPEMRP_Supply);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,7 +119,8 @@ public class MPPMRP extends X_PP_MRP
|
|||
public static void M_ForecastLine(X_M_ForecastLine fl, boolean delete)
|
||||
{
|
||||
String trxName = fl.get_TrxName();
|
||||
Properties ctx =fl.getCtx();
|
||||
Properties ctx = fl.getCtx();
|
||||
|
||||
if (delete)
|
||||
{
|
||||
final String sql = "DELETE FROM PP_MRP WHERE M_ForecastLine_ID=? AND AD_Client_ID=?";
|
||||
|
@ -121,9 +146,9 @@ public class MPPMRP extends X_PP_MRP
|
|||
mrp.setName("MRP");
|
||||
mrp.setQty(fl.getQty());
|
||||
mrp.setDatePromised(fl.getDatePromised());
|
||||
mrp.setDateStartSchedule(mrp.getDatePromised());
|
||||
mrp.setDateFinishSchedule(mrp.getDatePromised());
|
||||
mrp.setDateOrdered(mrp.getDatePromised());
|
||||
mrp.setDateStartSchedule(fl.getDatePromised());
|
||||
mrp.setDateFinishSchedule(fl.getDatePromised());
|
||||
mrp.setDateOrdered(fl.getDatePromised());
|
||||
mrp.setM_Product_ID(fl.getM_Product_ID());
|
||||
mrp.setM_Warehouse_ID(fl.getM_Warehouse_ID());
|
||||
mrp.setDocStatus(DocAction.STATUS_InProgress);
|
||||
|
@ -139,21 +164,27 @@ public class MPPMRP extends X_PP_MRP
|
|||
public static void C_Order(MOrder o, boolean delete)
|
||||
{
|
||||
String trxName = o.get_TrxName();
|
||||
|
||||
final String whereClause = COLUMNNAME_C_Order_ID+"=? AND AD_Client_ID=?";
|
||||
Object[] params = new Object[]{o.get_ID(), o.getAD_Client_ID()};
|
||||
|
||||
if (delete)
|
||||
{
|
||||
final String sql = "DELETE FROM PP_MRP WHERE "+whereClause;
|
||||
DB.executeUpdateEx(sql, params, trxName);
|
||||
return;
|
||||
}
|
||||
if (o.is_ValueChanged(MOrder.COLUMNNAME_DocStatus))
|
||||
|
||||
if (o.is_ValueChanged(MOrder.COLUMNNAME_DocStatus)
|
||||
|| o.is_ValueChanged(MOrder.COLUMNNAME_C_BPartner_ID)
|
||||
)
|
||||
{
|
||||
List<MPPMRP> list = new Query(o.getCtx(), MPPMRP.Table_Name, whereClause, trxName)
|
||||
.setParameters(params)
|
||||
.list();
|
||||
for (MPPMRP mrp : list) {
|
||||
mrp.setDocStatus(o.getDocStatus());
|
||||
for (MPPMRP mrp : list)
|
||||
{
|
||||
mrp.setC_Order(o);
|
||||
mrp.saveEx();
|
||||
}
|
||||
}
|
||||
|
@ -189,21 +220,11 @@ public class MPPMRP extends X_PP_MRP
|
|||
.first();
|
||||
if(mrp == null)
|
||||
{
|
||||
mrp = new MPPMRP(ctx, 0,trxName);
|
||||
mrp = new MPPMRP(ctx, 0, trxName);
|
||||
mrp.setAD_Org_ID(ol.getAD_Org_ID());
|
||||
mrp.setC_Order_ID(ol.getC_Order_ID());
|
||||
mrp.setC_OrderLine_ID(ol.getC_OrderLine_ID());
|
||||
if (ol.getParent().isSOTrx())
|
||||
{
|
||||
mrp.setOrderType(MPPMRP.ORDERTYPE_SalesOrder);
|
||||
mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand);
|
||||
}
|
||||
else
|
||||
{
|
||||
mrp.setOrderType(MPPMRP.ORDERTYPE_PurchaseOrder);
|
||||
mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply);
|
||||
}
|
||||
}
|
||||
mrp.setC_Order(ol.getParent());
|
||||
mrp.setDescription(ol.getDescription());
|
||||
mrp.setName("MRP");
|
||||
mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered()));
|
||||
|
@ -213,8 +234,6 @@ public class MPPMRP extends X_PP_MRP
|
|||
mrp.setDateOrdered(ol.getDateOrdered());
|
||||
mrp.setM_Product_ID(ol.getM_Product_ID());
|
||||
mrp.setM_Warehouse_ID(ol.getM_Warehouse_ID());
|
||||
mrp.setC_BPartner_ID(ol.getParent().getC_BPartner_ID());
|
||||
mrp.setDocStatus(ol.getParent().getDocStatus());
|
||||
mrp.saveEx();
|
||||
|
||||
MPPOrder order = new Query(ctx, MPPOrder.Table_Name, whereClause, trxName)
|
||||
|
@ -289,40 +308,45 @@ public class MPPMRP extends X_PP_MRP
|
|||
*/
|
||||
public static void PP_Order(MPPOrder o, boolean delete)
|
||||
{
|
||||
|
||||
String sql = null;
|
||||
Properties ctx = o.getCtx();
|
||||
String trxName = o.get_TrxName();
|
||||
Properties m_ctx = o.getCtx();
|
||||
|
||||
if (delete)
|
||||
{
|
||||
sql = "DELETE FROM PP_MRP WHERE PP_Order_ID = "+ o.getPP_Order_ID() +" AND AD_Client_ID = " + o.getAD_Client_ID();
|
||||
DB.executeUpdateEx(sql ,trxName);
|
||||
String sql = "DELETE FROM PP_MRP WHERE PP_Order_ID=? AND AD_Client_ID=?";
|
||||
Object[] params = new Object[]{o.getPP_Order_ID(), o.getAD_Client_ID()};
|
||||
DB.executeUpdateEx(sql, params, trxName);
|
||||
return;
|
||||
}
|
||||
String whereClause = "TypeMRP=? AND OrderType=? AND AD_Client_ID=? AND PP_Order_ID=?";
|
||||
MPPMRP mrp = new Query(m_ctx, MPPMRP.Table_Name, whereClause, trxName)
|
||||
.setParameters(new Object[]{MPPMRP.TYPEMRP_Supply, MPPMRP.ORDERTYPE_ManufacturingOrder, o.getAD_Client_ID() , o.getPP_Order_ID()})
|
||||
.first();
|
||||
if(mrp == null)
|
||||
|
||||
//
|
||||
// Supply
|
||||
final String whereClause = "TypeMRP=? AND OrderType=? AND AD_Client_ID=? AND PP_Order_ID=?";
|
||||
MPPMRP mrpSupply = new Query(ctx, MPPMRP.Table_Name, whereClause, trxName)
|
||||
.setParameters(new Object[]{MPPMRP.TYPEMRP_Supply, MPPMRP.ORDERTYPE_ManufacturingOrder, o.getAD_Client_ID(), o.getPP_Order_ID()})
|
||||
.first();
|
||||
if(mrpSupply == null)
|
||||
{
|
||||
mrp = new MPPMRP(m_ctx, 0, trxName);
|
||||
mrp.setAD_Org_ID(o.getAD_Org_ID());
|
||||
mrp.setPP_Order_ID(o.getPP_Order_ID());
|
||||
mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply);
|
||||
mrp.setOrderType(MPPMRP.ORDERTYPE_ManufacturingOrder);
|
||||
mrpSupply = new MPPMRP(ctx, 0, trxName);
|
||||
mrpSupply.setAD_Org_ID(o.getAD_Org_ID());
|
||||
mrpSupply.setTypeMRP(MPPMRP.TYPEMRP_Supply);
|
||||
}
|
||||
mrpSupply.setPP_Order(o);
|
||||
mrpSupply.setQty(o.getQtyOrdered().subtract(o.getQtyDelivered()));
|
||||
mrpSupply.setM_Product_ID(o.getM_Product_ID());
|
||||
mrpSupply.setM_Warehouse_ID(o.getM_Warehouse_ID());
|
||||
mrpSupply.saveEx();
|
||||
|
||||
//
|
||||
// Demand
|
||||
List<MPPMRP> demand = new Query(ctx, MPPMRP.Table_Name, whereClause, trxName)
|
||||
.setParameters(new Object[]{MPPMRP.TYPEMRP_Demand, MPPMRP.ORDERTYPE_ManufacturingOrder, o.getAD_Client_ID(), o.getPP_Order_ID()})
|
||||
.list();
|
||||
for (MPPMRP mrpDemand : demand)
|
||||
{
|
||||
mrpDemand.setPP_Order(o);
|
||||
mrpDemand.saveEx();
|
||||
}
|
||||
mrp.setDescription(o.getDescription());
|
||||
mrp.setName(o.getDocumentNo());
|
||||
mrp.setQty(o.getQtyOrdered().subtract(o.getQtyDelivered()));
|
||||
mrp.setDatePromised(o.getDatePromised());
|
||||
mrp.setDateOrdered(o.getDateOrdered());
|
||||
mrp.setDateStartSchedule(o.getDateStartSchedule());
|
||||
mrp.setDateFinishSchedule(o.getDateStartSchedule());
|
||||
mrp.setM_Product_ID(o.getM_Product_ID());
|
||||
mrp.setM_Warehouse_ID(o.getM_Warehouse_ID());
|
||||
mrp.setS_Resource_ID(o.getS_Resource_ID());
|
||||
mrp.setDocStatus(o.getDocStatus());
|
||||
mrp.saveEx();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -348,24 +372,15 @@ public class MPPMRP extends X_PP_MRP
|
|||
MPPOrder o = obl.getParent();
|
||||
if(mrp == null)
|
||||
{
|
||||
mrp = new MPPMRP(ctx, 0, trxName);
|
||||
mrp = new MPPMRP(ctx, 0, trxName);
|
||||
mrp.setAD_Org_ID(obl.getAD_Org_ID());
|
||||
mrp.setPP_Order_BOMLine_ID(obl.getPP_Order_BOMLine_ID());
|
||||
mrp.setPP_Order_ID(o.getPP_Order_ID());
|
||||
mrp.setOrderType(MPPMRP.ORDERTYPE_ManufacturingOrder);
|
||||
mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand);
|
||||
}
|
||||
mrp.setName(o.getDocumentNo());
|
||||
mrp.setDescription(o.getDescription());
|
||||
mrp.setPP_Order(o);
|
||||
mrp.setQty(obl.getQtyRequiered().subtract(obl.getQtyDelivered()));
|
||||
mrp.setDatePromised(o.getDatePromised());
|
||||
mrp.setDateOrdered(o.getDateOrdered());
|
||||
mrp.setDateStartSchedule(o.getDateStartSchedule());
|
||||
mrp.setDateFinishSchedule(o.getDateFinishSchedule());
|
||||
mrp.setM_Product_ID(obl.getM_Product_ID());
|
||||
mrp.setM_Warehouse_ID(obl.getM_Warehouse_ID());
|
||||
mrp.setS_Resource_ID(o.getS_Resource_ID());
|
||||
mrp.setDocStatus(o.getDocStatus());
|
||||
mrp.saveEx();
|
||||
}
|
||||
|
||||
|
|
|
@ -39,13 +39,11 @@ import org.compiere.model.ModelValidator;
|
|||
import org.compiere.model.PO;
|
||||
import org.compiere.model.POResultSet;
|
||||
import org.compiere.model.Query;
|
||||
import org.compiere.model.X_C_DocType;
|
||||
import org.compiere.print.ReportEngine;
|
||||
import org.compiere.process.DocAction;
|
||||
import org.compiere.process.DocumentEngine;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Util;
|
||||
import org.compiere.wf.MWFNode;
|
||||
import org.compiere.wf.MWFNodeNext;
|
||||
import org.compiere.wf.MWorkflow;
|
||||
|
@ -217,15 +215,6 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
super(ctx, rs, trxName);
|
||||
} // MOrder
|
||||
|
||||
/**
|
||||
* Overwrite Client/Org if required
|
||||
* @param AD_Client_ID client
|
||||
* @param AD_Org_ID org
|
||||
*/
|
||||
public void setClientOrg(int AD_Client_ID, int AD_Org_ID) {
|
||||
super.setClientOrg(AD_Client_ID, AD_Org_ID);
|
||||
} // setClientOrg
|
||||
|
||||
/**
|
||||
* @return Open Qty
|
||||
*/
|
||||
|
@ -234,58 +223,31 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
return getQtyOrdered().subtract(getQtyDelivered()).subtract(getQtyScrap());
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("MPPOrder[").append(get_ID())
|
||||
.append("-").append(getDocumentNo())
|
||||
.append(",IsSOTrx=").append(isSOTrx())
|
||||
.append(",C_DocType_ID=").append(getC_DocType_ID())
|
||||
.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
/**************************************************************************
|
||||
/**
|
||||
* Get BOM Lines of PP Order
|
||||
* @param whereClause where clause or null
|
||||
* @param orderClause order by clause or null
|
||||
* @return invoices
|
||||
* @return Order BOM Lines
|
||||
*/
|
||||
public MPPOrderBOMLine[] getLines(String whereClause, String orderClause)
|
||||
public MPPOrderBOMLine[] getLines()
|
||||
{
|
||||
StringBuffer whereClauseFinal = new StringBuffer(MPPOrderBOMLine.COLUMNNAME_PP_Order_ID).append("=?");
|
||||
if (!Util.isEmpty(whereClause, true))
|
||||
whereClauseFinal.append("AND (").append(whereClause).append(")");
|
||||
String whereClause = MPPOrderBOMLine.COLUMNNAME_PP_Order_ID+"=?";
|
||||
//
|
||||
List<MPPOrderBOMLine> list = new Query(getCtx(), MPPOrderBOMLine.Table_Name, whereClauseFinal.toString(), get_TrxName())
|
||||
.setParameters(new Object[]{getPP_Order_ID()})
|
||||
.setOrderBy(orderClause)
|
||||
.list();
|
||||
List<MPPOrderBOMLine> list = new Query(getCtx(), MPPOrderBOMLine.Table_Name, whereClause, get_TrxName())
|
||||
.setParameters(new Object[]{getPP_Order_ID()})
|
||||
.setOrderBy(MPPOrderBOMLine.COLUMNNAME_Line)
|
||||
.list();
|
||||
return list.toArray(new MPPOrderBOMLine[list.size()]);
|
||||
} // getLines
|
||||
|
||||
|
||||
public MPPOrderBOMLine[] getLines() {
|
||||
return getLines(null, null);
|
||||
} // getLines
|
||||
|
||||
/**
|
||||
* Set Processed.
|
||||
* Propergate to Lines/Taxes
|
||||
* @param processed processed
|
||||
*/
|
||||
@Override
|
||||
public void setProcessed(boolean processed)
|
||||
{
|
||||
super.setProcessed(processed);
|
||||
|
||||
// Update DB:
|
||||
if (get_ID() == 0)
|
||||
if (get_ID() <= 0)
|
||||
return;
|
||||
String sql = "UPDATE PP_Order SET Processed=? WHERE PP_Order_ID=?";
|
||||
DB.executeUpdateEx(sql, new Object[]{(processed ? "Y" : "N"), get_ID()}, get_TrxName());
|
||||
final String sql = "UPDATE PP_Order SET Processed=? WHERE PP_Order_ID=?";
|
||||
DB.executeUpdateEx(sql, new Object[]{processed, get_ID()}, get_TrxName());
|
||||
} // setProcessed
|
||||
|
||||
@Override
|
||||
|
@ -326,10 +288,12 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
@Override
|
||||
protected boolean afterSave(boolean newRecord, boolean success)
|
||||
{
|
||||
if (!success) {
|
||||
if (!success)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!newRecord) {
|
||||
if (!newRecord)
|
||||
{
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -404,6 +368,7 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
return true;
|
||||
} // beforeSave
|
||||
|
||||
@Override
|
||||
protected boolean beforeDelete()
|
||||
{
|
||||
// OrderBOMLine
|
||||
|
@ -440,77 +405,63 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
/** Just Prepared Flag */
|
||||
private boolean m_justPrepared = false;
|
||||
|
||||
/**
|
||||
* Unlock Document.
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean unlockIt() {
|
||||
public boolean unlockIt()
|
||||
{
|
||||
log.info("unlockIt - " + toString());
|
||||
setProcessing(false);
|
||||
return true;
|
||||
} // unlockIt
|
||||
|
||||
/**
|
||||
* Invalidate Document
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean invalidateIt() {
|
||||
public boolean invalidateIt()
|
||||
{
|
||||
log.info("invalidateIt - " + toString());
|
||||
setDocAction(DOCACTION_Prepare);
|
||||
return true;
|
||||
} // invalidateIt
|
||||
|
||||
/**************************************************************************
|
||||
* Prepare Document
|
||||
* @return new status (In Progress or Invalid)
|
||||
*/
|
||||
public String prepareIt() {
|
||||
public String prepareIt()
|
||||
{
|
||||
log.info("prepareIt - " + toString());
|
||||
log.info(toString());
|
||||
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE);
|
||||
if (m_processMsg != null)
|
||||
return DocAction.STATUS_Invalid;
|
||||
|
||||
// Std Period open?
|
||||
/*if (!MPeriod.isOpen(getCtx(), getDateAcct(), dt.getDocBaseType()))
|
||||
{
|
||||
m_processMsg = "@PeriodClosed@";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}*/
|
||||
|
||||
// Lines
|
||||
MPPOrderBOMLine[] lines = getLines(null, MPPOrderBOMLine.COLUMNNAME_M_Product_ID);
|
||||
if (lines.length == 0) {
|
||||
MPPOrderBOMLine[] lines = getLines();
|
||||
if (lines.length == 0)
|
||||
{
|
||||
m_processMsg = "@NoLines@";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
|
||||
// Cannot change Std to anything else if different warehouses
|
||||
if (getC_DocType_ID() != 0) {
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
if (lines[i].getM_Warehouse_ID() != getM_Warehouse_ID()) {
|
||||
if (getC_DocType_ID() != 0)
|
||||
{
|
||||
for (int i = 0; i < lines.length; i++)
|
||||
{
|
||||
if (lines[i].getM_Warehouse_ID() != getM_Warehouse_ID())
|
||||
{
|
||||
log.warning("different Warehouse " + lines[i]);
|
||||
m_processMsg = "@CannotChangeDocType@";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
// New or in Progress/Invalid
|
||||
if (DOCSTATUS_Drafted.equals(getDocStatus()) || DOCSTATUS_InProgress.equals(getDocStatus()) || DOCSTATUS_Invalid.equals(getDocStatus())
|
||||
|| getC_DocType_ID() == 0) {
|
||||
if (DOCSTATUS_Drafted.equals(getDocStatus())
|
||||
|| DOCSTATUS_InProgress.equals(getDocStatus())
|
||||
|| DOCSTATUS_Invalid.equals(getDocStatus())
|
||||
|| getC_DocType_ID() == 0)
|
||||
{
|
||||
setC_DocType_ID(getC_DocTypeTarget_ID());
|
||||
}
|
||||
|
||||
MDocType doc = MDocType.get(getCtx(), getC_DocType_ID());
|
||||
if (doc.getDocBaseType().equals(X_C_DocType.DOCBASETYPE_QualityOrder))
|
||||
if (doc.getDocBaseType().equals(MDocType.DOCBASETYPE_QualityOrder))
|
||||
{
|
||||
return DocAction.STATUS_InProgress;
|
||||
|
||||
if (lines.length == 0) {
|
||||
m_processMsg = "@NoLines@";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
|
||||
reserveStock(lines);
|
||||
|
@ -521,8 +472,6 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
return DocAction.STATUS_Invalid;
|
||||
|
||||
m_justPrepared = true;
|
||||
// if (!DOCACTION_Complete.equals(getDocAction())) don't set for just prepare
|
||||
// setDocAction(DOCACTION_Complete);
|
||||
return DocAction.STATUS_InProgress;
|
||||
} // prepareIt
|
||||
|
||||
|
@ -572,9 +521,9 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
}
|
||||
|
||||
/**
|
||||
* Reserve Inventory.
|
||||
* @param lines order lines (ordered by M_Product_ID for deadlock prevention)
|
||||
* @return true if (un) reserved
|
||||
* Reserve Inventory.
|
||||
* @param lines order lines (ordered by M_Product_ID for deadlock prevention)
|
||||
* @return true if (un) reserved
|
||||
*/
|
||||
private void reserveStock(MPPOrderBOMLine[] lines)
|
||||
{
|
||||
|
@ -602,9 +551,11 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
+ ",Reserved=" + line.getQtyReserved() + ",Delivered=" + line.getQtyDelivered());
|
||||
|
||||
// Check Product - Stocked and Item
|
||||
MProduct product = line.getProduct();
|
||||
if (product != null) {
|
||||
if (product.isStocked()) {
|
||||
MProduct product = line.getM_Product();
|
||||
if (product != null)
|
||||
{
|
||||
if (product.isStocked())
|
||||
{
|
||||
//vpj BigDecimal ordered = isSOTrx ? Env.ZERO : difference;
|
||||
BigDecimal ordered = Env.ZERO;
|
||||
//BigDecimal reserved = isSOTrx ? difference : Env.ZERO;
|
||||
|
@ -633,17 +584,13 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
} // reverse inventory
|
||||
} // reserveStock
|
||||
|
||||
/**
|
||||
* Approve Document
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean approveIt()
|
||||
{
|
||||
log.info("approveIt - " + toString());
|
||||
MDocType doc = MDocType.get(getCtx(), getC_DocType_ID());
|
||||
if (doc.getDocBaseType().equals(X_C_DocType.DOCBASETYPE_QualityOrder))
|
||||
if (doc.getDocBaseType().equals(MDocType.DOCBASETYPE_QualityOrder))
|
||||
{
|
||||
String whereClause = "PP_Product_BOM_ID=? AND AD_Workflow_ID =?";
|
||||
String whereClause = COLUMNNAME_PP_Product_BOM_ID+"=? AND "+COLUMNNAME_AD_Workflow_ID+"=?";
|
||||
MQMSpecification qms = new Query(getCtx(), MQMSpecification.Table_Name, whereClause, get_TrxName())
|
||||
.setParameters(new Object[]{getPP_Product_BOM_ID(), getAD_Workflow_ID()})
|
||||
.first();
|
||||
|
@ -657,10 +604,6 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
return true;
|
||||
} // approveIt
|
||||
|
||||
/**
|
||||
* Reject Approval
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean rejectIt()
|
||||
{
|
||||
log.info("rejectIt - " + toString());
|
||||
|
@ -668,20 +611,18 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
return true;
|
||||
} // rejectIt
|
||||
|
||||
/**************************************************************************
|
||||
* Complete Document
|
||||
* @return new status (Complete, In Progress, Invalid, Waiting ..)
|
||||
*/
|
||||
public String completeIt()
|
||||
{
|
||||
// Just prepare
|
||||
if (DOCACTION_Prepare.equals(getDocAction())) {
|
||||
if (DOCACTION_Prepare.equals(getDocAction()))
|
||||
{
|
||||
setProcessed(false);
|
||||
return DocAction.STATUS_InProgress;
|
||||
}
|
||||
|
||||
// Re-Check
|
||||
if (!m_justPrepared) {
|
||||
if (!m_justPrepared)
|
||||
{
|
||||
String status = prepareIt();
|
||||
if (!DocAction.STATUS_InProgress.equals(status))
|
||||
return status;
|
||||
|
@ -695,43 +636,47 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
|
||||
// Implicit Approval
|
||||
if (!isApproved())
|
||||
{
|
||||
approveIt();
|
||||
}
|
||||
|
||||
StringBuffer info = new StringBuffer();
|
||||
|
||||
MAcctSchema acctSchema = MClient.get(getCtx(), getAD_Client_ID()).getAcctSchema();
|
||||
log.info("Cost_Group_ID" + acctSchema.getM_CostType_ID());
|
||||
|
||||
//
|
||||
// Create Standard Costs for Order
|
||||
MCost[] costs = MCost.getCosts(getCtx(), getAD_Client_ID(), getAD_Org_ID(), getM_Product_ID(),
|
||||
acctSchema.getM_CostType_ID(), acctSchema.get_ID(),
|
||||
get_TrxName());
|
||||
for (MCost cost : costs) {
|
||||
for (MCost cost : costs)
|
||||
{
|
||||
MPPOrderCost PP_Order_Cost = new MPPOrderCost(cost, get_ID(), get_TrxName());
|
||||
PP_Order_Cost.saveEx();
|
||||
}
|
||||
|
||||
for (MPPOrderBOMLine line : getLines()) {
|
||||
//
|
||||
// Create Standard Costs for Order BOM Line
|
||||
for (MPPOrderBOMLine line : getLines())
|
||||
{
|
||||
costs = MCost.getCosts(getCtx(), getAD_Client_ID(), getAD_Org_ID(), line.getM_Product_ID(),
|
||||
acctSchema.getM_CostType_ID(), acctSchema.get_ID(),
|
||||
get_TrxName());
|
||||
for (MCost cost : costs) {
|
||||
for (MCost cost : costs)
|
||||
{
|
||||
MPPOrderCost PP_Order_Cost = new MPPOrderCost(cost, get_ID(), get_TrxName());
|
||||
PP_Order_Cost.saveEx();
|
||||
}
|
||||
}
|
||||
|
||||
setProcessed(true);
|
||||
setDocAction(DOCACTION_Close);
|
||||
|
||||
String valid = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_COMPLETE);
|
||||
if (valid != null) {
|
||||
if (info.length() > 0) info.append(" - ");
|
||||
info.append(valid);
|
||||
m_processMsg = info.toString();
|
||||
if (valid != null)
|
||||
{
|
||||
m_processMsg = valid;
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
|
||||
setProcessed(true);
|
||||
m_processMsg = info.toString();
|
||||
//
|
||||
setDocAction(DOCACTION_Close);
|
||||
return DocAction.STATUS_Completed;
|
||||
} // completeIt
|
||||
|
||||
|
@ -744,17 +689,14 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
return !notAvailable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Void Document.
|
||||
* Set Qtys to 0 - Sales: reverse all documents
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean voidIt() {
|
||||
log.info("voidIt - " + toString());
|
||||
public boolean voidIt()
|
||||
{
|
||||
log.info(toString());
|
||||
// Before Void
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_BEFORE_VOID);
|
||||
if (m_processMsg != null)
|
||||
return false;
|
||||
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_AFTER_VOID);
|
||||
if (m_processMsg != null)
|
||||
return false;
|
||||
|
@ -764,11 +706,6 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
return true;
|
||||
} // voidIt
|
||||
|
||||
/**
|
||||
* Close Document.
|
||||
* Cancel not delivered Qunatities
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean closeIt()
|
||||
{
|
||||
log.info(toString());
|
||||
|
@ -779,7 +716,7 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
return false;
|
||||
|
||||
// Close Not delivered Qty - SO/PO
|
||||
MPPOrderBOMLine[] lines = getLines(null, MPPOrderBOMLine.COLUMNNAME_M_Product_ID);
|
||||
MPPOrderBOMLine[] lines = getLines();
|
||||
/*
|
||||
for (int i = 0; i < lines.length; i++)
|
||||
{
|
||||
|
@ -807,63 +744,51 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
return true;
|
||||
} // closeIt
|
||||
|
||||
/**
|
||||
* Reverse Correction - same void
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean reverseCorrectIt() {
|
||||
public boolean reverseCorrectIt()
|
||||
{
|
||||
log.info("reverseCorrectIt - " + toString());
|
||||
return voidIt();
|
||||
} // reverseCorrectionIt
|
||||
|
||||
/**
|
||||
* Reverse Accrual - none
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean reverseAccrualIt() {
|
||||
public boolean reverseAccrualIt()
|
||||
{
|
||||
log.info("reverseAccrualIt - " + toString());
|
||||
return false;
|
||||
} // reverseAccrualIt
|
||||
|
||||
/**
|
||||
* Re-activate.
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean reActivateIt() {
|
||||
public boolean reActivateIt()
|
||||
{
|
||||
log.info("reActivateIt - " + toString());
|
||||
return false;
|
||||
} // reActivateIt
|
||||
|
||||
/**
|
||||
* Get Document Owner (Responsible)
|
||||
* @return AD_User_ID
|
||||
*/
|
||||
public int getDoc_User_ID() {
|
||||
public int getDoc_User_ID()
|
||||
{
|
||||
return getPlanner_ID();
|
||||
} // getDoc_User_ID
|
||||
|
||||
/**
|
||||
* Get Document Approval Amount
|
||||
* @return amount
|
||||
*/
|
||||
|
||||
public BigDecimal getApprovalAmt() {
|
||||
public BigDecimal getApprovalAmt()
|
||||
{
|
||||
return Env.ZERO;
|
||||
} // getApprovalAmt
|
||||
|
||||
public int getC_Currency_ID() {
|
||||
public int getC_Currency_ID()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getProcessMsg() {
|
||||
return "";
|
||||
public String getProcessMsg()
|
||||
{
|
||||
return m_processMsg;
|
||||
}
|
||||
|
||||
public String getSummary() {
|
||||
return "";
|
||||
public String getSummary()
|
||||
{
|
||||
return "" + getDocumentNo() + "/" + getDatePromised();
|
||||
}
|
||||
|
||||
public File createPDF() {
|
||||
public File createPDF()
|
||||
{
|
||||
try {
|
||||
File temp = File.createTempFile(get_TableName() + get_ID() + "_", ".pdf");
|
||||
return createPDF(temp);
|
||||
|
@ -879,7 +804,8 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
* @param file output file
|
||||
* @return file if success
|
||||
*/
|
||||
public File createPDF(File file) {
|
||||
public File createPDF(File file)
|
||||
{
|
||||
ReportEngine re = ReportEngine.get(getCtx(), ReportEngine.MANUFACTURING_ORDER, getPP_Order_ID());
|
||||
if (re == null)
|
||||
return null;
|
||||
|
@ -890,7 +816,8 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
* Get Document Info
|
||||
* @return document info (untranslated)
|
||||
*/
|
||||
public String getDocumentInfo() {
|
||||
public String getDocumentInfo()
|
||||
{
|
||||
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
|
||||
return dt.getName() + " " + getDocumentNo();
|
||||
} // getDocumentInfo
|
||||
|
@ -901,13 +828,26 @@ public class MPPOrder extends X_PP_Order implements DocAction
|
|||
POResultSet<PO> rs = new Query(getCtx(), tableName, whereClause, get_TrxName())
|
||||
.setParameters(params)
|
||||
.scroll();
|
||||
try {
|
||||
while(rs.hasNext()) {
|
||||
try
|
||||
{
|
||||
while(rs.hasNext())
|
||||
{
|
||||
rs.next().deleteEx(true);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
finally
|
||||
{
|
||||
rs.close();
|
||||
}
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("MPPOrder[").append(get_ID())
|
||||
.append("-").append(getDocumentNo())
|
||||
.append(",IsSOTrx=").append(isSOTrx())
|
||||
.append(",C_DocType_ID=").append(getC_DocType_ID())
|
||||
.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
} // MPPOrder
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
* For the text or an alternative of this public license, you may reach us *
|
||||
* Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. *
|
||||
* Contributor(s): Victor Perez www.e-evolution.com *
|
||||
* Teo Sarca, www.arhipac.ro *
|
||||
*****************************************************************************/
|
||||
package org.eevolution.model;
|
||||
|
||||
|
@ -35,8 +36,7 @@ import org.compiere.util.Env;
|
|||
public class MPPOrderBOMLine extends X_PP_Order_BOMLine
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param ctx context
|
||||
|
@ -107,7 +107,7 @@ public class MPPOrderBOMLine extends X_PP_Order_BOMLine
|
|||
}
|
||||
|
||||
private MPPOrder m_parent = null;
|
||||
private MProduct m_product = null;
|
||||
|
||||
/** Qty used for exploding this BOM Line */
|
||||
private BigDecimal m_qtyToExplode = null;
|
||||
|
||||
|
@ -140,7 +140,8 @@ public class MPPOrderBOMLine extends X_PP_Order_BOMLine
|
|||
if (!success)
|
||||
return false;
|
||||
log.fine(" Parent Product" + getM_Product_ID() + " getQtyBatch" + getQtyBatch() + " getQtyRequiered" + getQtyRequiered() + " QtyScrap" + getQtyScrap());
|
||||
//
|
||||
//
|
||||
// Explode Phantom Items
|
||||
if(m_qtyToExplode != null)
|
||||
{
|
||||
MProduct parent = MProduct.get(getCtx(), getM_Product_ID());
|
||||
|
@ -169,15 +170,10 @@ public class MPPOrderBOMLine extends X_PP_Order_BOMLine
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Product
|
||||
* @return product or null
|
||||
*/
|
||||
public MProduct getProduct()
|
||||
@Override
|
||||
public MProduct getM_Product()
|
||||
{
|
||||
if (m_product == null && getM_Product_ID() != 0)
|
||||
m_product = new MProduct (getCtx(), getM_Product_ID() ,get_TrxName());
|
||||
return m_product;
|
||||
return MProduct.get(getCtx(), getM_Product_ID());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
* For the text or an alternative of this public license, you may reach us *
|
||||
* Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. *
|
||||
* Contributor(s): Victor Perez www.e-evolution.com *
|
||||
* Teo Sarca, www.arhipac.ro *
|
||||
*****************************************************************************/
|
||||
|
||||
package org.eevolution.model;
|
||||
|
@ -22,10 +23,7 @@ import java.util.Properties;
|
|||
import org.compiere.model.MCost;
|
||||
|
||||
/**
|
||||
* Order Model.
|
||||
* Please do not set DocStatus and C_DocType_ID directly.
|
||||
* They are set in the process() method.
|
||||
* Use DocAction and C_DocTypeTarget_ID instead.
|
||||
* PP Order Cost Model.
|
||||
*
|
||||
* @author Victor Perez www.e-evolution.com
|
||||
* @version $Id: MOrder.java,v 1.40 2004/04/13 04:19:30 vpj-cd Exp $
|
||||
|
|
|
@ -267,8 +267,6 @@ public class MRP extends SvrProcess
|
|||
commit();
|
||||
|
||||
//Delete Requisition with Draft Status
|
||||
|
||||
|
||||
String whereClause = "DocStatus IN ('CL','DR') AND AD_Client_ID=? AND AD_Org_ID=? AND M_Warehouse_ID=?";
|
||||
deletePO(MRequisition.Table_Name, whereClause, new Object[]{AD_Client_ID, AD_Org_ID, M_Warehouse_ID});
|
||||
commit();
|
||||
|
|
Loading…
Reference in New Issue