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.

basket.py 945B

12345678910111213141516171819202122232425262728293031323334
  1. from decimal import Decimal as D
  2. from oscar.test import factories
  3. from oscar.apps.partner import strategy
  4. def add_product(basket, price=None, quantity=1, product=None):
  5. """
  6. Helper to add a product to the basket.
  7. """
  8. has_strategy = False
  9. try:
  10. has_strategy = hasattr(basket, 'strategy')
  11. except RuntimeError:
  12. pass
  13. if not has_strategy:
  14. basket.strategy = strategy.Default()
  15. if price is None:
  16. price = D('1')
  17. if product and product.has_stockrecords:
  18. record = product.stockrecords.all()[0]
  19. else:
  20. record = factories.create_stockrecord(
  21. product=product, price_excl_tax=price,
  22. num_in_stock=quantity + 1)
  23. basket.add_product(record.product, quantity)
  24. def add_products(basket, args):
  25. """
  26. Helper to add a series of products to the passed basket
  27. """
  28. for price, quantity in args:
  29. add_product(basket, price, quantity)