From dcd7d6a41e6b95851e75650bbd2e2f36ac5cdf2d Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Mon, 31 Aug 2020 08:23:33 +0200 Subject: [PATCH] =?UTF-8?q?IDEMPIERE-1709=20/=20IDEMPIERE-2624=20Cant=20co?= =?UTF-8?q?nfirm=200=20qty=20on=20Movement=20Confir=E2=80=A6=20(#227)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * IDEMPIERE-1709 / IDEMPIERE-2624 Cant confirm 0 qty on Movement Confirmation Implement void for movement confirm * IDEMPIERE-1709 / IDEMPIERE-2624 Cant confirm 0 qty on Movement Confirmation Voiding the confirmation voids the inventory move too * IDEMPIERE-1709 / IDEMPIERE-2624 Cant confirm 0 qty on Movement Confirmation Similar case found in MInOut - cannot void because of catch-22 Allow to void MInOut -> it automatically voids all pending confirmations * IDEMPIERE-1709 / IDEMPIERE-2624 Cant confirm 0 qty on Movement Confirmation Set quantities in zero when voiding movement confirmation --- .../src/org/compiere/model/MInOutLine.java | 22 +++++++++++-- .../org/compiere/model/MMovementConfirm.java | 31 +++++++++++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MInOutLine.java b/org.adempiere.base/src/org/compiere/model/MInOutLine.java index 50969cebd0..3e45cea184 100644 --- a/org.adempiere.base/src/org/compiere/model/MInOutLine.java +++ b/org.adempiere.base/src/org/compiere/model/MInOutLine.java @@ -517,8 +517,26 @@ public class MInOutLine extends X_M_InOutLine if (getParent().pendingConfirmations()) { if ( newRecord || (is_ValueChanged(COLUMNNAME_MovementQty) && !is_ValueChanged(COLUMNNAME_TargetQty))) { - log.saveError("SaveError", Msg.parseTranslation(getCtx(), "@Open@: @M_InOutConfirm_ID@")); - return false; + + if (getMovementQty().signum() == 0) + { + String docAction = getParent().getDocAction(); + String docStatus = getParent().getDocStatus(); + if ( MInOut.DOCACTION_Void.equals(docAction) + && ( MInOut.DOCSTATUS_Drafted.equals(docStatus) + || MInOut.DOCSTATUS_Invalid.equals(docStatus) + || MInOut.DOCSTATUS_InProgress.equals(docStatus) + || MInOut.DOCSTATUS_Approved.equals(docStatus) + || MInOut.DOCSTATUS_NotApproved.equals(docStatus) + ) + ) + { + // OK to save qty=0 when voiding + } else { + log.saveError("SaveError", Msg.parseTranslation(getCtx(), "@Open@: @M_InOutConfirm_ID@")); + return false; + } + } } } // Locator is mandatory if no charge is defined - teo_sarca BF [ 2757978 ] diff --git a/org.adempiere.base/src/org/compiere/model/MMovementConfirm.java b/org.adempiere.base/src/org/compiere/model/MMovementConfirm.java index b2c7222150..4bb131c938 100644 --- a/org.adempiere.base/src/org/compiere/model/MMovementConfirm.java +++ b/org.adempiere.base/src/org/compiere/model/MMovementConfirm.java @@ -604,12 +604,39 @@ public class MMovementConfirm extends X_M_MovementConfirm implements DocAction m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_BEFORE_VOID); if (m_processMsg != null) return false; + + + MMovement move = new MMovement (getCtx(), getM_Movement_ID(), get_TrxName()); + for (MMovementLineConfirm confirmLine : getLines(true)) + { + confirmLine.setTargetQty(Env.ZERO); + confirmLine.setConfirmedQty(Env.ZERO); + confirmLine.setScrappedQty(Env.ZERO); + confirmLine.setDifferenceQty(Env.ZERO); + confirmLine.setProcessed(true); + confirmLine.saveEx(); + } + + // set confirmation as processed to allow voiding the inventory move + setProcessed(true); + saveEx(); + + // voiding the confirmation voids also the inventory move + ProcessInfo processInfo = MWorkflow.runDocumentActionWorkflow(move, DocAction.ACTION_Void); + if (processInfo.isError()) + { + m_processMsg = processInfo.getSummary(); + setProcessed(false); + return false; + } + // After Void m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_AFTER_VOID); if (m_processMsg != null) return false; - - return false; + + setDocAction(DOCACTION_None); + return true; } // voidIt /**