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

@staticmethod
def supply_item_category_duplicate(item):

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