'Detect whether this is an update or a new record'

def deduplicate(self):

    table = self.table
    if ((table is None) or self.id):
        return
    METHOD = self.METHOD
    CREATE = METHOD['CREATE']
    UPDATE = METHOD['UPDATE']
    DELETE = METHOD['DELETE']
    MERGE = METHOD['MERGE']
    xml = current.xml
    UID = xml.UID
    data = self.data
    if (self.job.second_pass and (UID in table.fields)):
        uid = data.get(UID)
        if (uid and (not self.element.get(UID)) and (not self.original)):
            del data[UID]
    mandatory = self._mandatory_fields()
    if (self.original is not None):
        original = self.original
    elif self.data:
        original = S3Resource.original(table, self.data, mandatory=mandatory)
    else:
        original = None
    synchronise_uuids = current.response.s3.synchronise_uuids
    deleted = data[xml.DELETED]
    if deleted:
        if data[xml.REPLACEDBY]:
            self.method = MERGE
        else:
            self.method = DELETE
    self.uid = data.get(UID)
    if (original is not None):
        self.id = original[table._id.name]
        if (not deleted):
            self.method = UPDATE
    else:
        if ((UID in data) and (not synchronise_uuids)):
            self.id = None
            if (not deleted):
                self.method = CREATE
            else:
                self.method = DELETE
                self.skip = True
        else:
            resolve = current.s3db.get_config(self.tablename, 'deduplicate')
            if (data and resolve):
                resolve(self)
        if (self.id and (self.method in (UPDATE, DELETE, MERGE))):
            fields = S3Resource.import_fields(table, data, mandatory=mandatory)
            original = current.db((table._id == self.id)).select(limitby=(0, 1), *fields).first()
    if (original and (not synchronise_uuids) and (UID in original)):
        self.uid = data[UID] = original[UID]
    self.original = original
