'Update the Human Resource record with the site_id'

@staticmethod
def hrm_human_resource_site_onaccept(form):

    try:
        form_vars = form.vars
    except:
        _id = form.id
        delete = True
    else:
        _id = form_vars.id
        delete = False
    db = current.db
    ltable = db.hrm_human_resource_site
    table = db.hrm_human_resource
    if delete:
        record = db((ltable.id == _id)).select(ltable.deleted_fk, limitby=(0, 1)).first()
        if record:
            deleted_fks = json.loads(record.deleted_fk)
            human_resource_id = deleted_fks.get('human_resource_id')
            if human_resource_id:
                db((table.id == human_resource_id)).update(location_id=None, site_id=None, site_contact=False)
                current.auth.set_realm_entity(table, human_resource_id, force_update=True)
    else:
        human_resource_id = form_vars.human_resource_id
        rows = db((ltable.human_resource_id == human_resource_id)).select(ltable.id, ltable.site_id, ltable.human_resource_id, ltable.site_contact, orderby=(~ ltable.id))
        first = True
        for row in rows:
            if first:
                first = False
                continue
            db((ltable.id == row.id)).delete()
        record = rows.first()
        site_id = record.site_id
        db((table.id == human_resource_id)).update(site_id=site_id, site_contact=record.site_contact)
        entity = current.s3db.pr_get_pe_id('org_site', site_id)
        if entity:
            current.auth.set_realm_entity(table, human_resource_id, entity=entity, force_update=True)
        hrform = Storage(id=human_resource_id)
        hrm_human_resource_onaccept(hrform)
