'Make the last log entry before timestmp independent from
the referenced entity (if any)
@param timestmp: the date/time of the check-out, defaults
to current time'

def check_out(self, table=None, record=None, timestmp=None):

    db = current.db
    s3db = current.s3db
    ptable = s3db[PRESENCE]
    if (timestmp is None):
        timestmp = datetime.utcnow()
    interlock = None
    if (table is not None):
        if isinstance(table, str):
            table = s3db[table]
        if isinstance(record, Rows):
            record = record.first()
        if self.__super_entity(table):
            if (not isinstance(record, Row)):
                record = table[record]
            table = s3db[record.instance_type]
            fields = self.__get_fields(table, super_entity=False)
            if (not fields):
                raise SyntaxError(('No    trackable    type:    %s' % table._tablename))
            query = (table[UID] == record[UID])
            record = db(query).select(limitby=(0, 1)).first()
        if (isinstance(record, Row) and (table._id.name in record)):
            record = record[table._id.name]
        if record:
            interlock = ('%s,%s' % (table, record))
        else:
            return
    q = ((ptable.deleted == False) & (ptable.timestmp <= timestmp))
    for r in self.records:
        if (TRACK_ID not in r):
            continue
        query = (q & (ptable[TRACK_ID] == r[TRACK_ID]))
        presence = db(query).select(orderby=(~ ptable.timestmp), limitby=(0, 1)).first()
        if (presence and presence.interlock):
            if (interlock and (presence.interlock != interlock)):
                continue
            elif ((not interlock) and table and (not presence.interlock.startswith(('%s' % table)))):
                continue
            (tablename, record_id) = presence.interlock.split(',', 1)
            trackable = S3Trackable(tablename=tablename, record_id=record_id)
            location = trackable.get_location(_fields=['id'], timestmp=timestmp, as_rows=True).first()
            if ((timestmp - presence.timestmp) < timedelta(seconds=1)):
                timestmp = (timestmp + timedelta(seconds=1))
            data = dict(location_id=location.id, timestmp=timestmp, interlock=None)
            data.update({TRACK_ID: r[TRACK_ID]})
            ptable.insert(**data)
            self.__update_timestamp(r[TRACK_ID], timestmp)
