fix InvoiceCalculateTax:

* unpost invoice because we need to repost it after changing tax amounts
* refactor + able to run process from outside
This commit is contained in:
teo_sarca 2008-12-04 11:29:52 +00:00
parent 1c913f8cbf
commit e9ac5e52df
1 changed files with 47 additions and 27 deletions

View File

@ -17,53 +17,73 @@ package org.eevolution.process;
import org.adempiere.exceptions.FillMandatoryException;
import org.compiere.model.MBPartner; import org.compiere.model.MBPartner;
import org.compiere.model.MFactAcct;
import org.compiere.model.MInvoice; import org.compiere.model.MInvoice;
import org.compiere.model.MPeriod;
import org.compiere.process.ProcessInfoParameter; import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess; import org.compiere.process.SvrProcess;
/** /**
* Invoice Calculate Tax let re calculate Tax Invoice * Re-calculate Invoice Tax (and unpost the document)
* @author Victor Perez * @author Victor Perez
* @author Teo Sarca, www.arhipac.ro * @author Teo Sarca, www.arhipac.ro
*/ */
public class InvoiceCalculateTax extends SvrProcess public class InvoiceCalculateTax extends SvrProcess
{ {
private int p_C_Invoice_ID = 0; public static final String PARAM_C_Invoice_ID = "C_Invoice_ID";
private int p_C_Invoice_ID = 0;
@Override @Override
protected void prepare() protected void prepare()
{ {
for (ProcessInfoParameter para : getParameter()) for (ProcessInfoParameter para : getParameter())
{ {
String name = para.getParameterName(); String name = para.getParameterName();
if (para.getParameter() == null) if (para.getParameter() == null)
{ {
; ;
} }
else if (name.equals("C_Invoice_ID")) else if (name.equals(PARAM_C_Invoice_ID))
{ {
p_C_Invoice_ID = para.getParameterAsInt(); p_C_Invoice_ID = para.getParameterAsInt();
} }
} }
if (p_C_Invoice_ID <= 0)
{
throw new FillMandatoryException(PARAM_C_Invoice_ID);
}
}
} // prepare @Override
protected String doIt() throws Exception
@Override {
protected String doIt() throws Exception
{
MInvoice invoice = new MInvoice(getCtx(), p_C_Invoice_ID, get_TrxName()); MInvoice invoice = new MInvoice(getCtx(), p_C_Invoice_ID, get_TrxName());
recalculateTax(invoice);
//
return "@ProcessOK@";
}
public static void recalculateTax(MInvoice invoice)
{
//
// Delete accounting /UnPost
MPeriod.testPeriodOpen(invoice.getCtx(), invoice.getDateAcct(), invoice.getC_DocType_ID());
MFactAcct.deleteEx(MInvoice.Table_ID, invoice.get_ID(), invoice.get_TrxName());
//
// Update Invoice
invoice.calculateTaxTotal(); invoice.calculateTaxTotal();
invoice.setPosted(false);
invoice.saveEx(); invoice.saveEx();
// //
// Update balance // Update balance
MBPartner bp = new MBPartner (getCtx(), invoice.getC_BPartner_ID(), get_TrxName()); MBPartner bp = new MBPartner (invoice.getCtx(), invoice.getC_BPartner_ID(), invoice.get_TrxName());
bp.setTotalOpenBalance(); bp.setTotalOpenBalance();
bp.setSOCreditStatus(); bp.setSOCreditStatus();
bp.saveEx(); bp.saveEx();
// }
return "@ProcessOK@";
} // doIt
} }