def org_parents(organisation_id, path=[]):
 if (not organisation_id):
  return path
 db = current.db
 s3db = current.s3db
 otable = s3db.org_organisation
 btable = s3db.org_organisation.with_alias('org_branch_organisation')
 ltable = s3db.org_organisation_branch
 query = (btable.id == organisation_id)
 join = (((((ltable.deleted != True) & (btable.deleted != True)) & (otable.deleted != True)) & (btable.id == ltable.branch_id)) & (otable.id == ltable.organisation_id))
 row = db((query & join)).select(otable.id, limitby=(0, 1)).first()
 if (row is not None):
  organisation_id = row.id
  path.insert(0, organisation_id)
  return org_parents(organisation_id, path)
 else:
  return path

def org_parents ( organisation_id , path = [ ] ) : if ( not organisation_id ) : return path db = current . db s3db = current . s3db otable = s3db . org_organisation btable = s3db . org_organisation . with_alias ( 'org_branch_organisation' ) ltable = s3db . org_organisation_branch query = ( btable . id == organisation_id ) join = ( ( ( ( ( ltable . deleted != True ) & ( btable . deleted != True ) ) & ( otable . deleted != True ) ) & ( btable . id == ltable . branch_id ) ) & ( otable . id == ltable . organisation_id ) ) row = db ( ( query & join ) ) . select ( otable . id , limitby = ( 0 , 1 ) ) . first ( ) if ( row is not None ) : organisation_id = row . id path . insert ( 0 , organisation_id ) return org_parents ( organisation_id , path ) else : return path
lookup the parent organisations of a branch organisation .