Search in sources :

Example 11 with TrxRunnable

use of org.compiere.util.TrxRunnable in project adempiere by adempiere.

the class MDepreciationEntry method completeIt.

//	rejectIt
public String completeIt() {
    //	Re-Check
    if (!m_justPrepared) {
        String status = prepareIt();
        if (!DocAction.STATUS_InProgress.equals(status))
            return status;
    }
    //	Implicit Approval
    if (!isApproved()) {
        approveIt();
    }
    final MPeriod period = MPeriod.get(getCtx(), getC_Period_ID());
    final ArrayList<Exception> errors = new ArrayList<Exception>();
    final Iterator<MDepreciationExp> it = getLinesIterator(true);
    //
    while (it.hasNext()) {
        try {
            Trx.run(get_TrxName(), new TrxRunnable() {

                public void run(String trxName) {
                    MDepreciationExp depexp = it.next();
                    // Check if is in Period
                    if (!period.isInPeriod(depexp.getDateAcct())) {
                        throw new AssetException("The date is not within this Period" + " (" + depexp + ", Data=" + depexp.getDateAcct() + ", Period=" + period.getName() + // TODO: translate
                        ")");
                    }
                    depexp.process();
                }
            });
        } catch (Exception e) {
            log.log(Level.SEVERE, e.getLocalizedMessage(), e);
            errors.add(e);
        }
    }
    //
    if (errors.size() > 0) {
        throw new AssetArrayException(errors);
    }
    //	User Validation
    String valid = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_COMPLETE);
    if (valid != null) {
        m_processMsg = valid;
        return DocAction.STATUS_Invalid;
    }
    setProcessed(true);
    setDocAction(DOCACTION_Close);
    return DocAction.STATUS_Completed;
}
Also used : AssetArrayException(org.compiere.FA.exceptions.AssetArrayException) AssetException(org.compiere.FA.exceptions.AssetException) ArrayList(java.util.ArrayList) TrxRunnable(org.compiere.util.TrxRunnable) AdempiereException(org.adempiere.exceptions.AdempiereException) AssetArrayException(org.compiere.FA.exceptions.AssetArrayException) AssetException(org.compiere.FA.exceptions.AssetException)

Aggregations

TrxRunnable (org.compiere.util.TrxRunnable)11 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 MProduct (org.compiere.model.MProduct)3 Arrays (java.util.Arrays)2 List (java.util.List)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 ListModelTable (org.adempiere.webui.component.ListModelTable)2 MAcctSchema (org.compiere.model.MAcctSchema)2 MCost (org.compiere.model.MCost)2 MCostElement (org.compiere.model.MCostElement)2 MCostType (org.compiere.model.MCostType)2 Query (org.compiere.model.Query)2 Env (org.compiere.util.Env)2 Msg (org.compiere.util.Msg)2 Trx (org.compiere.util.Trx)2 MWorkflow (org.compiere.wf.MWorkflow)2 MPPProductPlanning (org.eevolution.model.MPPProductPlanning)2 IOException (java.io.IOException)1