Search in sources :

Example 1 with ProjectClose

use of org.compiere.process.ProjectClose in project adempiere by adempiere.

the class MAssetAddition method updateSourceDocument.

//	afterSave
/**
	 * Update Source Document (Invoice, Project etc) Status
	 * @param isReversal is called from a reversal action (like Void, Reverse-Correct).
	 * 					We need this flag because that when we call the method from voidIt()
	 * 					the document is not marked as voided yet. Same thing applies for reverseCorrectIt too. 
	 */
private void updateSourceDocument(final boolean isReversalParam) {
    boolean isReversal = isReversalParam;
    // Check if this document is reversed/voided
    String docStatus = getDocStatus();
    if (!isReversal && (DOCSTATUS_Reversed.equals(docStatus) || DOCSTATUS_Voided.equals(docStatus))) {
        isReversal = true;
    }
    final String sourceType = getA_SourceType();
    // Invoice: mark C_InvoiceLine.A_Processed='Y' and set C_InvoiceLine.A_Asset_ID
    if (A_SOURCETYPE_Invoice.equals(sourceType) && isProcessed()) {
        int C_InvoiceLine_ID = getC_InvoiceLine_ID();
        MInvoiceLine invoiceLine = new MInvoiceLine(getCtx(), C_InvoiceLine_ID, get_TrxName());
        invoiceLine.setA_Processed(!isReversal);
        invoiceLine.setA_Asset_ID(isReversal ? 0 : getA_Asset_ID());
        invoiceLine.saveEx();
    } else // Project
    if (A_SOURCETYPE_Project.equals(sourceType) && isProcessed()) {
        if (isReversal) {
        // Project remains closed. We just void/reverse/reactivate the Addition
        } else {
            //TODO decide whether to close project first or later
            int project_id = getC_Project_ID();
            ProcessInfo pi = new ProcessInfo("", 0, MProject.Table_ID, project_id);
            pi.setAD_Client_ID(getAD_Client_ID());
            pi.setAD_User_ID(Env.getAD_User_ID(getCtx()));
            //
            ProjectClose proc = new ProjectClose();
            proc.startProcess(getCtx(), pi, Trx.get(get_TrxName(), false));
            if (pi.isError()) {
                throw new AssetException(pi.getSummary());
            }
        }
    } else // Import
    if (A_SOURCETYPE_Imported.equals(sourceType) && !isProcessed()) {
        if (is_new() && getI_FixedAsset_ID() > 0) {
            MIFixedAsset ifa = getI_FixedAsset(false);
            if (ifa != null) {
                ifa.setI_IsImported(true);
                ifa.setA_Asset_ID(getA_Asset_ID());
                ifa.saveEx(get_TrxName());
            }
        }
    } else // Manual
    if (A_SOURCETYPE_Manual.equals(sourceType) && isProcessed()) {
        // nothing to do
        log.fine("Nothing to do");
    }
}
Also used : ProjectClose(org.compiere.process.ProjectClose) AssetException(org.compiere.FA.exceptions.AssetException) ProcessInfo(org.compiere.process.ProcessInfo)

Aggregations

AssetException (org.compiere.FA.exceptions.AssetException)1 ProcessInfo (org.compiere.process.ProcessInfo)1 ProjectClose (org.compiere.process.ProjectClose)1