'Update organisation affiliations for org_site instances.'

@staticmethod
def pr_pentity_onaccept(form):

    db = current.db
    s3db = current.s3db
    ptable = s3db.pr_pentity
    pe_id = form.vars.pe_id
    pe = db((ptable.pe_id == pe_id)).select(ptable.instance_type, limitby=(0, 1)).first()
    if pe:
        itable = s3db.table(pe.instance_type, None)
        if (itable and ('site_id' in itable.fields) and ('organisation_id' in itable.fields)):
            q = (itable.pe_id == pe_id)
            instance = db(q).select(itable.pe_id, itable.organisation_id, limitby=(0, 1)).first()
            if instance:
                s3db.org_update_affiliations('org_site', instance)
    return
