You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from django.contrib.auth.models import User
  2. from django.db import models
  3. from django.utils.translation import ugettext as _
  4. class Source(models.Model):
  5. """
  6. A source of payment for an order.
  7. This is normally a credit card which has been pre-authed
  8. for the order amount, but some applications will allow orders to be paid for using multiple
  9. sources such as cheque, credit accounts, gift cards. Each payment source will have its own
  10. entry.
  11. """
  12. order = models.ForeignKey('order.Order', related_name='sources')
  13. type = models.CharField(max_length=128)
  14. initial_amount = models.IntegerField()
  15. balance = models.IntegerField()
  16. reference = models.CharField(max_length=128, blank=True, null=True)
  17. def __unicode__(self):
  18. description = "Payment of %.2f from %s" % (self.initial_amount, self.type)
  19. if self.reference:
  20. description += " (reference: %s)" % self.reference
  21. return description
  22. class Transaction(models.Model):
  23. """
  24. A transaction for payment sources which need a secondary 'transaction' to actually take the money
  25. This applies mainly to credit card sources which can be a pre-auth for the money. A 'complete'
  26. needs to be run later to debit the money from the account.
  27. """
  28. source = models.ForeignKey('payment.Source', related_name='transactions')
  29. type = models.CharField(max_length=128, blank=True)
  30. delta_amount = models.FloatField()
  31. reference = models.CharField(max_length=128)
  32. transaction_date = models.DateField()
  33. def __unicode__(self):
  34. return "Transaction of %.2f" % self.delta_amount