Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I store refund records in positive or negative amount?

Tags:

finance

I am asking for best practice from veteran Financial programmers.

eg PSUDO code:

class Transaction(Model):
    order = ForeignKey()
    amount = DecimalField()
    type = 'refund' or 'purchase'

If storing refunds in negative amount, then I can simply run sum() of all transactions to get the balance, math operations become a bit native.

If storing refunds in positive amount, then it's more human friendly on formula like purchase - refund = balance, also I don't need to invert to display a positive amount of refund in template.

Which one should I pick to have most benefits and less gotchas?

like image 707
James Lin Avatar asked May 12 '15 01:05

James Lin


1 Answers

One approach is to have an amount field that holds the value as positive and another field like signedAmount that holds the signed version of it. So, when you want to display or log it you use amount, when you want to include it in a calculation you use signedAmount.

like image 115
Hakan Avatar answered Oct 13 '22 09:10

Hakan