'This callback will be called when importing records. It will look
to see if the record being imported is a duplicate.
@param item: An S3ImportItem object which includes all the details
of the record being imported
If the record is a duplicate then it will set the item method to update
Rules for finding a duplicate:
- If the Request Number matches
- The item is the same'

@staticmethod
def req_item_duplicate(item):

    db = current.db
    itable = item.table
    rtable = db.req_req
    stable = db.supply_item
    req_id = None
    item_id = None
    for ref in item.references:
        if (ref.entry.tablename == 'req_req'):
            if (ref.entry.id != None):
                req_id = ref.entry.id
            else:
                uuid = ref.entry.item_id
                jobitem = item.job.items[uuid]
                req_id = jobitem.id
        elif (ref.entry.tablename == 'supply_item'):
            if (ref.entry.id != None):
                item_id = ref.entry.id
            else:
                uuid = ref.entry.item_id
                jobitem = item.job.items[uuid]
                item_id = jobitem.id
    if ((req_id is not None) and (item_id is not None)):
        query = ((itable.req_id == req_id) & (itable.item_id == item_id))
    else:
        return
    duplicate = db(query).select(itable.id, limitby=(0, 1)).first()
    if duplicate:
        item.id = duplicate.id
        item.method = item.METHOD.UPDATE
