From b248f46cde4356d9e35a341f01e3cffa31b44b19 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 27 Jan 2016 19:53:44 +0100 Subject: [PATCH] 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 --- .../src/org/compiere/model/MInventory.java | 32 ++++++++++++++++ .../org/compiere/model/MInventoryLine.java | 8 ++-- .../src/org/compiere/model/MMovement.java | 38 ++++++++++++++++++- .../src/org/compiere/model/MMovementLine.java | 12 ++++-- 4 files changed, 82 insertions(+), 8 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MInventory.java b/org.adempiere.base/src/org/compiere/model/MInventory.java index 646760c2d9..b8366dc0ca 100644 --- a/org.adempiere.base/src/org/compiere/model/MInventory.java +++ b/org.adempiere.base/src/org/compiere/model/MInventory.java @@ -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(); diff --git a/org.adempiere.base/src/org/compiere/model/MInventoryLine.java b/org.adempiere.base/src/org/compiere/model/MInventoryLine.java index e6bf530dd9..aff95b4e8b 100644 --- a/org.adempiere.base/src/org/compiere/model/MInventoryLine.java +++ b/org.adempiere.base/src/org/compiere/model/MInventoryLine.java @@ -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) { diff --git a/org.adempiere.base/src/org/compiere/model/MMovement.java b/org.adempiere.base/src/org/compiere/model/MMovement.java index 1ad6d522e2..1599cb2dc1 100644 --- a/org.adempiere.base/src/org/compiere/model/MMovement.java +++ b/org.adempiere.base/src/org/compiere/model/MMovement.java @@ -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(); diff --git a/org.adempiere.base/src/org/compiere/model/MMovementLine.java b/org.adempiere.base/src/org/compiere/model/MMovementLine.java index 118dac29b3..5c54a07052 100644 --- a/org.adempiere.base/src/org/compiere/model/MMovementLine.java +++ b/org.adempiere.base/src/org/compiere/model/MMovementLine.java @@ -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;