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

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

    s3db = current.s3db
    otable = s3db.org_organisation
    fields = [otable.id, otable.name, otable.acronym]
    show_parent = self.parent
    if show_parent:
        btable = s3db.org_organisation_branch
        ptable = otable.with_alias('org_parent_organisation')
        fields.append(ptable.name)
        left = [btable.on(((btable.branch_id == otable.id) & (btable.deleted != True))), ptable.on((ptable.id == btable.organisation_id))]
    else:
        left = []
    if self.translate:
        ltable = s3db.org_organisation_name
        left.append(ltable.on((((ltable.organisation_id == otable.id) & (ltable.deleted != True)) & (ltable.language == self.language))))
        fields.extend([ltable.name_l10n, ltable.acronym_l10n])
        if show_parent:
            lptable = ltable.with_alias('org_parent_organisation_name')
            fields.append(lptable.name_l10n)
            left.append(lptable.on((lptable.organisation_id == btable.organisation_id)))
    count = len(values)
    if (count == 1):
        query = (otable.id == values[0])
    else:
        query = otable.id.belongs(values)
    rows = current.db(query).select(left=left, limitby=(0, count), *fields)
    self.queries += 1
    return rows
