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 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #: Retail price
  17. retail = None
  18. #: Price currency (3 char code)
  19. currency = None
  20. class Unavailable(Base):
  21. """
  22. This should be used as a pricing policy when a product is unavailable and
  23. no prices are known.
  24. """
  25. class FixedPrice(Base):
  26. """
  27. This should be used for when the price of a product is known in advance.
  28. It can work for when tax isn't known (like in the US).
  29. """
  30. exists = True
  31. def __init__(self, currency, excl_tax, tax=None):
  32. self.currency = currency
  33. self.excl_tax = excl_tax
  34. self.tax = tax
  35. @property
  36. def incl_tax(self):
  37. if self.is_tax_known:
  38. return self.excl_tax + self.tax
  39. raise prices.TaxNotKnown(
  40. "Can't calculate price.incl_tax as tax isn't known")
  41. @property
  42. def is_tax_known(self):
  43. return self.tax is not None
  44. class DelegateToStockRecord(Base):
  45. """
  46. Pricing policy which wraps around an existing stockrecord.
  47. This is backwards compatible with Oscar<0.6 where taxes were calculated by
  48. "partner wrappers" which wrapped around stockrecords.
  49. """
  50. is_tax_known = True
  51. def __init__(self, stockrecord):
  52. self.stockrecord = stockrecord
  53. @property
  54. def exists(self):
  55. return self.stockrecord is not None
  56. @property
  57. def excl_tax(self):
  58. return self.stockrecord.price_excl_tax
  59. @property
  60. def incl_tax(self):
  61. return self.stockrecord.price_incl_tax
  62. @property
  63. def tax(self):
  64. return self.stockrecord.price_tax
  65. @property
  66. def retail(self):
  67. return self.stockrecord.price_retail
  68. @property
  69. def currency(self):
  70. return self.stockrecord.price_currency