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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from decimal import Decimal as D
  2. import warnings
  3. class Base(object):
  4. """
  5. Shipping method interface class
  6. This is the superclass to the classes in methods.py, and a de-facto
  7. superclass to the classes in models.py. This allows using all
  8. shipping methods interchangeably (aka polymorphism).
  9. The interface is all properties.
  10. """
  11. # CORE INTERFACE
  12. # --------------
  13. #: Used to store this method in the session. Each shipping method should
  14. # have a unique code.
  15. code = '__default__'
  16. #: The name of the shipping method, shown to the customer during checkout
  17. name = 'Default shipping'
  18. #: A more detailed description of the shipping method shown to the customer
  19. # during checkout. Can contain HTML.
  20. description = ''
  21. #: Shipping charge including taxes
  22. charge_excl_tax = D('0.00')
  23. #: Shipping charge excluding taxes
  24. charge_incl_tax = None
  25. #: Whether we now the shipping tax applicable (and hence whether
  26. # charge_incl_tax returns a value.
  27. is_tax_known = False
  28. # END OF CORE INTERFACE
  29. # ---------------------
  30. # These are not intended to be overridden and are used to track shipping
  31. # discounts.
  32. is_discounted = False
  33. discount = D('0.00')
  34. def _get_tax(self):
  35. return self.charge_incl_tax - self.charge_excl_tax
  36. def _set_tax(self, value):
  37. self.charge_incl_tax = self.charge_excl_tax + value
  38. self.is_tax_known = True
  39. tax = property(_get_tax, _set_tax)
  40. def set_basket(self, basket):
  41. self.basket = basket
  42. def basket_charge_excl_tax(self):
  43. warnings.warn((
  44. "Use the charge_excl_tax property not basket_charge_excl_tax. "
  45. "Basket.basket_charge_excl_tax will be removed "
  46. "in v0.7"),
  47. DeprecationWarning)
  48. return self.charge_excl_tax
  49. def basket_charge_incl_tax(self):
  50. warnings.warn((
  51. "Use the charge_incl_tax property not basket_charge_incl_tax. "
  52. "Basket.basket_charge_incl_tax will be removed "
  53. "in v0.7"),
  54. DeprecationWarning)
  55. return self.charge_incl_tax
  56. # For backwards compatibility, keep an alias called "ShippingMethod"
  57. ShippingMethod = Base