def org_site_has_inv(row, tablename='org_facility'):
 if (not current.deployment_settings.has_module('inv')):
  return False
 if hasattr(row, tablename):
  row = row[tablename]
 try:
  id = row.id
 except AttributeError:
  return None
 s3db = current.s3db
 itable = s3db.inv_inv_item
 stable = s3db[tablename]
 query = ((((itable.deleted != True) & (stable.id == id)) & (itable.site_id == stable.site_id)) & (itable.quantity > 0))
 inv = current.db(query).select(itable.id, limitby=(0, 1)).first()
 if inv:
  return True
 else:
  return False

def org_site_has_inv ( row , tablename = 'org_facility' ) : if ( not current . deployment_settings . has_module ( 'inv' ) ) : return False if hasattr ( row , tablename ) : row = row [ tablename ] try : id = row . id except AttributeError : return None s3db = current . s3db itable = s3db . inv_inv_item stable = s3db [ tablename ] query = ( ( ( ( itable . deleted != True ) & ( stable . id == id ) ) & ( itable . site_id == stable . site_id ) ) & ( itable . quantity > 0 ) ) inv = current . db ( query ) . select ( itable . id , limitby = ( 0 , 1 ) ) . first ( ) if inv : return True else : return False
whether a site has inventory .