IDEMPIERE-3388 Manual posting of MR break Average PO costing.
This commit is contained in:
parent
b17ce13062
commit
296878a2c3
|
@ -39,6 +39,10 @@ import org.compiere.model.MAccount;
|
|||
import org.compiere.model.MAcctSchema;
|
||||
import org.compiere.model.MConversionRate;
|
||||
import org.compiere.model.MDocType;
|
||||
import org.compiere.model.MInOut;
|
||||
import org.compiere.model.MInvoice;
|
||||
import org.compiere.model.MMatchInv;
|
||||
import org.compiere.model.MMatchPO;
|
||||
import org.compiere.model.MNote;
|
||||
import org.compiere.model.MPeriod;
|
||||
import org.compiere.model.ModelValidationEngine;
|
||||
|
@ -51,6 +55,7 @@ import org.compiere.util.DB;
|
|||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
import org.compiere.util.Trx;
|
||||
import org.compiere.util.Util;
|
||||
|
||||
/**
|
||||
* Posting Document Root.
|
||||
|
@ -238,6 +243,77 @@ public abstract class Doc
|
|||
return DocManager.postDocument(ass, AD_Table_ID, Record_ID, force, true, trxName);
|
||||
} // post
|
||||
|
||||
/**
|
||||
* Manual posting by user
|
||||
* @param WindowNo
|
||||
* @param AD_Client_ID
|
||||
* @param AD_Table_ID
|
||||
* @param Record_ID
|
||||
* @param force
|
||||
* @return error message ( if any )
|
||||
*/
|
||||
public static String manualPosting (int WindowNo, int AD_Client_ID,
|
||||
int AD_Table_ID, int Record_ID, boolean force)
|
||||
{
|
||||
String error = null;
|
||||
MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(Env.getCtx(), AD_Client_ID);
|
||||
Trx trx = Trx.get(Trx.createTrxName("ManulPosting"), true);
|
||||
try
|
||||
{
|
||||
error = postImmediate(ass, AD_Table_ID, Record_ID, force, trx.getTrxName());
|
||||
//Average Costing: Post MatchPO and MatchInv together with MR and Invoice
|
||||
if (Util.isEmpty(error))
|
||||
{
|
||||
if (AD_Table_ID == MInvoice.Table_ID)
|
||||
{
|
||||
MMatchInv[] matchInvs = MMatchInv.getInvoice(Env.getCtx(), Record_ID, trx.getTrxName());
|
||||
for (MMatchInv matchInv : matchInvs)
|
||||
{
|
||||
if (!matchInv.isPosted())
|
||||
{
|
||||
error = postImmediate(ass, matchInv.get_Table_ID(), matchInv.get_ID(), force, matchInv.get_TrxName());
|
||||
if (!Util.isEmpty(error))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (AD_Table_ID == MInOut.Table_ID)
|
||||
{
|
||||
MMatchPO[] matchPos = MMatchPO.getInOut(Env.getCtx(), Record_ID, trx.getTrxName());
|
||||
for (MMatchPO matchPo : matchPos)
|
||||
{
|
||||
if (!matchPo.isPosted())
|
||||
{
|
||||
error = postImmediate(ass, matchPo.get_Table_ID(), matchPo.get_ID(), force, matchPo.get_TrxName());
|
||||
if (!Util.isEmpty(error))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Util.isEmpty(error))
|
||||
{
|
||||
trx.commit(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
trx.rollback();
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
trx.rollback();
|
||||
return "@Error@ " + t.getLocalizedMessage();
|
||||
}
|
||||
finally
|
||||
{
|
||||
trx.close();
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/** Static Log */
|
||||
protected static CLogger s_log = CLogger.getCLogger(Doc.class);
|
||||
/** Log per Document */
|
||||
|
|
|
@ -47,6 +47,7 @@ import javax.swing.RepaintManager;
|
|||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.compiere.acct.Doc;
|
||||
import org.compiere.db.CConnection;
|
||||
import org.compiere.grid.ed.Calculator;
|
||||
import org.compiere.interfaces.Server;
|
||||
|
@ -54,7 +55,6 @@ import org.compiere.model.MMenu;
|
|||
import org.compiere.model.MQuery;
|
||||
import org.compiere.model.MRole;
|
||||
import org.compiere.model.MTable;
|
||||
import org.compiere.process.DocumentEngine;
|
||||
import org.compiere.swing.CButton;
|
||||
import org.compiere.swing.CFrame;
|
||||
import org.compiere.swing.CMenuItem;
|
||||
|
@ -874,9 +874,7 @@ public final class AEnv
|
|||
+ ", AD_Table_ID=" + AD_Table_ID + "/" + Record_ID
|
||||
+ ", Force=" + force);
|
||||
|
||||
String error = DocumentEngine.postImmediate(Env.getCtx(), AD_Client_ID, AD_Table_ID, Record_ID, force, null);
|
||||
|
||||
return error;
|
||||
return Doc.manualPosting(WindowNo, AD_Client_ID, AD_Table_ID, Record_ID, force);
|
||||
} // postImmediate
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,7 +47,6 @@ import org.compiere.acct.Doc;
|
|||
import org.compiere.model.GridWindowVO;
|
||||
import org.compiere.model.I_AD_Window;
|
||||
import org.compiere.model.Lookup;
|
||||
import org.compiere.model.MAcctSchema;
|
||||
import org.compiere.model.MClient;
|
||||
import org.compiere.model.MLanguage;
|
||||
import org.compiere.model.MLookup;
|
||||
|
@ -340,11 +339,7 @@ public final class AEnv
|
|||
+ ", AD_Table_ID=" + AD_Table_ID + "/" + Record_ID
|
||||
+ ", Force=" + force);
|
||||
|
||||
String error = null;
|
||||
MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(Env.getCtx(), AD_Client_ID);
|
||||
error = Doc.postImmediate(ass, AD_Table_ID, Record_ID, force, null);
|
||||
|
||||
return error;
|
||||
return Doc.manualPosting(WindowNo, AD_Client_ID, AD_Table_ID, Record_ID, force);
|
||||
} // postImmediate
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue