'Handle Updates of entries to reset the hidden start_date
Update Project Status at all levels'

def project_indicator_data_ondelete(self, row):

    db = current.db
    s3db = current.s3db
    table = s3db.project_indicator_data
    record_id = row.get('id')
    record = db((table.id == record_id)).select(table.deleted_fk, table.start_date, table.end_date, limitby=(0, 1)).first()
    try:
        fks = json.loads(record.deleted_fk)
        indicator_id = fks['indicator_id']
    except:
        current.log.error('Cannot    find    Project    Indicator    Data    record    (no    record    for    this    ID),    so    cannot    update    start_date    or    statuses')
        return
    start_date = record.start_date
    end_date = record.end_date
    query = (((table.indicator_id == indicator_id) & (table.deleted == False)) & (table.end_date < end_date))
    date_field = table.end_date
    record = db(query).select(date_field, limitby=(0, 1), orderby=date_field).first()
    if (record and (record[date_field] != start_date)):
        db((table.id == record_id)).update(start_date=record[date_field])
    query = (((table.indicator_id == indicator_id) & (table.deleted == False)) & (table.end_date > end_date))
    record = db(query).select(table.id, table.start_date, date_field, limitby=(0, 1), orderby=date_field).first()
    if (record and (record.start_date != end_date)):
        db((table.id == record.id)).update(start_date=end_date)
    table = s3db.project_indicator
    row = db((table.id == indicator_id)).select(table.project_id, limitby=(0, 1)).first()
    try:
        project_id = row.project_id
    except:
        current.log.error('Cannot    find    Project    record    (no    record    for    this    ID),    so    cannot    update    statuses')
    else:
        self.project_planning_status_update(project_id)
