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

methods.py 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. from decimal import Decimal as D
  2. from django.utils.translation import ugettext_lazy as _
  3. from oscar.apps.shipping.base import Base
  4. class Free(Base):
  5. code = 'free-shipping'
  6. name = _('Free shipping')
  7. is_tax_known = True
  8. charge_incl_tax = charge_excl_tax = D('0.00')
  9. class NoShippingRequired(Free):
  10. """
  11. This is a special shipping method that indicates that no shipping is
  12. actually required (eg for digital goods).
  13. """
  14. code = 'no-shipping-required'
  15. name = _('No shipping required')
  16. class FixedPrice(Base):
  17. code = 'fixed-price-shipping'
  18. name = _('Fixed price shipping')
  19. def __init__(self, charge_excl_tax, charge_incl_tax=None):
  20. self.charge_excl_tax = charge_excl_tax
  21. if charge_incl_tax is not None:
  22. self.charge_incl_tax = charge_incl_tax
  23. self.is_tax_known = True
  24. class OfferDiscount(Base):
  25. """
  26. Wrapper class that applies a discount to an existing shipping method's
  27. charges
  28. """
  29. def __init__(self, method, offer):
  30. self.method = method
  31. self.offer = offer
  32. @property
  33. def is_discounted(self):
  34. # We check to see if the discount is non-zero. It is possible to have
  35. # zero shipping already in which case this the offer does not lead to
  36. # any further discount.
  37. return self.get_discount()['discount'] > 0
  38. @property
  39. def discount(self):
  40. return self.get_discount()['discount']
  41. @property
  42. def code(self):
  43. return self.method.code
  44. @property
  45. def name(self):
  46. return self.method.name
  47. @property
  48. def description(self):
  49. return self.method.description
  50. def get_discount(self):
  51. # Return a 'discount' dictionary in the same form as that used by the
  52. # OfferApplications class
  53. parent_charge = self.method.charge_incl_tax
  54. return {
  55. 'offer': self.offer,
  56. 'result': None,
  57. 'name': self.offer.name,
  58. 'description': '',
  59. 'voucher': self.offer.get_voucher(),
  60. 'freq': 1,
  61. 'discount': self.offer.shipping_discount(parent_charge)}
  62. @property
  63. def charge_incl_tax_before_discount(self):
  64. return self.method.charge_incl_tax
  65. @property
  66. def charge_excl_tax_before_discount(self):
  67. return self.method.charge_excl_tax
  68. @property
  69. def is_tax_known(self):
  70. return self.method.is_tax_known
  71. @property
  72. def charge_incl_tax(self):
  73. parent_charge = self.method.charge_incl_tax
  74. discount = self.offer.shipping_discount(parent_charge)
  75. return parent_charge - discount
  76. @property
  77. def charge_excl_tax(self):
  78. # Adjust tax exclusive rate using the ratio of the two tax inclusive
  79. # charges.
  80. parent_charge_excl_tax = self.method.charge_excl_tax
  81. parent_charge_incl_tax = self.method.charge_incl_tax
  82. charge_incl_tax = self.charge_incl_tax
  83. if parent_charge_incl_tax == 0:
  84. return D('0.00')
  85. return parent_charge_excl_tax * (charge_incl_tax /
  86. parent_charge_incl_tax)