Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 Base(object):
  7. #: Whether any prices exist
  8. exists = False
  9. #: Whether tax is known for this product (and session)
  10. is_tax_known = False
  11. # Normal price properties
  12. excl_tax = incl_tax = tax = None
  13. class Unavailable(Base):
  14. """
  15. No stockrecord, therefore no prices
  16. """
  17. class FixedPrice(Base):
  18. exists = True
  19. def __init__(self, excl_tax, tax=None):
  20. self.excl_tax = excl_tax
  21. self.tax = tax
  22. @property
  23. def incl_tax(self):
  24. if self.is_tax_known:
  25. return self.excl_tax + self.tax
  26. raise TaxNotKnown("Can't calculate price.incl_tax as tax isn't known")
  27. @property
  28. def is_tax_known(self):
  29. return self.tax is not None
  30. class DelegateToStockRecord(Base):
  31. def __init__(self, stockrecord):
  32. self.stockrecord = stockrecord
  33. @property
  34. def exists(self):
  35. return self.stockrecord is not None
  36. @property
  37. def excl_tax(self):
  38. return self.stockrecord.price_excl_tax
  39. @property
  40. def incl_tax(self):
  41. return self.stockrecord.price_incl_tax
  42. @property
  43. def tax(self):
  44. return self.stockrecord.price_tax