def cr_update_capacity_from_housing_units(shelter_id):
 db = current.db
 stable = db.cr_shelter
 htable = db.cr_shelter_unit
 query = (((htable.shelter_id == shelter_id) & (htable.status == 1)) & (htable.deleted != True))
 total_capacity_day = htable.capacity_day.sum()
 total_capacity_night = htable.capacity_night.sum()
 row = db(query).select(total_capacity_day, total_capacity_night).first()
 if row:
  total_capacity_day = row[total_capacity_day]
  total_capacity_night = row[total_capacity_night]
 else:
  total_capacity_day = total_capacity_night = 0
 db((stable._id == shelter_id)).update(capacity_day=total_capacity_day, capacity_night=total_capacity_night)

def cr_update_capacity_from_housing_units ( shelter_id ) : db = current . db stable = db . cr_shelter htable = db . cr_shelter_unit query = ( ( ( htable . shelter_id == shelter_id ) & ( htable . status == 1 ) ) & ( htable . deleted != True ) ) total_capacity_day = htable . capacity_day . sum ( ) total_capacity_night = htable . capacity_night . sum ( ) row = db ( query ) . select ( total_capacity_day , total_capacity_night ) . first ( ) if row : total_capacity_day = row [ total_capacity_day ] total_capacity_night = row [ total_capacity_night ] else : total_capacity_day = total_capacity_night = 0 db ( ( stable . _id == shelter_id ) ) . update ( capacity_day = total_capacity_day , capacity_night = total_capacity_night )
update shelter capacity numbers .