'Test a Staff which has a Site assigned after creation'

def _testStaffUpdateFromSite(self, address):

    db = current.db
    s3db = current.s3db
    gtable = s3db.gis_location
    record = Storage(name='Test    Site    Location')
    site_location_id = gtable.insert(**record)
    self.assertNotEqual(site_location_id, None)
    record['id'] = site_location_id
    s3db.onaccept(gtable, record, method='create')
    otable = s3db.org_office
    record = Storage(name='Test    Office', location_id=site_location_id)
    office_id = otable.insert(**record)
    self.assertNotEqual(office_id, None)
    record['id'] = office_id
    s3db.update_super(otable, record)
    s3db.onaccept(otable, record, method='create')
    site_id = record['site_id']
    ptable = s3db.pr_person
    record = Storage(first_name='Test', last_name='Person')
    person_id = ptable.insert(**record)
    self.assertNotEqual(person_id, None)
    record['id'] = person_id
    s3db.update_super(ptable, record)
    s3db.onaccept(ptable, record, method='create')
    if address:
        pe_id = record['pe_id']
        record = Storage(name='Test    Address    Location')
        address_location_id = gtable.insert(**record)
        self.assertNotEqual(address_location_id, None)
        record['id'] = address_location_id
        s3db.onaccept(gtable, record, method='create')
        atable = s3db.pr_address
        record = Storage(pe_id=pe_id, type=1, location_id=address_location_id)
        address_id = atable.insert(**record)
        self.assertNotEqual(address_id, None)
        record['id'] = address_id
        s3db.onaccept(atable, record, method='create')
    else:
        address_location_id = None
    htable = s3db.hrm_human_resource
    record = Storage(person_id=person_id, type=1)
    human_resource_id = htable.insert(**record)
    self.assertNotEqual(human_resource_id, None)
    record['id'] = human_resource_id
    s3db.update_super(htable, record)
    s3db.onaccept(htable, record, method='create')
    ltable = s3db.hrm_human_resource_site
    record = Storage(human_resource_id=human_resource_id, site_id=site_id)
    link_id = ltable.insert(**record)
    self.assertNotEqual(link_id, None)
    record['id'] = link_id
    s3db.onaccept(ltable, record, method='create')
    row = db((htable.id == human_resource_id)).select(htable.location_id, limitby=(0, 1)).first()
    self.assertNotEqual(row, None)
    return (row, address_location_id, site_location_id)
