Migration of account_invoice_reference

Added some tests in the process and fixed a few issues (going to backport them)