'Update all ancestor fields from immediate parent
Warn if totals are not equal to 1.0
@ToDo: Handle deployment_settings which have Indicators directly
attached to Projects
Update Project Status at all levels'

def project_indicator_onaccept(self, form, create=False):

    db = current.db
    s3db = current.s3db
    form_vars = form.vars
    record_id = form_vars.id
    table = s3db.project_indicator
    settings = current.deployment_settings
    if (settings.get_project_outputs() and (settings.get_project_outcomes() or settings.get_project_goals())):
        output_id = form_vars.get('output_id')
        if output_id:
            otable = s3db.project_output
            output = db((otable.id == output_id)).select(otable.goal_id, otable.outcome_id, limitby=(0, 1)).first()
            if output:
                db((table.id == record_id)).update(goal_id=output.goal_id, outcome_id=output.outcome_id)
            if (not create):
                query = (((table.output_id == output_id) & (table.deleted == False)) & (table.id != record_id))
                records = db(query).select(table.weighting)
                total = 0
                for r in records:
                    total += r.weighting
                total += form_vars.weighting
                if (total != 1.0):
                    current.response.warning = current.T('Weightings    should    add    up    to    1.0')
    elif (settings.get_project_outcomes() and settings.get_project_goals()):
        outcome_id = form_vars.get('outcome_id')
        if outcome_id:
            otable = s3db.project_outcome
            outcome = db((otable.id == outcome_id)).select(otable.goal_id, limitby=(0, 1)).first()
            if outcome:
                db((table.id == record_id)).update(goal_id=outcome.goal_id)
    row = db((table.id == record_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)
