Ignore:
Timestamp:
Oct 4, 2010, 6:45:47 PM (14 years ago)
Author:
gav
Message:

Work around for 'more than 4' bug in inventory value reports.
The inventoryGroup and inventoryType lists as layed out on the reports cause an infinate loop and out of memory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/InventoryReportService.groovy

    r676 r677  
    238238        } // for
    239239
     240        /// @todo: This protects against a bug in the report layout, remove when solved.
     241        if(result.inventoryTypes.size() > 4)
     242            result.inventoryTypes = [[name:'More than 4']]
     243
     244        if(result.inventoryGroups.size() > 4)
     245            result.inventoryGroups =  [[name:'More than 4']]
     246
    240247        // Success.
    241248        return result
     
    287294                namedParams.siteId = result.site.id
    288295                and 'inventoryStore.site.id = :siteId'
     296                namedParams.groupIds = result.inventoryGroups.collect {it.id}
     297                and 'inventoryItem.inventoryGroup.id in(:groupIds)'
     298                namedParams.typeIds = result.inventoryTypes.collect {it.id}
     299                and 'inventoryItem.inventoryType.id in(:typeIds)'
    289300        }
    290301        def baseWhereLogic = new ArrayList(q.whereClauseTerms)
     
    292303        // Count the inventoryItems.
    293304        q.select = 'count(distinct inventoryItem)'
    294         result.inventoryItemCount = InventoryItem.executeQuery(q.query, q.namedParams, q.paginateParams)[0]
     305        result.inventoryItemCount = InventoryItem.executeQuery(q.query, q.namedParams)[0]
    295306
    296307        // Get the first currency found on this site.
     
    308319
    309320        // Get values for each group.
    310         q.and 'inventoryItem.inventoryGroup.id = :groupId'
    311321        def tempGroups = []
    312322        result.inventoryGroups.each() { group ->
    313             q.namedParams.groupId = group.id
     323            q.namedParams.groupIds = [group.id]
    314324            def groupValue = InventoryItem.executeQuery(q.query, q.namedParams)[0] ?: 0
    315325            tempGroups << [name: group.name, value: groupValue]
    316326        }
    317 
    318         // Cleanup and reset query.
    319         q.namedParams.remove('groupId')
    320         q.whereClauseTerms = baseWhereLogic
     327        q.namedParams.groupIds = result.inventoryGroups.collect {it.id} // reset.
    321328        result.inventoryGroups = tempGroups
    322329
    323330        // Get values for each type.
    324         q.and 'inventoryItem.inventoryType.id = :typeId'
    325331        def tempTypes = []
    326332        result.inventoryTypes.each() { type ->
    327             q.namedParams.typeId = type.id
     333            q.namedParams.typeIds = [type.id]
    328334            def typeValue = InventoryItem.executeQuery(q.query, q.namedParams)[0] ?: 0
    329335            tempTypes << [name: type.name, value: typeValue]
    330336        }
    331 
    332         // Cleanup and reset query.
    333         q.namedParams.remove('typeId')
    334         q.whereClauseTerms = baseWhereLogic
    335337        result.inventoryTypes = tempTypes
    336338
     339        /// @todo: This protects against a bug in the report layout, remove when solved.
     340        if(result.inventoryTypes.size() > 4)
     341            result.inventoryTypes = [[name:'More than 4', value: 0]]
     342
     343        if(result.inventoryGroups.size() > 4)
     344            result.inventoryGroups =  [[name:'More than 4', value: 0]]
     345
     346        // Check all currency is the same.
    337347        if(currencyCount != 1)
    338348            fail(code:'report.error.multiple.currency.found') // No return, populate errors but continue report.
Note: See TracChangeset for help on using the changeset viewer.