Question about credit memos.

Just a quick question. How do you know which period to record credit memos? For example, lets say in December I received an invoice for a bunch widgets that I bought in 2012. However, some of the widgets were defective. So I called the manufacturer and they agreed to issue a credit memo which I received in January 2013. So, do I record that credit memo in 2012 or 2013?