(data)
convert the parsed sms stock report into an instance like what would be
    submitted from a commcare phone
convert the parsed sms stock report into an instance like what would be
    submitted from a commcare phone
convert the parsed sms stock report into an instance like what would be submitted from a commcare phone
def to_instance(data):
    """convert the parsed sms stock report into an instance like what would be
    submitted from a commcare phone"""
    E = XML()
    M = XML(const.META_XMLNS, 'jrm')

    deviceID = get_device_id(data)
    timestamp = json_format_datetime(data['timestamp'])

    transactions = data['transactions']
    category = set(tx.category for tx in transactions).pop()
    stock_blocks = convert_transactions_to_blocks(E, transactions)

    if category == 'stock':
        root = E.stock_report(
            M.meta(
                M.userID(data['user']._id),
                M.deviceID(deviceID),
                M.timeStart(timestamp),
                M.timeEnd(timestamp)
            ),
            E.location(data['location']._id),
            *stock_blocks
        )
        return etree.tostring(root, encoding='utf-8', pretty_print=True)
    else:
        raise RequisitionsHaveBeenRemoved()
def to_instance ( data ) : E = XML ( ) M = XML ( const . META_XMLNS , 'jrm' ) deviceID = get_device_id ( data ) timestamp = json_format_datetime ( data [ 'timestamp' ] ) transactions = data [ 'transactions' ] category = set ( tx . category for tx in transactions ) . pop ( ) stock_blocks = convert_transactions_to_blocks ( E , transactions ) if category == 'stock' : root = E . stock_report ( M . meta ( M . userID ( data [ 'user' ] . _id ) , M . deviceID ( deviceID ) , M . timeStart ( timestamp ) , M . timeEnd ( timestamp ) ) , E . location ( data [ 'location' ] . _id ) , * stock_blocks ) return etree . tostring ( root , encoding = 'utf-8' , pretty_print = True ) else : raise RequisitionsHaveBeenRemoved ( )