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.

abstract_models.py 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from django.contrib.auth.models import User
  2. from django.db import models
  3. from django.utils.translation import ugettext as _
  4. class AbstractSource(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.ForeignKey('payment.SourceType')
  14. initial_amount = models.DecimalField(decimal_places=2, max_digits=12)
  15. balance = models.DecimalField(decimal_places=2, max_digits=12)
  16. reference = models.CharField(max_length=128, blank=True, null=True)
  17. class Meta:
  18. abstract = True
  19. def __unicode__(self):
  20. description = "Payment of %.2f from %s" % (self.initial_amount, self.type)
  21. if self.reference:
  22. description += " (reference: %s)" % self.reference
  23. return description
  24. class AbstractSourceType(models.Model):
  25. """
  26. A type of payment source (eg Bankcard, Business account, Gift card)
  27. """
  28. name = models.CharField(max_length=128)
  29. class Meta:
  30. abstract = True
  31. def __unicode__(self):
  32. return self.name
  33. class AbstractTransaction(models.Model):
  34. """
  35. A transaction for payment sources which need a secondary 'transaction' to actually take the money
  36. This applies mainly to credit card sources which can be a pre-auth for the money. A 'complete'
  37. needs to be run later to debit the money from the account.
  38. """
  39. source = models.ForeignKey('payment.Source', related_name='transactions')
  40. type = models.CharField(max_length=128, blank=True)
  41. delta_amount = models.FloatField()
  42. reference = models.CharField(max_length=128)
  43. date_created = models.DateField()
  44. class Meta:
  45. abstract = True
  46. def __unicode__(self):
  47. return "Transaction of %.2f" % self.delta_amount