Search in sources :

Example 1 with AssetInvoiceWithMixedLines_LRO

use of org.compiere.FA.exceptions.AssetInvoiceWithMixedLines_LRO in project adempiere by adempiere.

the class ModelValidator method validateFixedAssetsInvoice_LRO.

/**
	 * Check if is a valid fixed asset related invoice (LRO)
	 * @param invoice
	 */
private void validateFixedAssetsInvoice_LRO(MInvoice invoice) {
    if (invoice.get_ValueAsBoolean("IsFixedAssetInvoice")) {
        boolean hasFixedAssetLines = false;
        boolean hasNormalLines = false;
        for (MInvoiceLine line : invoice.getLines()) {
            if (line.get_ValueAsBoolean("IsFixedAssetInvoice")) {
                hasFixedAssetLines = true;
            } else if (line.getM_Product_ID() > 0) {
                MProduct product = MProduct.get(line.getCtx(), line.getM_Product_ID());
                if (product.isItem()) {
                    // Only items are forbiden for FA invoices because in Romania these should use
                    // V_Liability vendor account and not V_Liability_FixedAssets vendor account
                    hasNormalLines = true;
                }
            }
            // No mixed lines are allowed
            if (hasFixedAssetLines && hasNormalLines) {
                throw new AssetInvoiceWithMixedLines_LRO();
            }
        }
    }
}
Also used : MProduct(org.compiere.model.MProduct) MInvoiceLine(org.compiere.model.MInvoiceLine) AssetInvoiceWithMixedLines_LRO(org.compiere.FA.exceptions.AssetInvoiceWithMixedLines_LRO)

Aggregations

AssetInvoiceWithMixedLines_LRO (org.compiere.FA.exceptions.AssetInvoiceWithMixedLines_LRO)1 MInvoiceLine (org.compiere.model.MInvoiceLine)1 MProduct (org.compiere.model.MProduct)1