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.

prices.py 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. from oscar.core import prices
  2. class Base(object):
  3. """
  4. The interface that any pricing policy must support
  5. """
  6. #: Whether any prices exist
  7. exists = False
  8. #: Whether tax is known
  9. is_tax_known = False
  10. #: Price excluding tax
  11. excl_tax = None
  12. #: Price including tax
  13. incl_tax = None
  14. #: Price tax
  15. tax = None
  16. #: Price currency (3 char code)
  17. currency = None
  18. class Unavailable(Base):
  19. """
  20. This should be used as a pricing policy when a product is unavailable and
  21. no prices are known.
  22. """
  23. class FixedPrice(Base):
  24. """
  25. This should be used for when the price of a product is known in advance.
  26. It can work for when tax isn't known (like in the US).
  27. """
  28. exists = True
  29. def __init__(self, currency, excl_tax, tax=None):
  30. self.currency = currency
  31. self.excl_tax = excl_tax
  32. self.tax = tax
  33. @property
  34. def incl_tax(self):
  35. if self.is_tax_known:
  36. return self.excl_tax + self.tax
  37. raise prices.TaxNotKnown(
  38. "Can't calculate price.incl_tax as tax isn't known")
  39. @property
  40. def is_tax_known(self):
  41. return self.tax is not None
  42. class DelegateToStockRecord(Base):
  43. """
  44. Pricing policy which wraps around an existing stockrecord.
  45. This is backwards compatible with Oscar<0.6 where taxes were calculated by
  46. "partner wrappers" which wrapped around stockrecords.
  47. """
  48. is_tax_known = True
  49. def __init__(self, stockrecord):
  50. self.stockrecord = stockrecord
  51. @property
  52. def exists(self):
  53. return self.stockrecord is not None
  54. @property
  55. def excl_tax(self):
  56. return self.stockrecord.price_excl_tax
  57. @property
  58. def incl_tax(self):
  59. return self.stockrecord.price_incl_tax
  60. @property
  61. def tax(self):
  62. return self.stockrecord.price_tax
  63. @property
  64. def currency(self):
  65. return self.stockrecord.price_currency