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?
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With