Migration of account_invoice_reference

Added some tests in the process and fixed a few issues (going to backport them)
Because if something other than an browse_record is passed here, it is a developer error, not a user error.