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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import datetime
  2. from decimal import Decimal as D
  3. from django.utils.translation import ugettext_lazy as _
  4. class DefaultWrapper(object):
  5. """
  6. Default stockrecord wrapper
  7. """
  8. def is_available_to_buy(self, stockrecord):
  9. """
  10. Test whether a product is available to buy.
  11. This is used to determine whether to show the add-to-basket button.
  12. """
  13. if stockrecord.num_in_stock is None:
  14. return True
  15. return stockrecord.net_stock_level > 0
  16. def is_purchase_permitted(self, stockrecord, user=None, quantity=1):
  17. """
  18. Test whether a particular purchase is possible (is a user buying a given
  19. quantity of the product)
  20. """
  21. if not self.is_available_to_buy(stockrecord):
  22. return False, _("'%s' is not available to purchase" % stockrecord.product.title)
  23. max_qty = self.max_purchase_quantity(stockrecord, user)
  24. if max_qty is None:
  25. return True, None
  26. if max_qty < quantity:
  27. return False, _("'%s' - A maximum of %d can be bought" % (
  28. stockrecord.product.title, max_qty))
  29. return True, None
  30. def max_purchase_quantity(self, stockrecord, user=None):
  31. """
  32. Return the maximum available purchase quantity for a given user
  33. """
  34. if stockrecord.num_in_stock is None:
  35. return None
  36. return stockrecord.net_stock_level
  37. def availability_code(self, stockrecord):
  38. """
  39. Return a code for the availability of this product.
  40. This is normally used within CSS to add icons to stock messages
  41. :param oscar.apps.partner.models.StockRecord stockrecord: stockrecord instance
  42. """
  43. if stockrecord.net_stock_level > 0:
  44. return 'instock'
  45. if self.is_available_to_buy(stockrecord):
  46. return 'available'
  47. return 'outofstock'
  48. def availability(self, stockrecord):
  49. """
  50. Return an availability message for the passed stockrecord.
  51. :param oscar.apps.partner.models.StockRecord stockrecord: stockrecord instance
  52. """
  53. if stockrecord.net_stock_level > 0:
  54. return _("In stock (%d available)" % stockrecord.net_stock_level)
  55. if self.is_available_to_buy(stockrecord):
  56. return _('Available')
  57. return _("Not available")
  58. def dispatch_date(self, stockrecord):
  59. if stockrecord.net_stock_level:
  60. # Assume next day for in-stock items
  61. return datetime.date.today() + datetime.timedelta(days=1)
  62. # Assume one week for out-of-stock items
  63. return datetime.date.today() + datetime.timedelta(days=7)
  64. def lead_time(self, stockrecord):
  65. return 1
  66. def calculate_tax(self, stockrecord):
  67. return D('0.00')