IDEMPIERE-1770 Allowing manual entry from Attributes tab on shipment/MR line -> move validation for mandatory serial from beforeSave to prepareIt on MInventory and MMovement

This commit is contained in:
Carlos Ruiz 2016-01-27 19:53:44 +01:00
parent 87432dd660
commit b248f46cde
4 changed files with 82 additions and 8 deletions

View File

@ -334,6 +334,38 @@ public class MInventory extends X_M_Inventory implements DocAction
return DocAction.STATUS_Invalid;
}
// Validate mandatory ASI on lines - IDEMPIERE-1770 - ASI validation must be moved to MInventory.prepareIt
for (MInventoryLine line : lines) {
// Product requires ASI
if (line.getM_AttributeSetInstance_ID() == 0)
{
MProduct product = MProduct.get(getCtx(), line.getM_Product_ID());
if (product != null && product.isASIMandatory(line.isSOTrx()))
{
if (! product.getAttributeSet().excludeTableEntry(MInventoryLine.Table_ID, line.isSOTrx())) {
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
String docSubTypeInv = dt.getDocSubTypeInv();
BigDecimal qtyDiff = line.getQtyInternalUse();
if (MDocType.DOCSUBTYPEINV_PhysicalInventory.equals(docSubTypeInv))
qtyDiff = line.getQtyBook().subtract(line.getQtyCount());
// verify if the ASIs are captured on lineMA
MInventoryLineMA mas[] = MInventoryLineMA.get(getCtx(),
line.getM_InventoryLine_ID(), get_TrxName());
BigDecimal qtyma = Env.ZERO;
for (MInventoryLineMA ma : mas) {
if (! ma.isAutoGenerated()) {
qtyma = qtyma.add(ma.getMovementQty());
}
}
if (qtyma.subtract(qtyDiff).signum() != 0) {
m_processMsg = "@Line@ " + line.getLine() + ": @FillMandatory@ @M_AttributeSetInstance_ID@";
return DocAction.STATUS_Invalid;
}
}
}
} // No ASI
}
// TODO: Add up Amounts
// setApprovalAmt();

View File

@ -125,7 +125,7 @@ public class MInventoryLine extends X_M_InventoryLine
setQtyCount (QtyCount);
if (QtyInternalUse != null && QtyInternalUse.signum() != 0)
setQtyInternalUse (QtyInternalUse);
m_isManualEntry = false;
// m_isManualEntry = false;
} // MInventoryLine
public MInventoryLine (MInventory inventory,
@ -136,7 +136,7 @@ public class MInventoryLine extends X_M_InventoryLine
}
/** Manually created */
private boolean m_isManualEntry = true;
// private boolean m_isManualEntry = true;
/** Parent */
private MInventory m_parent = null;
/** Product */
@ -260,6 +260,7 @@ public class MInventoryLine extends X_M_InventoryLine
log.saveError("ParentComplete", Msg.translate(getCtx(), "M_InventoryLine"));
return false;
}
/* IDEMPIERE-1770 - ASI validation must be moved to MInventory.prepareIt, saving a line without ASI is ok on draft
if (m_isManualEntry)
{
// Product requires ASI
@ -279,7 +280,8 @@ public class MInventoryLine extends X_M_InventoryLine
}
} // No ASI
} // manual
*/
// Set Line No
if (getLine() == 0)
{

View File

@ -290,7 +290,43 @@ public class MMovement extends X_M_Movement implements DocAction
m_processMsg = "@NoLines@";
return DocAction.STATUS_Invalid;
}
// Validate mandatory ASI on lines - IDEMPIERE-1770 - ASI validation must be moved to MMovement.prepareIt
for (MMovementLine line : lines) {
// Mandatory Instance
MProduct product = line.getProduct();
if (line.getM_AttributeSetInstance_ID() == 0) {
if (product != null && product.isASIMandatory(true)) {
if (! product.getAttributeSet().excludeTableEntry(MMovementLine.Table_ID, true)) { // outgoing
BigDecimal qtyDiff = line.getMovementQty();
// verify if the ASIs are captured on lineMA
MMovementLineMA mas[] = MMovementLineMA.get(getCtx(),
line.getM_MovementLine_ID(), get_TrxName());
BigDecimal qtyma = Env.ZERO;
for (MMovementLineMA ma : mas) {
if (! ma.isAutoGenerated()) {
qtyma = qtyma.add(ma.getMovementQty());
}
}
if (qtyma.subtract(qtyDiff).signum() != 0) {
m_processMsg = "@Line@ " + line.getLine() + ": @FillMandatory@ @M_AttributeSetInstance_ID@";
return DocAction.STATUS_Invalid;
}
}
}
}
if (line.getM_AttributeSetInstanceTo_ID() == 0)
{
if (product != null && product.isASIMandatory(false) && line.getM_AttributeSetInstanceTo_ID() == 0)
{
if (! product.getAttributeSet().excludeTableEntry(MMovementLine.Table_ID, false)) { // incoming
m_processMsg = "@Line@ " + line.getLine() + ": @FillMandatory@ @M_AttributeSetInstanceTo_ID@";
return DocAction.STATUS_Invalid;
}
}
} // ASI
}
// Confirmation
if (dt.isInTransit())
createConfirmation();

View File

@ -207,8 +207,9 @@ public class MMovementLine extends X_M_MovementLine
// Qty Precision
if (newRecord || is_ValueChanged(COLUMNNAME_MovementQty))
setMovementQty(getMovementQty());
// Mandatory Instance
/* IDEMPIERE-1770 - ASI validation must be moved to MMovement.prepareIt, saving a line without ASI is ok on draft
MProduct product = getProduct();
if (getM_AttributeSetInstance_ID() == 0) {
if (product != null && product.isASIMandatory(true)) {
@ -216,12 +217,13 @@ public class MMovementLine extends X_M_MovementLine
log.saveError("NoAttributeSet", product.getValue());
return false;
}
if (! product.getAttributeSet().excludeTableEntry(MMovementLine.Table_ID, true /*outgoing*/)) {
if (! product.getAttributeSet().excludeTableEntry(MMovementLine.Table_ID, true)) { // outgoing
log.saveError("FillMandatory", Msg.getElement(getCtx(), COLUMNNAME_M_AttributeSetInstance_ID));
return false;
}
}
}
*/
if (getM_AttributeSetInstanceTo_ID() == 0)
{
//instance id default to same for movement between locator
@ -230,18 +232,20 @@ public class MMovementLine extends X_M_MovementLine
if (getM_AttributeSetInstance_ID() != 0) //set to from
setM_AttributeSetInstanceTo_ID(getM_AttributeSetInstance_ID());
}
/* IDEMPIERE-1770 - ASI validation must be moved to MMovement.prepareIt, saving a line without ASI is ok on draft
if (product != null && product.isASIMandatory(false) && getM_AttributeSetInstanceTo_ID() == 0)
{
if (product.getAttributeSet()==null) {
log.saveError("NoAttributeSet", product.getValue());
return false;
}
if (! product.getAttributeSet().excludeTableEntry(MMovementLine.Table_ID, false /*incoming*/)) {
if (! product.getAttributeSet().excludeTableEntry(MMovementLine.Table_ID, false)) { // incoming
log.saveError("FillMandatory", Msg.getElement(getCtx(), COLUMNNAME_M_AttributeSetInstanceTo_ID));
return false;
}
}
*/
} // ASI
return true;