IDEMPIERE-3431 Posting error for Matched PO if invoice posted while MR is not posted

This commit is contained in:
Heng Sin Low 2017-09-12 18:07:01 +08:00
parent bfd3b422d4
commit a0d891f419
3 changed files with 52 additions and 2 deletions

View File

@ -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<Fact> getFacts() {
return m_fact;
}
/**
* Return document whether need to defer posting or not
*/
public boolean isDeferPosting() {
return false;
}
} // Doc

View File

@ -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
@ -103,6 +104,24 @@ public class Doc_MatchPO extends Doc
m_pc = new ProductCost (Env.getCtx(),
getM_Product_ID(), m_M_AttributeSetInstance_ID, getTrxName());
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

View File

@ -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)