libero QA: refactor MPPOrder

This commit is contained in:
teo_sarca 2009-01-15 17:08:04 +00:00
parent 7765d79801
commit 25da8acb59
2 changed files with 95 additions and 82 deletions

View File

@ -67,8 +67,6 @@ import org.compiere.wf.MWorkflow;
public class MPPOrder extends X_PP_Order implements DocAction public class MPPOrder extends X_PP_Order implements DocAction
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** Product */
private MProduct m_product = null;
public static MPPOrder forC_OrderLine_ID(Properties ctx, int C_OrderLine_ID, String trxName) public static MPPOrder forC_OrderLine_ID(Properties ctx, int C_OrderLine_ID, String trxName)
{ {
@ -114,7 +112,7 @@ public class MPPOrder extends X_PP_Order implements DocAction
* @param project Project to create Order from * @param project Project to create Order from
* @param DocSubTypeSO if SO DocType Target (default DocSubTypeSO_OnCredit) * @param DocSubTypeSO if SO DocType Target (default DocSubTypeSO_OnCredit)
*/ */
public MPPOrder(MProject project, int PP_Product_BOM_ID,int AD_Workflow_ID) public MPPOrder(MProject project, int PP_Product_BOM_ID, int AD_Workflow_ID)
{ {
this(project.getCtx(), 0, project.get_TrxName()); this(project.getCtx(), 0, project.get_TrxName());
setAD_Client_ID(project.getAD_Client_ID()); setAD_Client_ID(project.getAD_Client_ID());
@ -168,7 +166,7 @@ public class MPPOrder extends X_PP_Order implements DocAction
} // MOrder } // MOrder
/** /**
* @return Open Qty * @return Open Qty (Ordered - Delivered - Scrap)
*/ */
public BigDecimal getQtyOpen() public BigDecimal getQtyOpen()
{ {
@ -397,14 +395,17 @@ public class MPPOrder extends X_PP_Order implements DocAction
setC_DocType_ID(getC_DocTypeTarget_ID()); setC_DocType_ID(getC_DocTypeTarget_ID());
} }
MDocType doc = MDocType.get(getCtx(), getC_DocType_ID()); String docBaseType = MDocType.get(getCtx(), getC_DocType_ID()).getDocBaseType();
if (doc.getDocBaseType().equals(MDocType.DOCBASETYPE_QualityOrder)) if (MDocType.DOCBASETYPE_QualityOrder.equals(docBaseType))
{ {
return DocAction.STATUS_InProgress; ; // nothing
}
// ManufacturingOrder, MaintenanceOrder
else
{
reserveStock(lines);
orderStock();
} }
reserveStock(lines);
orderStock();
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_PREPARE); m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_PREPARE);
if (m_processMsg != null) if (m_processMsg != null)
@ -416,8 +417,8 @@ public class MPPOrder extends X_PP_Order implements DocAction
private void orderStock() private void orderStock()
{ {
MProduct product = MProduct.get(getCtx(), getM_Product_ID()); MProduct product = getM_Product();
if (product != null && product.isStocked()) if (product.isStocked())
{ {
BigDecimal target = getQtyOrdered(); BigDecimal target = getQtyOrdered();
BigDecimal difference = target.subtract(getQtyReserved()).subtract(getQtyDelivered()); BigDecimal difference = target.subtract(getQtyReserved()).subtract(getQtyDelivered());
@ -425,20 +426,12 @@ public class MPPOrder extends X_PP_Order implements DocAction
return ; return ;
BigDecimal ordered = difference; BigDecimal ordered = difference;
int M_Locator_ID = 0; int M_Locator_ID = getM_Locator_ID(ordered);
// Get Locator to reserve // Necessary to clear order quantities when called from closeIt - 4Layers
if (getM_AttributeSetInstance_ID() != 0) // Get existing Location
M_Locator_ID = MStorage.getM_Locator_ID(getM_Warehouse_ID(), getM_Product_ID(), getM_AttributeSetInstance_ID(), ordered,
get_TrxName());
// Get default Location
if (M_Locator_ID == 0)
{
M_Locator_ID = getM_Locator_ID();
}
//4Layers - Necessary to clear order quantities when called from closeIt
if (DOCACTION_Close.equals(getDocAction())) if (DOCACTION_Close.equals(getDocAction()))
{ {
if (!MStorage.add(getCtx(), getM_Warehouse_ID(), M_Locator_ID, getM_Product_ID(), getM_AttributeSetInstance_ID(), if (!MStorage.add(getCtx(), getM_Warehouse_ID(), M_Locator_ID,
getM_Product_ID(), getM_AttributeSetInstance_ID(),
getM_AttributeSetInstance_ID(), Env.ZERO, Env.ZERO, ordered, get_TrxName())) getM_AttributeSetInstance_ID(), Env.ZERO, Env.ZERO, ordered, get_TrxName()))
{ {
throw new AdempiereException(); throw new AdempiereException();
@ -447,7 +440,8 @@ public class MPPOrder extends X_PP_Order implements DocAction
else else
{ {
// Update Storage // Update Storage
if (!MStorage.add(getCtx(), getM_Warehouse_ID(), M_Locator_ID, getM_Product_ID(), getM_AttributeSetInstance_ID(), if (!MStorage.add(getCtx(), getM_Warehouse_ID(), M_Locator_ID,
getM_Product_ID(), getM_AttributeSetInstance_ID(),
getM_AttributeSetInstance_ID(), Env.ZERO, Env.ZERO, ordered, get_TrxName())) getM_AttributeSetInstance_ID(), Env.ZERO, Env.ZERO, ordered, get_TrxName()))
{ {
throw new AdempiereException(); throw new AdempiereException();
@ -466,11 +460,11 @@ public class MPPOrder extends X_PP_Order implements DocAction
*/ */
private void reserveStock(MPPOrderBOMLine[] lines) private void reserveStock(MPPOrderBOMLine[] lines)
{ {
int header_M_Warehouse_ID = getM_Warehouse_ID(); final int header_M_Warehouse_ID = getM_Warehouse_ID();
// Always check and (un) Reserve Inventory // Always check and (un) Reserve Inventory
for (int i = 0; i < lines.length; i++) { for (MPPOrderBOMLine line : lines)
MPPOrderBOMLine line = lines[i]; {
// Check/set WH/Org // Check/set WH/Org
if (header_M_Warehouse_ID != 0) // enforce WH if (header_M_Warehouse_ID != 0) // enforce WH
{ {
@ -479,48 +473,35 @@ public class MPPOrder extends X_PP_Order implements DocAction
if (getAD_Org_ID() != line.getAD_Org_ID()) if (getAD_Org_ID() != line.getAD_Org_ID())
line.setAD_Org_ID(getAD_Org_ID()); line.setAD_Org_ID(getAD_Org_ID());
} }
// Binding //
//vpj BigDecimal target = binding ? line.getQtyOrdered() : Env.ZERO; final BigDecimal target = line.getQtyRequiered();
BigDecimal target = line.getQtyRequiered(); final BigDecimal difference = target.subtract(line.getQtyReserved()).subtract(line.getQtyDelivered());
BigDecimal difference = target.subtract(line.getQtyReserved()).subtract(line.getQtyDelivered());
if (difference.signum() == 0) if (difference.signum() == 0)
{
continue; continue;
}
log.fine("Line=" + line.getLine() + " - Target=" + target + ",Difference=" + difference + " - Requiered=" + line.getQtyRequiered() log.fine("Line=" + line.getLine() + " - Target=" + target + ",Difference=" + difference + " - Requiered=" + line.getQtyRequiered()
+ ",Reserved=" + line.getQtyReserved() + ",Delivered=" + line.getQtyDelivered()); + ",Reserved=" + line.getQtyReserved() + ",Delivered=" + line.getQtyDelivered());
// Check Product - Stocked and Item // Check Product - Stocked and Item
MProduct product = line.getM_Product(); MProduct product = line.getM_Product();
if (product != null) if (!product.isStocked())
{ {
if (product.isStocked()) BigDecimal ordered = Env.ZERO;
BigDecimal reserved = difference;
int M_Locator_ID = getM_Locator_ID(ordered);
// Update Storage
if (!MStorage.add(getCtx(), line.getM_Warehouse_ID(), M_Locator_ID,
line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(),
line.getM_AttributeSetInstance_ID(), Env.ZERO, reserved, ordered, get_TrxName()))
{ {
//vpj BigDecimal ordered = isSOTrx ? Env.ZERO : difference; throw new AdempiereException();
BigDecimal ordered = Env.ZERO; }
//BigDecimal reserved = isSOTrx ? difference : Env.ZERO; } // stocked
BigDecimal reserved = difference; // update line
int M_Locator_ID = 0; line.setQtyReserved(line.getQtyReserved().add(difference));
// Get Locator to reserve line.saveEx(get_TrxName());
if (line.getM_AttributeSetInstance_ID() != 0) // Get existing Location }
M_Locator_ID = MStorage.getM_Locator_ID(line.getM_Warehouse_ID(), line.getM_Product_ID(),
line.getM_AttributeSetInstance_ID(), ordered, get_TrxName());
// Get default Location
if (M_Locator_ID == 0) {
MWarehouse wh = MWarehouse.get(getCtx(), line.getM_Warehouse_ID());
M_Locator_ID = wh.getDefaultLocator().getM_Locator_ID();
}
// Update Storage
if (!MStorage.add(getCtx(), line.getM_Warehouse_ID(), M_Locator_ID, line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(),
line.getM_AttributeSetInstance_ID(), Env.ZERO, reserved, ordered, get_TrxName()))
{
throw new AdempiereException();
}
} // stockec
// update line
line.setQtyReserved(line.getQtyReserved().add(difference));
line.saveEx(get_TrxName());
}
} // reverse inventory
} // reserveStock } // reserveStock
public boolean approveIt() public boolean approveIt()
@ -613,14 +594,17 @@ public class MPPOrder extends X_PP_Order implements DocAction
if (MPPOrderBOM.BOMTYPE_Make_To_Kit.equals(obom.getBOMType()) && MPPOrderBOM.BOMUSE_Manufacturing.equals(obom.getBOMUse())) if (MPPOrderBOM.BOMTYPE_Make_To_Kit.equals(obom.getBOMType()) && MPPOrderBOM.BOMUSE_Manufacturing.equals(obom.getBOMUse()))
{ {
if(!MPPOrder.DOCSTATUS_Completed.equals(getDocStatus())) if(!MPPOrder.DOCSTATUS_Completed.equals(getDocStatus()))
{
throw new AdempiereException( Msg.translate(getCtx(),MRefList.getListName(getCtx(), MPPOrderBOM.BOMTYPE_AD_Reference_ID, MPPOrderBOM.BOMTYPE_Make_To_Kit)) throw new AdempiereException( Msg.translate(getCtx(),MRefList.getListName(getCtx(), MPPOrderBOM.BOMTYPE_AD_Reference_ID, MPPOrderBOM.BOMTYPE_Make_To_Kit))
+ " " + " "
+ Msg.translate(getCtx(), MPPOrder.COLUMNNAME_PP_Order_ID) + Msg.translate(getCtx(), MPPOrder.COLUMNNAME_PP_Order_ID)
+" : " +" : "
+ getDocumentNo() + getDocumentNo()
+ " "+Msg.getMsg(getCtx(), "ShipmentCreateDocNotCompleted")); + " "+Msg.getMsg(getCtx(), "ShipmentCreateDocNotCompleted"));
ArrayList[][] issue = new ArrayList[m_lines.length][1]; }
Timestamp today = new Timestamp(System.currentTimeMillis()); Timestamp today = new Timestamp(System.currentTimeMillis());
ArrayList[][] issue = new ArrayList[m_lines.length][1];
for (int i = 0; i < getLines().length ; i++) for (int i = 0; i < getLines().length ; i++)
{ {
@ -629,7 +613,9 @@ public class MPPOrder extends X_PP_Order implements DocAction
KeyNamePair id = null; KeyNamePair id = null;
if(MPPOrderBOMLine.ISSUEMETHOD_Backflush.equals(line.getIssueMethod())) if(MPPOrderBOMLine.ISSUEMETHOD_Backflush.equals(line.getIssueMethod()))
{
id = new KeyNamePair(line.get_ID(),"Y"); id = new KeyNamePair(line.get_ID(),"Y");
}
else else
id = new KeyNamePair(line.get_ID(),"N"); id = new KeyNamePair(line.get_ID(),"N");
@ -896,24 +882,18 @@ public class MPPOrder extends X_PP_Order implements DocAction
*/ */
public void setQtyOrdered (BigDecimal QtyOrdered) public void setQtyOrdered (BigDecimal QtyOrdered)
{ {
MProduct product = getProduct(); if (QtyOrdered != null)
if (QtyOrdered != null && product != null)
{ {
int precision = product.getUOMPrecision(); int precision = getM_Product().getUOMPrecision();
QtyOrdered = QtyOrdered.setScale(precision, BigDecimal.ROUND_HALF_UP); QtyOrdered = QtyOrdered.setScale(precision, BigDecimal.ROUND_HALF_UP);
} }
super.setQtyOrdered(QtyOrdered); super.setQtyOrdered(QtyOrdered);
} // setQtyOrdered } // setQtyOrdered
/** // @Override
* Get Product public MProduct getM_Product()
* @return product or null
*/
public MProduct getProduct()
{ {
if (m_product == null && getM_Product_ID() != 0) return MProduct.get (getCtx(), getM_Product_ID());
m_product = MProduct.get (getCtx(), getM_Product_ID());
return m_product;
} // getProduct } // getProduct
public MPPOrderBOM getMPPOrderBOM() public MPPOrderBOM getMPPOrderBOM()
@ -1231,6 +1211,23 @@ public class MPPOrder extends X_PP_Order implements DocAction
return cc; return cc;
} }
public static boolean isAvailableQty(MPPOrder order, I_PP_Order_BOMLine line)
{
MProduct product = MProduct.get(order.getCtx(), line.getM_Product_ID());
if (product == null || !product.isStocked())
{
return true;
}
BigDecimal qtyToDeliver = line.getQtyRequiered();
BigDecimal qtyScrap = line.getQtyScrap();
BigDecimal qtyRequired = qtyToDeliver.add(qtyScrap);
BigDecimal qtyAvailable = MStorage.getQtyAvailable(order.getM_Warehouse_ID(), 0,
line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(),
order.get_TrxName());
return qtyAvailable.compareTo(qtyRequired) >= 0;
}
/** /**
* get if Component is Available * get if Component is Available
* @param MPPOrdrt Manufacturing order * @param MPPOrdrt Manufacturing order
@ -1252,7 +1249,6 @@ public class MPPOrder extends X_PP_Order implements DocAction
continue; continue;
} }
Boolean isCritical = (Boolean)issue[i][0].get(1);
String value = (String)issue[i][0].get(2); String value = (String)issue[i][0].get(2);
KeyNamePair productkey = (KeyNamePair) issue[i][0].get(3); KeyNamePair productkey = (KeyNamePair) issue[i][0].get(3);
int M_Product_ID = productkey.getKey(); int M_Product_ID = productkey.getKey();
@ -1260,8 +1256,7 @@ public class MPPOrder extends X_PP_Order implements DocAction
BigDecimal qtyScrapComponent = (BigDecimal) issue[i][0].get(5); BigDecimal qtyScrapComponent = (BigDecimal) issue[i][0].get(5);
MProduct product = MProduct.get(order.getCtx(), M_Product_ID); MProduct product = MProduct.get(order.getCtx(), M_Product_ID);
if (product != null && product.isStocked())
if (product != null && product.get_ID() != 0 && product.isStocked())
{ {
int M_AttributeSetInstance_ID = ANY_ASI; int M_AttributeSetInstance_ID = ANY_ASI;
if (value == null && isSelected) if (value == null && isSelected)
@ -1269,7 +1264,7 @@ public class MPPOrder extends X_PP_Order implements DocAction
M_AttributeSetInstance_ID = (Integer)key.getKey(); M_AttributeSetInstance_ID = (Integer)key.getKey();
} }
MStorage[] storages = MPPOrder.getStorages(order.getCtx(), MStorage[] storages = MPPOrder.getStorages(order.getCtx(),
M_Product_ID, M_Product_ID,
order.getM_Warehouse_ID(), order.getM_Warehouse_ID(),
M_AttributeSetInstance_ID, M_AttributeSetInstance_ID,
@ -1345,8 +1340,7 @@ public class MPPOrder extends X_PP_Order implements DocAction
} }
/** /**
* Default Location * @return Default Locator for current Warehouse
* @return
*/ */
private int getM_Locator_ID() private int getM_Locator_ID()
{ {
@ -1354,6 +1348,28 @@ public class MPPOrder extends X_PP_Order implements DocAction
return wh.getDefaultLocator().getM_Locator_ID(); return wh.getDefaultLocator().getM_Locator_ID();
} }
/**
* @param qty
* @return Storage locator for current product/asi/warehouse and qty
* @see MStorage#getM_Locator_ID(int, int, int, BigDecimal, String)
*/
private int getM_Locator_ID(BigDecimal qty)
{
int M_Locator_ID = 0;
int M_ASI_ID = getM_AttributeSetInstance_ID();
// Get existing Locator
if (M_ASI_ID != 0)
{
M_Locator_ID = MStorage.getM_Locator_ID(getM_Warehouse_ID(), getM_Product_ID(), M_ASI_ID, qty, get_TrxName());
}
// Get Default
if (M_Locator_ID == 0)
{
M_Locator_ID = getM_Locator_ID();
}
return M_Locator_ID;
}
public String toString() public String toString()
{ {
StringBuffer sb = new StringBuffer("MPPOrder[").append(get_ID()) StringBuffer sb = new StringBuffer("MPPOrder[").append(get_ID())

View File

@ -65,9 +65,7 @@ import org.compiere.minigrid.MiniTable;
import org.compiere.model.GridField; import org.compiere.model.GridField;
import org.compiere.model.GridFieldVO; import org.compiere.model.GridFieldVO;
import org.compiere.model.MAttributeSetInstance; import org.compiere.model.MAttributeSetInstance;
import org.compiere.model.MClient;
import org.compiere.model.MColumn; import org.compiere.model.MColumn;
import org.compiere.model.MDocType;
import org.compiere.model.MLocatorLookup; import org.compiere.model.MLocatorLookup;
import org.compiere.model.MLookup; import org.compiere.model.MLookup;
import org.compiere.model.MLookupFactory; import org.compiere.model.MLookupFactory;
@ -90,7 +88,6 @@ import org.compiere.util.Env;
import org.compiere.util.KeyNamePair; import org.compiere.util.KeyNamePair;
import org.compiere.util.Language; import org.compiere.util.Language;
import org.compiere.util.Msg; import org.compiere.util.Msg;
import org.eevolution.model.MPPCostCollector;
import org.eevolution.model.MPPOrder; import org.eevolution.model.MPPOrder;
import org.eevolution.model.MPPOrderBOMLine; import org.eevolution.model.MPPOrderBOMLine;
import org.eevolution.model.MPPProductBOMLine; import org.eevolution.model.MPPProductBOMLine;