Migration of account_invoice_reference

Added some tests in the process and fixed a few issues (going to backport them)
Would not raising an except_orm be better here?