IDEMPIERE-1040 The Sales Order / Purchase Order ignore the excluded tables for an Attribute Set defined as always mandatory

This commit is contained in:
Carlos Ruiz 2013-06-13 23:41:30 -05:00
parent 28c7343f04
commit 140eac588d
5 changed files with 70 additions and 48 deletions

View File

@ -41,8 +41,7 @@ public class MAttributeSet extends X_M_AttributeSet
/** /**
* *
*/ */
private static final long serialVersionUID = -2703536167929259405L; private static final long serialVersionUID = -187568054160926817L;
/** /**
* Get MAttributeSet from Cache * Get MAttributeSet from Cache
@ -210,13 +209,40 @@ public class MAttributeSet extends X_M_AttributeSet
} // isMandatoryShipping } // isMandatoryShipping
/** /**
* Exclude entry * Exclude column entry
* @param AD_Column_ID column * @param AD_Column_ID column
* @param isSOTrx sales order * @param isSOTrx sales order
* @return true if excluded * @return true if excluded
*/ */
public boolean excludeEntry (int AD_Column_ID, boolean isSOTrx) public boolean excludeEntry (int AD_Column_ID, boolean isSOTrx)
{ {
MColumn column = MColumn.get(getCtx(), AD_Column_ID);
return excludeTableEntry(column.getAD_Table_ID(), isSOTrx);
} // excludeEntry
/**
* Exclude table entry
* @param AD_Table_ID column
* @param isSOTrx sales order
* @return true if excluded
*/
public boolean excludeTableEntry (int AD_Table_ID, boolean isSOTrx)
{
loadExcludes();
// Find it
if (m_excludes != null && m_excludes.length > 0)
{
for (int i = 0; i < m_excludes.length; i++)
{
if (m_excludes[i].getAD_Table_ID() == AD_Table_ID
&& m_excludes[i].isSOTrx() == isSOTrx)
return true;
}
}
return false;
} // excludeTableEntry
private void loadExcludes() {
if (m_excludes == null) if (m_excludes == null)
{ {
final String whereClause = X_M_AttributeSetExclude.COLUMNNAME_M_AttributeSet_ID+"=?"; final String whereClause = X_M_AttributeSetExclude.COLUMNNAME_M_AttributeSet_ID+"=?";
@ -227,19 +253,7 @@ public class MAttributeSet extends X_M_AttributeSet
m_excludes = new X_M_AttributeSetExclude[list.size ()]; m_excludes = new X_M_AttributeSetExclude[list.size ()];
list.toArray (m_excludes); list.toArray (m_excludes);
} }
// Find it }
if (m_excludes != null && m_excludes.length > 0)
{
MColumn column = MColumn.get(getCtx(), AD_Column_ID);
for (int i = 0; i < m_excludes.length; i++)
{
if (m_excludes[i].getAD_Table_ID() == column.getAD_Table_ID()
&& m_excludes[i].isSOTrx() == isSOTrx)
return true;
}
}
return false;
} // excludeEntry
/** /**
* Exclude Lot creation * Exclude Lot creation

View File

@ -1186,9 +1186,11 @@ public class MInOut extends X_M_InOut implements DocAction
continue; continue;
if (product != null && product.isASIMandatory(isSOTrx())) if (product != null && product.isASIMandatory(isSOTrx()))
{ {
m_processMsg = "@M_AttributeSet_ID@ @IsMandatory@ (@Line@ #" + lines[i].getLine() + if (! product.getAttributeSet().excludeTableEntry(MInOutLine.Table_ID, isSOTrx())) {
", @M_Product_ID@=" + product.getValue() + ")"; m_processMsg = "@M_AttributeSet_ID@ @IsMandatory@ (@Line@ #" + lines[i].getLine() +
return DocAction.STATUS_Invalid; ", @M_Product_ID@=" + product.getValue() + ")";
return DocAction.STATUS_Invalid;
}
} }
} }
setVolume(Volume); setVolume(Volume);

View File

@ -260,7 +260,7 @@ public class MInventoryLine extends X_M_InventoryLine
log.saveError("ParentComplete", Msg.translate(getCtx(), "M_InventoryLine")); log.saveError("ParentComplete", Msg.translate(getCtx(), "M_InventoryLine"));
return false; return false;
} }
if (newRecord && m_isManualEntry) if (m_isManualEntry)
{ {
// Product requires ASI // Product requires ASI
if (getM_AttributeSetInstance_ID() == 0) if (getM_AttributeSetInstance_ID() == 0)
@ -268,11 +268,13 @@ public class MInventoryLine extends X_M_InventoryLine
MProduct product = MProduct.get(getCtx(), getM_Product_ID()); MProduct product = MProduct.get(getCtx(), getM_Product_ID());
if (product != null && product.isASIMandatory(isSOTrx())) if (product != null && product.isASIMandatory(isSOTrx()))
{ {
log.saveError("FillMandatory", Msg.getElement(getCtx(), COLUMNNAME_M_AttributeSetInstance_ID)); if (! product.getAttributeSet().excludeTableEntry(MInventoryLine.Table_ID, isSOTrx())) {
return false; log.saveError("FillMandatory", Msg.getElement(getCtx(), COLUMNNAME_M_AttributeSetInstance_ID));
return false;
}
} }
} // No ASI } // No ASI
} // new or manual } // manual
// Set Line No // Set Line No
if (getLine() == 0) if (getLine() == 0)
@ -423,12 +425,10 @@ public class MInventoryLine extends X_M_InventoryLine
* @return true if is internal use inventory * @return true if is internal use inventory
*/ */
public boolean isInternalUseInventory() { public boolean isInternalUseInventory() {
/* TODO: need to add M_Inventory.IsInternalUseInventory flag // IDEMPIERE-675
see FR [ 1879029 ] Added IsInternalUseInventory flag to M_Inventory table MDocType dt = MDocType.get(getCtx(), getParent().getC_DocType_ID());
MInventory parent = getParent(); String docSubTypeInv = dt.getDocSubTypeInv();
return parent != null && parent.isInternalUseInventory(); return (MDocType.DOCSUBTYPEINV_InternalUseInventory.equals(docSubTypeInv));
*/
return getQtyInternalUse().signum() != 0;
} }
/** /**

View File

@ -211,9 +211,11 @@ public class MMovementLine extends X_M_MovementLine
// Mandatory Instance // Mandatory Instance
MProduct product = getProduct(); MProduct product = getProduct();
if (getM_AttributeSetInstance_ID() == 0) { if (getM_AttributeSetInstance_ID() == 0) {
if (product != null && product.isASIMandatory(false)) { if (product != null && product.isASIMandatory(true)) {
log.saveError("FillMandatory", Msg.getElement(getCtx(), COLUMNNAME_M_AttributeSetInstance_ID)); if (! product.getAttributeSet().excludeTableEntry(MMovementLine.Table_ID, true /*outgoing*/)) {
return false; log.saveError("FillMandatory", Msg.getElement(getCtx(), COLUMNNAME_M_AttributeSetInstance_ID));
return false;
}
} }
} }
if (getM_AttributeSetInstanceTo_ID() == 0) if (getM_AttributeSetInstanceTo_ID() == 0)
@ -225,10 +227,12 @@ public class MMovementLine extends X_M_MovementLine
setM_AttributeSetInstanceTo_ID(getM_AttributeSetInstance_ID()); setM_AttributeSetInstanceTo_ID(getM_AttributeSetInstance_ID());
} }
if (product != null && product.isASIMandatory(true) && getM_AttributeSetInstanceTo_ID() == 0) if (product != null && product.isASIMandatory(false) && getM_AttributeSetInstanceTo_ID() == 0)
{ {
log.saveError("FillMandatory", Msg.getElement(getCtx(), COLUMNNAME_M_AttributeSetInstanceTo_ID)); if (! product.getAttributeSet().excludeTableEntry(MMovementLine.Table_ID, false /*incoming*/)) {
return false; log.saveError("FillMandatory", Msg.getElement(getCtx(), COLUMNNAME_M_AttributeSetInstanceTo_ID));
return false;
}
} }
} // ASI } // ASI

