'Ondelete-cascade method for inspection task links:
- close the linked task if there are no other
unresolved flags linked to it'

@staticmethod
def shelter_inspection_task_ondelete_cascade(row, tablename=None):

    db = current.db
    s3db = current.s3db
    ltable = s3db.cr_shelter_inspection_task
    query = (ltable.id == row.id)
    link = db(query).select(ltable.id, ltable.task_id, limitby=(0, 1)).first()
    task_id = link.task_id
    ftable = s3db.cr_shelter_inspection_flag
    ttable = s3db.project_task
    query = (((((ltable.task_id == task_id) & (ltable.id != link.id)) & (ltable.deleted != True)) & (ftable.id == ltable.inspection_flag_id)) & ((ftable.resolved == False) | (ftable.resolved == None)))
    other = db(query).select(ltable.id, limitby=(0, 1)).first()
    if (not other):
        closed = current.deployment_settings.get_cr_shelter_inspection_task_completed_status()
        db((ttable.id == task_id)).update(status=closed)
        link.update_record(task_id=None)
