diff --git a/base/src/org/compiere/model/MInOut.java b/base/src/org/compiere/model/MInOut.java index 14f2f2ed1b..a07ee779a2 100644 --- a/base/src/org/compiere/model/MInOut.java +++ b/base/src/org/compiere/model/MInOut.java @@ -20,6 +20,7 @@ import java.io.File; import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.Timestamp; +import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.logging.Level; @@ -54,7 +55,7 @@ public class MInOut extends X_M_InOut implements DocAction /** * */ - private static final long serialVersionUID = 727186799622809208L; + private static final long serialVersionUID = -239302197968535277L; /** * Create Shipment From Order @@ -1481,14 +1482,16 @@ public class MInOut extends X_M_InOut implements DocAction iLine.save(); // update matched invoice with ASI inv.setM_AttributeSetInstance_ID(sLine.getM_AttributeSetInstance_ID()); } + boolean isNewMatchInv = false; + if (inv.get_ID() == 0) + isNewMatchInv = true; if (!inv.save(get_TrxName())) { m_processMsg = CLogger.retrieveErrorString("Could not create Inv Matching"); return DocAction.STATUS_Invalid; } - if (MClient.isClientAccountingImmediate()) { - String ignoreError = DocumentEngine.postImmediate(inv.getCtx(), inv.getAD_Client_ID(), inv.get_Table_ID(), inv.get_ID(), true, inv.get_TrxName()); - } + if (isNewMatchInv) + addDocsPostProcess(inv); } } @@ -1498,14 +1501,16 @@ public class MInOut extends X_M_InOut implements DocAction log.fine("PO Matching"); // Ship - PO MMatchPO po = MMatchPO.create (null, sLine, getMovementDate(), matchQty); + boolean isNewMatchPO = false; + if (po.get_ID() == 0) + isNewMatchPO = true; if (!po.save(get_TrxName())) { m_processMsg = "Could not create PO Matching"; return DocAction.STATUS_Invalid; } - if (MClient.isClientAccountingImmediate()) { - String ignoreError = DocumentEngine.postImmediate(po.getCtx(), po.getAD_Client_ID(), po.get_Table_ID(), po.get_ID(), true, po.get_TrxName()); - } + if (isNewMatchPO) + addDocsPostProcess(po); // Update PO with ASI if ( oLine != null && oLine.getM_AttributeSetInstance_ID() == 0 && sLine.getMovementQty().compareTo(oLine.getQtyOrdered()) == 0) // just if full match [ 1876965 ] @@ -1524,14 +1529,16 @@ public class MInOut extends X_M_InOut implements DocAction // Ship - Invoice MMatchPO po = MMatchPO.create (iLine, sLine, getMovementDate(), matchQty); + boolean isNewMatchPO = false; + if (po.get_ID() == 0) + isNewMatchPO = true; if (!po.save(get_TrxName())) { m_processMsg = "Could not create PO(Inv) Matching"; return DocAction.STATUS_Invalid; } - if (MClient.isClientAccountingImmediate()) { - String ignoreError = DocumentEngine.postImmediate(po.getCtx(), po.getAD_Client_ID(), po.get_Table_ID(), po.get_ID(), true, po.get_TrxName()); - } + if (isNewMatchPO) + addDocsPostProcess(po); // Update PO with ASI oLine = new MOrderLine (getCtx(), po.getC_OrderLine_ID(), get_TrxName()); if ( oLine != null && oLine.getM_AttributeSetInstance_ID() == 0 @@ -1572,6 +1579,17 @@ public class MInOut extends X_M_InOut implements DocAction return DocAction.STATUS_Completed; } // completeIt + /* Save array of documents to process AFTER completing this one */ + ArrayList docsPostProcess = new ArrayList(); + + private void addDocsPostProcess(PO doc) { + docsPostProcess.add(doc); + } + + public ArrayList getDocsPostProcess() { + return docsPostProcess; + } + /** * Automatically creates a customer shipment for any * drop shipment material receipt diff --git a/base/src/org/compiere/model/MInvoice.java b/base/src/org/compiere/model/MInvoice.java index ba04c2c418..88e67008c2 100644 --- a/base/src/org/compiere/model/MInvoice.java +++ b/base/src/org/compiere/model/MInvoice.java @@ -61,8 +61,7 @@ public class MInvoice extends X_C_Invoice implements DocAction /** * */ - private static final long serialVersionUID = 5406556271212363271L; - + private static final long serialVersionUID = 816227083897031327L; /** * Get Payments Of BPartner @@ -1676,17 +1675,17 @@ public class MInvoice extends X_C_Invoice implements DocAction BigDecimal matchQty = line.getQtyInvoiced(); MMatchPO po = MMatchPO.create (line, null, getDateInvoiced(), matchQty); + boolean isNewMatchPO = false; + if (po.get_ID() == 0) + isNewMatchPO = true; if (!po.save(get_TrxName())) { m_processMsg = "Could not create PO Matching"; return DocAction.STATUS_Invalid; } - else { - matchPO++; - if (MClient.isClientAccountingImmediate()) { - String ignoreError = DocumentEngine.postImmediate(po.getCtx(), po.getAD_Client_ID(), po.get_Table_ID(), po.get_ID(), true, po.get_TrxName()); - } - } + matchPO++; + if (isNewMatchPO) + addDocsPostProcess(po); } } @@ -1719,17 +1718,17 @@ public class MInvoice extends X_C_Invoice implements DocAction matchQty = receiptLine.getMovementQty(); MMatchInv inv = new MMatchInv(line, getDateInvoiced(), matchQty); + boolean isNewMatchInv = false; + if (inv.get_ID() == 0) + isNewMatchInv = true; if (!inv.save(get_TrxName())) { m_processMsg = CLogger.retrieveErrorString("Could not create Invoice Matching"); return DocAction.STATUS_Invalid; } - else { - matchInv++; - if (MClient.isClientAccountingImmediate()) { - String ignoreError = DocumentEngine.postImmediate(inv.getCtx(), inv.getAD_Client_ID(), inv.get_Table_ID(), inv.get_ID(), true, inv.get_TrxName()); - } - } + matchInv++; + if (isNewMatchInv) + addDocsPostProcess(inv); } } // for all lines if (matchInv > 0) @@ -1858,6 +1857,17 @@ public class MInvoice extends X_C_Invoice implements DocAction return DocAction.STATUS_Completed; } // completeIt + /* Save array of documents to process AFTER completing this one */ + ArrayList docsPostProcess = new ArrayList(); + + private void addDocsPostProcess(PO doc) { + docsPostProcess.add(doc); + } + + public ArrayList getDocsPostProcess() { + return docsPostProcess; + } + /** * Set the definite document number after completed */ diff --git a/base/src/org/compiere/model/PO.java b/base/src/org/compiere/model/PO.java index 1573637307..cc9b4a1362 100644 --- a/base/src/org/compiere/model/PO.java +++ b/base/src/org/compiere/model/PO.java @@ -95,7 +95,7 @@ public abstract class PO /** * */ - private static final long serialVersionUID = 4112064325136026951L; + private static final long serialVersionUID = 6604764467216189092L; private static final String USE_TIMEOUT_FOR_UPDATE = "org.adempiere.po.useTimeoutForUpdate"; @@ -829,7 +829,7 @@ public abstract class PO /* FR 2962094 - Finish implementation of weighted average costing Fill the column ProcessedOn (if it exists) with a bigdecimal representation of current timestamp (with nanoseconds) */ - private void setProcessedOn(String ColumnName, Object value, Object oldValue) { + public void setProcessedOn(String ColumnName, Object value, Object oldValue) { if ("Processed".equals(ColumnName) && value instanceof Boolean && ((Boolean)value).booleanValue() == true diff --git a/base/src/org/compiere/process/DocumentEngine.java b/base/src/org/compiere/process/DocumentEngine.java index f5bc00e628..810dadd554 100644 --- a/base/src/org/compiere/process/DocumentEngine.java +++ b/base/src/org/compiere/process/DocumentEngine.java @@ -44,10 +44,10 @@ import org.compiere.model.MMovement; import org.compiere.model.MOrder; import org.compiere.model.MPayment; import org.compiere.model.MTable; +import org.compiere.model.PO; import org.compiere.util.CLogger; import org.compiere.util.DB; import org.compiere.util.Env; -import org.compiere.util.Ini; import org.eevolution.model.I_DD_Order; import org.eevolution.model.I_HR_Process; import org.eevolution.model.I_PP_Cost_Collector; @@ -295,12 +295,36 @@ public class DocumentEngine implements DocAction || STATUS_WaitingConfirmation.equals(status); if (m_document != null && ok) { - MClient client = MClient.get(m_document.getCtx(), m_document.getAD_Client_ID()); + // PostProcess documents when invoice or inout (this is to postprocess the generated MatchPO and MatchInv if any) + ArrayList docsPostProcess = new ArrayList();; + if (m_document instanceof MInvoice || m_document instanceof MInOut) { + if (m_document instanceof MInvoice) { + docsPostProcess = ((MInvoice) m_document).getDocsPostProcess(); + } + if (m_document instanceof MInOut) { + docsPostProcess = ((MInOut) m_document).getDocsPostProcess(); + } + } + if (m_document instanceof PO && docsPostProcess.size() > 0) { + // Process (this is to update the ProcessedOn flag with a timestamp after the original document) + for (PO docafter : docsPostProcess) { + docafter.setProcessedOn("Processed", true, false); + docafter.save(); + } + } + if (STATUS_Completed.equals(status) && MClient.isClientAccountingImmediate()) { m_document.save(); postIt(); + + if (m_document instanceof PO && docsPostProcess.size() > 0) { + for (PO docafter : docsPostProcess) { + String ignoreError = DocumentEngine.postImmediate(docafter.getCtx(), docafter.getAD_Client_ID(), docafter.get_Table_ID(), docafter.get_ID(), true, docafter.get_TrxName()); + } + } } + } return ok; }