View File

@ -1310,19 +1310,21 @@ public class MOrder extends X_C_Order implements DocAction
} // convert DocType } // convert DocType
// Mandatory Product Attribute Set Instance // Mandatory Product Attribute Set Instance
String mandatoryType = "='Y'"; // IN ('Y','S') for (MOrderLine line : getLines()) {
String sql = "SELECT COUNT(*) " if (line.getM_Product_ID() > 0 && line.getM_AttributeSetInstance_ID() == 0) {
+ "FROM C_OrderLine ol" MProduct product = line.getProduct();
+ " INNER JOIN M_Product p ON (ol.M_Product_ID=p.M_Product_ID)" if (product.isASIMandatory(isSOTrx())) {
+ " INNER JOIN M_AttributeSet pas ON (p.M_AttributeSet_ID=pas.M_AttributeSet_ID) " if (! product.getAttributeSet().excludeTableEntry(MOrderLine.Table_ID, isSOTrx())) {
+ "WHERE pas.MandatoryType" + mandatoryType StringBuilder msg = new StringBuilder("@M_AttributeSet_ID@ @IsMandatory@ (@Line@ #")
+ " AND (ol.M_AttributeSetInstance_ID is NULL OR ol.M_AttributeSetInstance_ID = 0)" .append(line.getLine())
+ " AND ol.C_Order_ID=?"; .append(", @M_Product_ID@=")
int no = DB.getSQLValue(get_TrxName(), sql, getC_Order_ID()); .append(product.getValue())
if (no != 0) .append(")");
{ m_processMsg = msg.toString();
m_processMsg = "@LinesWithoutProductAttribute@ (" + no + ")"; return DocAction.STATUS_Invalid;
return DocAction.STATUS_Invalid; }
}
}
} }
// Lines // Lines