The deposit was most likely not a taxable transaction. So you should not have applied a tax code. You were just recording a receipt on account. It should have been handled according to this Guide: https://www.manager.io/guides/7093.
When you raise the sales invoice, apply the sales tax code. That is when tax becomes payable (in most cases). The deposit will be automatically applied to reduce the balance due on the sales invoice.
Now, in some cases, deposits are taxable as partial invoices. In that case, you should raise a sales invoice for the deposit and apply the tax code to it. Then, when the job is complete or the goods are delivered, you raise a second sales invoice for the balance of the job and apply the tax code to it.
The key to understanding this is realizing that it is the sale that is taxable, not the receipt or the deposit. Another way to think about it is that a deposit before the invoice is little different from a receipt after the invoice, except for timing. It’s the invoice where you apply the tax.