Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. class TaxNotKnown(Exception):
  2. """
  3. Exception for when a tax-inclusive price is requested but we don't know
  4. what the tax applicable is (yet).
  5. """
  6. class Price(object):
  7. """
  8. Simple price class that encapsulates a price and its tax information
  9. Attributes:
  10. incl_tax (Decimal): Price including taxes
  11. excl_tax (Decimal): Price excluding taxes
  12. tax (Decimal): Tax amount
  13. is_tax_known (bool): Whether tax is known
  14. currency (str): 3 character currency code
  15. """
  16. def __init__(self, currency, excl_tax, incl_tax=None, tax=None):
  17. self.currency = currency
  18. self.excl_tax = excl_tax
  19. if incl_tax is not None:
  20. self.incl_tax = incl_tax
  21. self.is_tax_known = True
  22. elif tax is not None:
  23. self.incl_tax = excl_tax + tax
  24. self.is_tax_known = True
  25. else:
  26. self.incl_tax = None
  27. self.is_tax_known = False
  28. def _get_tax(self):
  29. return self.incl_tax - self.excl_tax
  30. def _set_tax(self, value):
  31. self.incl_tax = self.excl_tax + value
  32. self.is_tax_known = True
  33. tax = property(_get_tax, _set_tax)
  34. def __repr__(self):
  35. if self.is_tax_known:
  36. return "%s(currency=%r, excl_tax=%r, incl_tax=%r, tax=%r)" % (
  37. self.__class__.__name__, self.currency, self.excl_tax,
  38. self.incl_tax, self.tax)
  39. return "%s(currency=%r, excl_tax=%r)" % (
  40. self.__class__.__name__, self.currency, self.excl_tax)
  41. def __eq__(self, other):
  42. """
  43. Two price objects are equal if currency, price.excl_tax and tax match.
  44. """
  45. return (self.currency == other.currency and
  46. self.excl_tax == other.excl_tax and
  47. self.incl_tax == other.incl_tax)