'Given a data dict coming from buckaroo, verify it and find the related
transaction record.'

@api.model
def _buckaroo_form_get_tx_from_data(self, data):

    origin_data = dict(data)
    data = normalize_keys_upper(data)
    (reference, pay_id, shasign) = (data.get('BRQ_INVOICENUMBER'), data.get('BRQ_PAYMENT'), data.get('BRQ_SIGNATURE'))
    if ((not reference) or (not pay_id) or (not shasign)):
        error_msg = (_('Buckaroo:    received    data    with    missing    reference    (%s)    or    pay_id    (%s)    or    shasign    (%s)') % (reference, pay_id, shasign))
        _logger.info(error_msg)
        raise ValidationError(error_msg)
    tx = self.search([('reference', '=', reference)])
    if ((not tx) or (len(tx) > 1)):
        error_msg = (_('Buckaroo:    received    data    for    reference    %s') % reference)
        if (not tx):
            error_msg += _(';    no    order    found')
        else:
            error_msg += _(';    multiple    order    found')
        _logger.info(error_msg)
        raise ValidationError(error_msg)
    shasign_check = tx.acquirer_id._buckaroo_generate_digital_sign('out', origin_data)
    if (shasign_check.upper() != shasign.upper()):
        error_msg = (_('Buckaroo:    invalid    shasign,    received    %s,    computed    %s,    for    data    %s') % (shasign, shasign_check, data))
        _logger.info(error_msg)
        raise ValidationError(error_msg)
    return tx
