Purchase Credit Invoice

We purchase material from a supplier in containers that have a deposit.
The deposit is included on the invoice from the supplier.
If the container is returned to the supplier , the supplier issues a Credit Memo.
The Credit Memo is in the form of a Invoice with a negative total.

How may I record this transaction?

There are different size containers with different deposit prices, currently each container deposit is a variant. The deposit is in Work in Progress warehouse. There is no separate account for deposits. I would prefer not to have to apply the Credit against a Purchase Invoice , rather apply the credit towards a liability account.

@smino you can track using Custom Field and make separate Journal Entries (un-linked?)

Just curious , there are Fields 12 (Is return) and 13 (Return against purchase) if I look at customizing the form . There Is Return Field on Purchase Invoice form is there but it does not function. What do they do?

Ideally the entry of the credit invoice would update stock inventory and credit the account payable for the supplier, and debit the appropriate liability account for the company. As it is now, the grand total cannot be less than zero.