'On-accept for Member records'

@staticmethod
def member_onaccept(form):

    db = current.db
    s3db = current.s3db
    auth = current.auth
    settings = current.deployment_settings
    utable = current.auth.settings.table_user
    ptable = s3db.pr_person
    ltable = s3db.pr_person_user
    mtable = db.member_membership
    _id = form.vars.id
    if _id:
        query = (mtable.id == _id)
        record = db(query).select(mtable.id, mtable.person_id, mtable.organisation_id, mtable.deleted, limitby=(0, 1)).first()
    else:
        return
    data = Storage()
    person_id = record.person_id
    person = Storage(id=person_id)
    if settings.get_auth_person_realm_member_org():
        organisation_id = record.organisation_id
        entity = s3db.pr_get_pe_id('org_organisation', organisation_id)
        if entity:
            auth.set_realm_entity(ptable, person, entity=entity, force_update=True)
    atable = s3db.pr_address
    query = ((((atable.pe_id == ptable.pe_id) & (ptable.id == record.person_id)) & (atable.type == 1)) & (atable.deleted == False))
    address = db(query).select(atable.location_id, limitby=(0, 1)).first()
    if address:
        data.location_id = address.location_id
    query = (((ptable.id == record.person_id) & (ltable.pe_id == ptable.pe_id)) & (utable.id == ltable.user_id))
    user = db(query).select(utable.id, utable.organisation_id, utable.site_id, limitby=(0, 1)).first()
    if user:
        data.owned_by_user = user.id
    if (not data):
        return
    record.update_record(**data)
