diff --git a/org.adempiere.base/src/org/compiere/acct/Doc.java b/org.adempiere.base/src/org/compiere/acct/Doc.java index 6364029fe1..1bc38d49ce 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc.java @@ -555,6 +555,12 @@ public abstract class Doc p_Error = loadDocumentDetails(); if (p_Error != null) return p_Error; + if (isDeferPosting()) + { + unlock(); + p_Status = STATUS_NotPosted; + return null; + } Trx trx = Trx.get(getTrxName(), true); // Delete existing Accounting @@ -2304,4 +2310,11 @@ public abstract class Doc public ArrayList getFacts() { return m_fact; } + + /** + * Return document whether need to defer posting or not + */ + public boolean isDeferPosting() { + return false; + } } // Doc diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_MatchPO.java b/org.adempiere.base/src/org/compiere/acct/Doc_MatchPO.java index 1d271a6b48..87a48da28b 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_MatchPO.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_MatchPO.java @@ -77,6 +77,7 @@ public class Doc_MatchPO extends Doc private ProductCost m_pc; private int m_M_AttributeSetInstance_ID = 0; private MMatchPO m_matchPO; + private boolean m_deferPosting = false; /** * Load Specific Document Details @@ -102,7 +103,25 @@ public class Doc_MatchPO extends Doc // m_pc = new ProductCost (Env.getCtx(), getM_Product_ID(), m_M_AttributeSetInstance_ID, getTrxName()); - m_pc.setQty(getQty()); + m_pc.setQty(getQty()); + + if (m_M_InOutLine_ID == 0) + { + MMatchPO[] matchPOs = MMatchPO.getOrderLine(getCtx(), m_oLine.getC_OrderLine_ID(), getTrxName()); + for (MMatchPO matchPO : matchPOs) + { + if (matchPO.getM_InOutLine_ID() > 0 && matchPO.getC_InvoiceLine_ID() == 0) + { + m_M_InOutLine_ID = matchPO.getM_InOutLine_ID(); + break; + } + } + } + + if (m_M_InOutLine_ID == 0) // Defer posting if not matched to Shipment + { + m_deferPosting = true; + } return null; } // loadDocumentDetails @@ -487,4 +506,11 @@ public class Doc_MatchPO extends Doc return null; } + + @Override + public boolean isDeferPosting() { + return m_deferPosting; + } + + } // Doc_MatchPO diff --git a/org.adempiere.server/src/main/server/org/compiere/server/AcctProcessor.java b/org.adempiere.server/src/main/server/org/compiere/server/AcctProcessor.java index c1c4b22876..09b27b5238 100644 --- a/org.adempiere.server/src/main/server/org/compiere/server/AcctProcessor.java +++ b/org.adempiere.server/src/main/server/org/compiere/server/AcctProcessor.java @@ -34,6 +34,7 @@ import org.compiere.model.MClient; import org.compiere.model.MCost; import org.compiere.model.MOrgInfo; import org.compiere.model.MRole; +import org.compiere.model.MTable; import org.compiere.model.MUser; import org.compiere.util.DB; import org.compiere.util.Env; @@ -224,7 +225,6 @@ public class AcctProcessor extends AdempiereServer rs = pstmt.executeQuery(); while (!isInterrupted() && rs.next()) { - count[i]++; boolean ok = true; try { @@ -238,6 +238,17 @@ public class AcctProcessor extends AdempiereServer } if (!ok) countError[i]++; + else // only count the posted record. + { + MTable table = MTable.get(Env.getCtx(), AD_Table_ID); + int Record_ID = rs.getInt(table.getKeyColumns()[0]); + sql = new StringBuffer("SELECT COUNT(*) FROM ").append(table.getTableName()); + sql.append(" WHERE Posted='Y' AND ").append(table.getTableName()).append("_ID=").append(Record_ID); + int no = DB.getSQLValue(null, sql.toString()); + if (no > 0 ) + count[i]++; + + } } } catch (Exception e)