'Callback function used to look for duplicates during
the import process
@param item: the S3ImportItem to check'

@staticmethod
def supply_item_duplicate(item):

    data = item.data
    code = data.get('code')
    if code:
        table = item.table
        query = ((table.deleted != True) & (table.code.lower() == code.lower()))
        duplicate = current.db(query).select(table.id, limitby=(0, 1)).first()
        if duplicate:
            item.id = duplicate.id
            item.method = item.METHOD.UPDATE
            return
    else:
        name = data.get('name')
        if (not name):
            return
        um = data.get('um')
        if (not um):
            (name, um) = item_um_from_name(name)
        table = item.table
        query = ((table.deleted != True) & (table.name.lower() == name.lower()))
        if um:
            query &= (table.um.lower() == um.lower())
        catalog_id = data.get('catalog_id')
        if catalog_id:
            query &= (table.catalog_id == catalog_id)
        duplicate = current.db(query).select(table.id, limitby=(0, 1)).first()
        if duplicate:
            item.id = duplicate.id
            item.method = item.METHOD.UPDATE
