BF [ 1885414 ] ASI should be always mandatory if CostingLevel is Batch/Lot

This commit is contained in:
teo_sarca 2008-02-18 17:49:23 +00:00
parent 71b71e4618
commit cab309511f
4 changed files with 572 additions and 515 deletions

View File

@ -1096,21 +1096,11 @@ public class MInOut extends X_M_InOut implements DocAction
//
if (line.getM_AttributeSetInstance_ID() != 0)
continue;
if (product != null)
if (product != null && product.isASIMandatory(isSOTrx()))
{
int M_AttributeSet_ID = product.getM_AttributeSet_ID();
if (M_AttributeSet_ID != 0)
{
MAttributeSet mas = MAttributeSet.get(getCtx(), M_AttributeSet_ID);
if (mas != null
&& ((isSOTrx() && mas.isMandatory())
|| (!isSOTrx() && mas.isMandatoryAlways())) )
{
m_processMsg = "@M_AttributeSet_ID@ @IsMandatory@ (@Line@ #" + lines[i].getLine() +
", @M_Product_ID@=" + product.getValue() + ")";
return DocAction.STATUS_Invalid;
}
}
m_processMsg = "@M_AttributeSet_ID@ @IsMandatory@ (@Line@ #" + lines[i].getLine() +
", @M_Product_ID@=" + product.getValue() + ")";
return DocAction.STATUS_Invalid;
}
}
setVolume(Volume);

View File

@ -300,15 +300,10 @@ public class MInventoryLine extends X_M_InventoryLine
if (getM_AttributeSetInstance_ID() == 0)
{
MProduct product = MProduct.get(getCtx(), getM_Product_ID());
if (product.getM_AttributeSet_ID() != 0)
if (product != null && product.isASIMandatory(isSOTrx()))
{
MAttributeSet mas = MAttributeSet.get(getCtx(), product.getM_AttributeSet_ID());
if (mas.isInstanceAttribute()
&& (mas.isMandatory() || mas.isMandatoryAlways()))
{
log.saveError("FillMandatory", Msg.getElement(getCtx(), "M_AttributeSetInstance_ID"));
return false;
}
log.saveError("FillMandatory", Msg.getElement(getCtx(), COLUMNNAME_M_AttributeSetInstance_ID));
return false;
}
} // No ASI
} // new or manual
@ -418,4 +413,38 @@ public class MInventoryLine extends X_M_InventoryLine
}
} // createMA
/**
* Is Internal Use Inventory
* @return true if is internal use inventory
*/
public boolean isInternalUseInventory() {
/* TODO: need to add M_Inventory.IsInternalUseInventory flag
see FR [ 1879029 ] Added IsInternalUseInventory flag to M_Inventory table
MInventory parent = getParent();
return parent != null && parent.isInternalUseInventory();
*/
return getQtyInternalUse().signum() != 0;
}
/**
* Get Movement Qty (absolute value)
* <li>negative value means outgoing trx
* <li>positive value means incoming trx
* @return movement qty
*/
public BigDecimal getMovementQty() {
if(isInternalUseInventory()) {
return getQtyInternalUse().negate();
}
else {
return getQtyCount().subtract(getQtyBook());
}
}
/**
* @return true if is an outgoing transaction
*/
public boolean isSOTrx() {
return getMovementQty().signum() < 0;
}
} // MInventoryLine

View File

@ -177,23 +177,23 @@ public class MMovementLine extends X_M_MovementLine
setMovementQty(getMovementQty());
// Mandatory Instance
MProduct product = getProduct();
if (getM_AttributeSetInstance_ID() == 0) {
if (product != null && product.isASIMandatory(false)) {
log.saveError("FillMandatory", Msg.getElement(getCtx(), COLUMNNAME_M_AttributeSetInstance_ID));
return false;
}
}
if (getM_AttributeSetInstanceTo_ID() == 0)
{
if (getM_AttributeSetInstance_ID() != 0) // set to from
setM_AttributeSetInstanceTo_ID(getM_AttributeSetInstance_ID());
else
{
MProduct product = getProduct();
if (product != null
&& product.getM_AttributeSet_ID() != 0)
if (product != null && product.isASIMandatory(true))
{
MAttributeSet mas = MAttributeSet.get(getCtx(), product.getM_AttributeSet_ID());
if (mas.isInstanceAttribute()
&& (mas.isMandatory() || mas.isMandatoryAlways()))
{
log.saveError("FillMandatory", Msg.getElement(getCtx(), "M_AttributeSetInstanceTo_ID"));
return false;
}
log.saveError("FillMandatory", Msg.getElement(getCtx(), COLUMNNAME_M_AttributeSetInstanceTo_ID));
return false;
}
}
} // ASI

View File

@ -30,6 +30,7 @@ import org.compiere.util.*;
*
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>FR [ 1885153 ] Refactor: getMMPolicy code
* <li>BF [ 1885414 ] ASI should be always mandatory if CostingLevel is Batch/Lot
*/
public class MProduct extends X_M_Product
{
@ -748,4 +749,41 @@ public class MProduct extends X_M_Product
return MMPolicy;
}
/**
* Check if ASI is mandatory
* @param isSOTrx is outgoing trx?
* @return true if ASI is mandatory, false otherwise
*/
public boolean isASIMandatory(boolean isSOTrx) {
//
// If CostingLevel is BatchLot ASI is always mandatory - check all client acct schemas
MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID(), get_TrxName());
for (MAcctSchema as : mass) {
MProductCategoryAcct pca = MProductCategoryAcct.get(getCtx(), getM_Product_Category_ID(), as.getC_AcctSchema_ID(), get_TrxName());
String cl = pca.getCostingLevel();
if (cl == null)
cl = as.getCostingLevel();
if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(cl)) {
return true;
}
}
//
// Check Attribute Set settings
int M_AttributeSet_ID = getM_AttributeSet_ID();
if (M_AttributeSet_ID != 0)
{
MAttributeSet mas = MAttributeSet.get(getCtx(), M_AttributeSet_ID);
if (mas == null || !mas.isInstanceAttribute())
return false;
// Outgoing transaction
else if (isSOTrx)
return mas.isMandatory();
// Incoming transaction
else // isSOTrx == false
return mas.isMandatoryAlways();
}
//
// Default not mandatory
return false;
}
} // MProduct