Should I keep the return records in a positive or negative amount?

I ask the best practitioners from veterans of financial programmers.

for example, PSUDO code:

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

If you store the return in a negative amount, I can just run the sum() all transactions to get the balance, the math operations will become a bit native.

If you store the return in a positive quantity, then it is more friendly for a person according to a formula such as purchase - refund = balance , I also do not need to invert to display the positive amount of return in the template.

Which should I choose to have more benefits and fewer errors?

+5
source share
1 answer

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

+3
source

All Articles