'Custom lookup method for item category rows, does a
left join with the parent category. Parameters
key and fields are not used, but are kept for API
compatibility reasons.
@param values: the supply_item_category IDs'

def custom_lookup_rows(self, key, values, fields=[]):

    db = current.db
    table = current.s3db.supply_item_category
    ctable = db.supply_catalog
    ptable = db.supply_item_category.with_alias('supply_parent_item_category')
    gtable = db.supply_item_category.with_alias('supply_grandparent_item_category')
    left = [ctable.on((ctable.id == table.catalog_id)), ptable.on((ptable.id == table.parent_item_category_id)), gtable.on((gtable.id == ptable.parent_item_category_id))]
    qty = len(values)
    if (qty == 1):
        query = (table.id == values[0])
        limitby = (0, 1)
    else:
        query = table.id.belongs(values)
        limitby = (0, qty)
    rows = db(query).select(left=left, limitby=limitby, *self.fields)
    self.queries += 1
    return rows
