Test invoice sequence before accessing id

issue3199
(transplanted from 0cf87321e787f66569b7df3f8c5d08b0d6655c33)

--HG--
extra : transplant_source : %0C%F8s%21%E7%87%F6ei%B7%DF%3F%8C%5D%08%B0%D6e%5C3