From 2ad8fdfb3e28f9f57406a6dcfb9dac258fd5516b Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sat, 22 Aug 2020 20:55:44 +0200 Subject: [PATCH] =?UTF-8?q?IDEMPIERE-2216:when=20make=20a=20warehouse=20or?= =?UTF-8?q?der=20(in=20counter=20document=20test)=E2=80=A6=20(#226)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * IDEMPIERE-2216:when make a warehouse order (in counter document test). new document material receipt is link with warehouse order not link with purchase order. it's correct? * IDEMPIERE-2240:when create "On Credit Order" in counter document mode. invoice vendor make wrong reference to sale order * IDEMPIERE-2257:can't complete invoice (vendor) generate from "order credit" by counter. Integrating patch from Hiep hieplq@hasuvimex.vn Changed syntax to be more readable Used Processed instead of checking list of DocStatus Co-authored-by: hieplq@hasuvimex.vn --- .../src/org/compiere/model/MInvoice.java | 27 +++++++++++-------- .../src/org/compiere/model/MInvoiceLine.java | 6 +++-- .../src/org/compiere/model/MOrder.java | 15 +++++++---- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MInvoice.java b/org.adempiere.base/src/org/compiere/model/MInvoice.java index cf2e92c209..f4a0072136 100644 --- a/org.adempiere.base/src/org/compiere/model/MInvoice.java +++ b/org.adempiere.base/src/org/compiere/model/MInvoice.java @@ -1873,20 +1873,25 @@ public class MInvoice extends X_C_Invoice implements DocAction && !isReversal()) { MInOutLine receiptLine = new MInOutLine (getCtx(),line.getM_InOutLine_ID(), get_TrxName()); - BigDecimal movementQty = receiptLine.getM_InOut().getMovementType().charAt(1) == '-' ? receiptLine.getMovementQty().negate() : receiptLine.getMovementQty(); - BigDecimal matchQty = isCreditMemo() ? line.getQtyInvoiced().negate() : line.getQtyInvoiced(); + MInOut receipt = receiptLine.getParent(); - if (movementQty.compareTo(matchQty) < 0) - matchQty = movementQty; + if (receipt.isProcessed()){ - MMatchInv inv = new MMatchInv(line, getDateInvoiced(), matchQty); - if (!inv.save(get_TrxName())) - { - m_processMsg = CLogger.retrieveErrorString("Could not create Invoice Matching"); - return DocAction.STATUS_Invalid; + BigDecimal movementQty = receiptLine.getM_InOut().getMovementType().charAt(1) == '-' ? receiptLine.getMovementQty().negate() : receiptLine.getMovementQty(); + BigDecimal matchQty = isCreditMemo() ? line.getQtyInvoiced().negate() : line.getQtyInvoiced(); + + if (movementQty.compareTo(matchQty) < 0) + matchQty = movementQty; + + MMatchInv inv = new MMatchInv(line, getDateInvoiced(), matchQty); + if (!inv.save(get_TrxName())) + { + m_processMsg = CLogger.retrieveErrorString("Could not create Invoice Matching"); + return DocAction.STATUS_Invalid; + } + matchInv++; + addDocsPostProcess(inv); } - matchInv++; - addDocsPostProcess(inv); } // Update Order Line diff --git a/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java b/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java index eb6a5ab06e..8f304810b6 100644 --- a/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java +++ b/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java @@ -63,8 +63,10 @@ public class MInvoiceLine extends X_C_InvoiceLine { if (sLine == null) return null; - final String whereClause = I_M_InOutLine.COLUMNNAME_M_InOutLine_ID+"=?"; - List list = new Query(sLine.getCtx(),I_C_InvoiceLine.Table_Name,whereClause,sLine.get_TrxName()) + + final String whereClause = "C_InvoiceLine.M_InOutLine_ID=? AND C_Invoice.Processed='Y'"; + final String joinInvoice = "JOIN C_Invoice ON (C_Invoice.C_Invoice_ID = C_InvoiceLine.C_Invoice_ID)"; + List list = new Query(sLine.getCtx(),I_C_InvoiceLine.Table_Name,whereClause,sLine.get_TrxName()).addJoinClause(joinInvoice) .setParameters(sLine.getM_InOutLine_ID()) .list(); diff --git a/org.adempiere.base/src/org/compiere/model/MOrder.java b/org.adempiere.base/src/org/compiere/model/MOrder.java index eb40d16157..d3eb3b352e 100644 --- a/org.adempiere.base/src/org/compiere/model/MOrder.java +++ b/org.adempiere.base/src/org/compiere/model/MOrder.java @@ -136,8 +136,11 @@ public class MOrder extends X_C_Order implements DocAction // if (!to.save(trxName)) throw new IllegalStateException("Could not create Order"); - if (counter) + if (counter){ + // save to other counter document can re-get refer document from.setRef_Order_ID(to.getC_Order_ID()); + from.saveEx(); + } if (to.copyLinesFrom(from, counter, copyASI) == 0) throw new IllegalStateException("Could not create Order Lines"); @@ -1932,6 +1935,12 @@ public class MOrder extends X_C_Order implements DocAction boolean realTimePOS = MSysConfig.getBooleanValue(MSysConfig.REAL_TIME_POS, false , getAD_Client_ID()); + // Counter Documents + // move by IDEMPIERE-2216 + MOrder counter = createCounterDoc(); + if (counter != null) + info.append(" - @CounterDoc@: @Order@=").append(counter.getDocumentNo()); + // Create SO Shipment - Force Shipment MInOut shipment = null; if (MDocType.DOCSUBTYPESO_OnCreditOrder.equals(DocSubTypeSO) // (W)illCall(I)nvoice @@ -1976,10 +1985,6 @@ public class MOrder extends X_C_Order implements DocAction return DocAction.STATUS_Invalid; } - // Counter Documents - MOrder counter = createCounterDoc(); - if (counter != null) - info.append(" - @CounterDoc@: @Order@=").append(counter.getDocumentNo()); // User Validation String valid = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_COMPLETE); if (valid != null)