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.

v0.8.rst 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. =======================
  2. Oscar 0.8 release notes
  3. =======================
  4. .. warning::
  5. Since v0.8 has not been released yet, these release notes are still a work-in-progress.
  6. Welcome to Oscar 0.8!
  7. Table of contents:
  8. .. contents::
  9. :local:
  10. :depth: 1
  11. .. _overview_of_0.8:
  12. Overview
  13. --------
  14. Oscar now has a demo site customised for the US!
  15. Things that have been heavily rewritten:
  16. - Adding product to the basket
  17. Shipping functionality got a thorough re-working including a new dashboard for
  18. weight-based shipping methods.
  19. Lots of methods deprecated in the 0.6 release have now been removed.
  20. Specifically, the partner "wrapper" functionality is now gone. All price and
  21. availability logic now needs to be handled with strategies.
  22. .. _compatibility_of_0.8:
  23. Compatibility
  24. -------------
  25. Oscar 0.8 is compatible with Django 1.5-1.7.
  26. Support for Python 2.6 has been dropped; Oscar works with Python 2.7, 3.3
  27. and 3.4.
  28. .. _new_in_0.8:
  29. What's new in Oscar 0.8?
  30. ------------------------
  31. Customisation just got easier!
  32. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. * Oscar's views are now dynamically imported. This means that they can be
  34. overridden like most other classes in Oscar; overriding the related
  35. Application instance is not necessary any more.
  36. * A new management command, ``oscar_fork_app``, has been introduced to help
  37. with the all-to-common pattern of forking an Oscar app to override one of
  38. it's classes.
  39. * The documentation around :doc:`/topics/customisation` has been given an
  40. overhaul to incorporate the changes.
  41. Explicit differentiation of child, parent and stand-alone products
  42. ------------------------------------------------------------------
  43. In some edge cases, it was difficult to decide whether e.g. a product is a
  44. parent product (previously known as group product) without children or a
  45. stand-alone product (which never has children). To make that distinction
  46. easier, a ``structure`` field has been introduced on the ``AbstractProduct``
  47. class. In that process, naming for the three different product structures
  48. has been altered to be:
  49. - A stand alone product. Regular product that lives by itself.
  50. - A child product. All child products have a parent product. They're a
  51. specific version of the parent. Previously known as product variant.
  52. - A parent product. It essentially represents a set of products.
  53. Previously also known as group product.
  54. Some properties and method names have also been updated to the new naming. The
  55. old ones will throw a deprecation warning.
  56. Reworked shipping app
  57. ~~~~~~~~~~~~~~~~~~~~~
  58. Several parts of the shipping app have been altered. The most important change is a
  59. to the API of shipping methods to avoid a potential thread safety issue.
  60. Any existing Oscar sites with custom shipping methods will need to adjust them
  61. to confirm to the new API. The new API and the other changes are detailed below.
  62. See the
  63. :ref:`backwards incompatible changes <incompatible_shipping_changes_in_0.8>`
  64. for the shipping app and the
  65. :doc:`guide to configuring shipping </howto/how_to_configure_shipping>`
  66. for more information.
  67. Dashboard for weight-based shipping methods
  68. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  69. There is a new dashboard for weight-based shipping methods. It isn't enabled by
  70. default as weight-based shipping methods are enabled by default. To add it to
  71. the dashboard menu, include this snippet in your ``OSCAR_DASHBOARD_NAVIGATION``
  72. setting:
  73. .. code-block:: python
  74. OSCAR_DASHBOARD_NAVIGATION = [
  75. ...
  76. {
  77. 'label': _('Shipping charges'),
  78. 'url_name': 'dashboard:shipping-method-list',
  79. },
  80. ...
  81. ]
  82. You'll also need to modify your shipping repository class to return weight-based
  83. shipping methods too.
  84. US demo site
  85. ~~~~~~~~~~~~
  86. To help developers building sites for the US, a new example Oscar site has been
  87. included in the repo. This customises core Oscar to treat all prices as
  88. excluding tax and then calculate and apply taxes once the shipping address is
  89. known.
  90. See :ref:`us_site` for more information.
  91. Basket additions clean-up
  92. ~~~~~~~~~~~~~~~~~~~~~~~~~
  93. The forms and views around adding things to your basket has been vigorously
  94. reworked. This cleans up some very old code there and ensures variant products
  95. are handled in a consistent way.
  96. The changes do require changing the constructor signature of the
  97. ``AddToBasketForm`` - the details are documented in the
  98. :ref:`basket_app_changes`.
  99. Checkout improvements
  100. ~~~~~~~~~~~~~~~~~~~~~
  101. The checkout process now skips payment if the order total is zero (e.g. when
  102. ordering free products or using a voucher). As part of that, checkout views
  103. now evaluate *pre-conditions* (as before) and newly introduced
  104. *skip conditions*. This should make customising the checkout flow easier.
  105. Cleanup around shipping methods
  106. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  107. * The models of the shipping app now have abstract base classes, similar to
  108. the rest of Oscar.
  109. * The legacy ``ShippingMethod`` name of the interface of the shipping app has
  110. been removed. Inherit from ``shipping.base.Base`` for the class instead, and
  111. inherit from ``shipping.abstract_models.AbstractBase`` for model-based
  112. shipping methods.
  113. * ``oscar.apps.shipping.Scales`` has been renamed and moved to
  114. ``oscar.apps.shipping.scales.Scale``, and is now overridable.
  115. * ``WeightBand.upper_limit`` is now a ``DecimalField``, just like the other
  116. weight-related fields.
  117. - Stand-alone product: Products that "stand by themselves", neither have
  118. parent nor children.
  119. - Parent product: An overarching product, previously known as group product.
  120. - Child products: Products related to a common parent product
  121. .. _minor_changes_in_0.8:
  122. Minor changes
  123. ~~~~~~~~~~~~~
  124. * The ``OSCAR_CURRENCY_LOCALE`` setting has been removed. The locale is now
  125. automatically determined from the current language. This ensures prices are
  126. always shown in the correct format when switching languages.
  127. * The login and registration view now redirects staff users to the dashboard
  128. after logging in. It also employs flash messages to welcome returning and
  129. newly registered users.
  130. * The basket middleware now assigns a ``basket_hash`` attribute to the
  131. ``request`` instance. This provides a hook for basket caching.
  132. * The tracking pixel now also reports the Oscar version in use. This was
  133. forgotten when adding tracking of the Python and Django version in 0.7.
  134. Total information collected now is the versions of Django, Python and Oscar.
  135. * ``OSCAR_SLUG_FUNCTION`` now accepts both string notation and a callable.
  136. * The default templates now allow the order status to be changed on the
  137. dashboard order detail page.
  138. * The forms for the order dashboard views are now loaded dynamically so they
  139. can be overridden.
  140. * Introduced a ``OSCAR_DELETE_IMAGE_FILES`` settings which makes deleting
  141. image files and thumbnails upon deleting of a model with an ``ImageField``
  142. optional. It usually is desired behaviour, but can slow down an app when
  143. using a remote storage.
  144. .. _incompatible_changes_in_0.8:
  145. Backwards incompatible changes in 0.8
  146. -------------------------------------
  147. .. _incompatible_shipping_changes_in_0.8:
  148. Product structure
  149. ~~~~~~~~~~~~~~~~~
  150. Generally, backwards compatibility has been preserved. Two changes are
  151. unavoidable:
  152. * You now need to explicitly set product structure when creating a product;
  153. the default is a stand-alone product.
  154. * The related_name for child products was altered from ``variants`` to
  155. ``children``. A ``variants`` property has been provided (and will throw a
  156. deprecation warning), but if you used the old related name in a query lookup
  157. (e.g. ``products.filter(variants__title='foo')``, you will have to change it
  158. to ``children``.
  159. The following methods and properties have been deprecated:
  160. * ``Product.is_parent`` - Use ``is_group`` instead.
  161. * ``Product.is_variant`` - Use ``is_child`` instead.
  162. * ``Product.is_top_level`` - Test for ``is_standalone`` and/or ``is_parent`` instead.
  163. * ``Strategy.fetch_for_group`` - Use ``fetch_for_parent`` instead.
  164. * ``Strategy.select_variant_stockrecords`` - Use
  165. ``select_children_stockrecords`` instead.
  166. *
  167. Shipping
  168. ~~~~~~~~
  169. The shipping method API has been altered to avoid potential thread-safety
  170. issues. Prior to v0.8, shipping methods had a ``set_basket`` method which
  171. allowed a basket instance to be assigned. This was really a crutch to allow
  172. templates to have easy access to shipping charges (as they could be read
  173. straight off the shipping method instance). However, it was also a
  174. design problem as shipping methods could be instantiated at compile-time
  175. leading to a thread safety issue where multiple threads could assign a basket
  176. to the same shipping method instance.
  177. In Oscar 0.8, shipping methods are stateless services that have a method
  178. :func:`~oscar.apps.shipping.methods.Base.calculate` that takes a basket and
  179. returns a ``Price`` instance. New :doc:`template tags </ref/templatetags/>` are
  180. provided that allow these shipping charges to be accessed from templates.
  181. This API change does require quite a few changes as both the shipping method
  182. and shipping charge now need to be passed around separately:
  183. * Shipping methods no longer have ``charge_excl_tax``,
  184. ``charge_incl_tax`` and ``is_tax_known`` properties.
  185. * The :class:`~oscar.apps.order.utils.OrderCreator` class now requires the
  186. ``shipping_charge`` to be passed to ``place_order``.
  187. * The signature of the :class:`~oscar.apps.checkout.calculators.OrderTotalCalculator`
  188. class has changed to accept ``shipping_charge`` rather than a
  189. ``shipping_method`` instance.
  190. * The signature of the
  191. :func:`~oscar.apps.checkout.session.CheckoutSessionMixin.get_order_totals`
  192. method has changed to accept the ``shipping_charge`` rather than a
  193. ``shipping_method`` instance.
  194. Another key change is in the shipping repository object. The
  195. ``get_shipping_methods`` method has been split in two to simplify the exercise
  196. of providing new shipping methods. The best practice for Oscar 0.8 is to
  197. override the ``methods`` attribute if the same set of shipping methods is
  198. available to everyone:
  199. .. code-block:: python
  200. from oscar.apps.shipping import repository, methods
  201. class Standard(methods.FixedPrice):
  202. code = "standard"
  203. name = "Standard"
  204. charge_excl_tax = D('10.00')
  205. class Express(methods.FixedPrice):
  206. code = "express"
  207. name = "Express"
  208. charge_excl_tax = D('20.00')
  209. class Repository(repository.Repository):
  210. methods = [Standard(), Express()]
  211. or to override ``get_available_shipping_methods`` if the available shipping
  212. methods if only available conditionally:
  213. .. code-block:: python
  214. from oscar.apps.shipping import repository
  215. class Repository(repository.Repository):
  216. def get_available_shipping_methods(
  217. self, basket, shipping_addr=None, **kwargs):
  218. methods = [Standard()]
  219. if shipping_addr.country.code == 'US':
  220. # Express only available in the US
  221. methods.append(Express())
  222. return methods
  223. Note that shipping address should be passed around as instances not classes.
  224. Other potentially breaking changes related to shipping include:
  225. * Weight based shipping methods used to have an ``upper_charge`` field which was
  226. returned if no weight band matched. That doesn't work very well in practice,
  227. and has been removed. Instead, charges from bands are now added together to
  228. match the weight of the basket.
  229. * The :class:`~oscar.apps.order.utils.OrderCreator` class no longer defaults to
  230. free shipping: a shipping method and charge have to be explicitly passed in.
  231. * The ``Base`` shipping method class now lives in ``oscar.apps.shipping.methods``.
  232. * The ``find_by_code`` method of the shipping ``Repository`` class has been
  233. removed as it is no longer used.
  234. * The parameters for
  235. :func:`oscar.apps.shipping.respository.Repository.get_shipping_methods`
  236. have been re-ordered to reflect which are the most important.
  237. * The legacy ``ShippingMethod`` name of the interface of the shipping app has
  238. been removed. Inherit from ``shipping.base.Base`` for the class instead, and
  239. inherit from ``shipping.abstract_models.AbstractBase`` for model-based
  240. shipping methods.
  241. * ``oscar.apps.shipping.Scales`` has been renamed and moved to
  242. ``oscar.apps.shipping.scales.Scale``, and is now overridable.
  243. Misc
  244. ~~~~
  245. * The ``oscar_calculate_scores`` command has been `rewritten`_ to use the ORM
  246. instead of raw SQL. That exposed a bug in the previous calculations,
  247. where purchases got weighed less than any other event. When you upgrade,
  248. your total scores will be change. If you rely on the old behaviour,
  249. just extend the ``Calculator`` class and adjust the weights.
  250. * ``Order.order_number`` now has ``unique=True`` set. If order numbers are
  251. not unique in your database, you need to remedy that before migrating. By
  252. default, Oscar creates unique order numbers.
  253. * ``Product.score`` was just duplicating ``ProductRecord.score`` and has been
  254. removed. Use ``Product.stats.score`` instead.
  255. * Oscar has child products to model tightly coupled products, and
  256. ``Product.recommended_products`` to model products that are loosely related
  257. (e.g. used for upselling). ``Product.related_products`` was a
  258. third option that sat somewhere in between, and which was not well supported.
  259. We fear it adds confusion, and in the spirit of keeping Oscar core lean,
  260. has been removed. If you're using it, switch to
  261. ``Product.recommended_products`` or just add the field back to your
  262. custom Product instance and ``ProductForm`` when migrating.
  263. * The ``basket_form`` template tag code has been greatly simplified. Because of
  264. that, the syntax needed to change slightly.
  265. Before: ``{% basket_form request product as basket_form single %}``
  266. After: ``{% basket_form request product 'single' as basket_form %}``
  267. * Product attribute validation has been cleaned up. As part of that, the
  268. trivial ``ProductAttribute.get_validator`` and the unused
  269. ``ProductAttribute.is_value_valid`` methods have been removed.
  270. * It is now possible to use product attributes to add a relation to arbitrary
  271. model instances. There was some (presumably broken) support for it before,
  272. but you should now be able to use product attributes of type ``entity`` as
  273. expected. There's currently no frontend or dashboard support for it, as there
  274. is no good default behaviour.
  275. .. _rewritten: https://github.com/tangentlabs/django-oscar/commit/d8b4dbfed17be90846ea4bc47b5f7b39ad944c24
  276. Basket line stockrecords
  277. ~~~~~~~~~~~~~~~~~~~~~~~~
  278. The basket line model got a reference to the stockrecord in Oscar 0.6. The
  279. basket middleware since then updated basket lines to have stockrecords if
  280. one was missing. If any lines are still missing a stockrecord, we'd expect them
  281. to be from from submitted baskets or from old, abandoned baskets.
  282. This updating of basket lines has been removed for 0.8 as it incurs additional
  283. database queries. Oscar 0.8 now also enforces the stockrecord by making it
  284. the ``stockrecord`` field of basket ``Line`` model no longer nullable.
  285. There is a migration that makes the appropriate schema change but, before that
  286. runs, you may need to clean up your ``basket_line`` table to ensure that all
  287. existing null values are replaced or removed.
  288. Here's a simple script you could run before upgrading which should ensure there
  289. are no nulls in your ``basket_line`` table:
  290. .. code-block:: python
  291. from oscar.apps.basket import models
  292. from oscar.apps.partner.strategy import Selector
  293. strategy = Selector().strategy()
  294. lines = models.Line.objects.filter(stockrecord__isnull=True):
  295. for line in lines:
  296. info = strategy.fetch_for_product(line.product)
  297. if line.stockrecord:
  298. line.stockrecord = info.stockrecord
  299. line.save()
  300. else:
  301. line.delete()
  302. * The ``reload_page_response`` method of
  303. :class:`~oscar.apps.dashboard.orders.views.OrderDetailView`
  304. has been renamed to ``reload_page``.
  305. .. _basket_app_changes:
  306. Basket app changes
  307. ~~~~~~~~~~~~~~~~~~
  308. - The ``basket:add`` URL now required the primary key of the "base" product to
  309. be included. This allows the same form to be used for both GET and POST
  310. requests for variant products.
  311. - The ``ProductSelectionForm`` is no longer used and has been removed.
  312. - The constructor of the :class:`~oscar.apps.basket.forms.AddToBasketForm` has
  313. been adjusted to take the basket and the purchase info tuple as parameters
  314. instead of the request instance (c74f57bf_ and 8ba283e8_).
  315. .. _c74f57bf: https://github.com/tangentlabs/django-oscar/commit/c74f57bf434661877f4d2d2259e7e7eb18b34951#diff-d200ac8746274e0307f512af886e1f3eR148
  316. .. _8ba283e8: https://github.com/tangentlabs/django-oscar/commit/8ba283e8c4239e4eff95da5e8097a17ecfadf5f5
  317. Migrations
  318. ~~~~~~~~~~
  319. .. warning::
  320. The catalogue app has a data migration to determine the product structure.
  321. Please double-check it's outcome and make sure to do something similar
  322. if you have forked the catalogue app.
  323. * Address:
  324. - ``0011`` - ``AbstractAddress.search_text`` turned into a ``TextField``.
  325. * Catalogue:
  326. - ``0021`` - Add ``unique_together`` to ``ProductAttributeValue``,
  327. ``ProductRecommendation`` and ``ProductCategory``
  328. - ``0022`` - Remove ``Product.score`` field.
  329. - ``0023`` - Drop ``Product.related_products``.
  330. - ``0024`` - Change ``ProductAttributeValue.value_text`` to a ``TextField``
  331. and do entity attribute changes and model deletions.
  332. - ``0025`` & ``0026`` - Schema & data migration to determine and save Product structure.
  333. * Order:
  334. - ``0029`` - Add ``unique_together`` to ``PaymentEventQuantity`` and ``ShippingEventQuantity``
  335. - ``0030`` - Set ``unique=True`` for ``Order.order_number``
  336. - ``0031`` - ``AbstractAddress.search_text`` turned into a ``TextField``.
  337. * Partner:
  338. - ``0014`` - ``AbstractAddress.search_text`` turned into a ``TextField``.
  339. * Promotions:
  340. - ``0006`` - Add ``unique_together`` to ``OrderedProduct``
  341. * Shipping:
  342. - ``0007`` - Change ``WeightBand.upper_limit`` from ``FloatField`` to ``DecimalField``
  343. - ``0008`` - Drop ``WeightBased.upper_charge`` field.
  344. .. _deprecated_features_in_0.8:
  345. Removal of deprecated features
  346. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  347. These methods have been removed:
  348. * ``oscar.apps.catalogue.abstract_models.AbstractProduct.has_stockrecord``
  349. * ``oscar.apps.catalogue.abstract_models.AbstractProduct.stockrecord``
  350. * ``oscar.apps.catalogue.abstract_models.AbstractProduct.is_available_to_buy``
  351. * ``oscar.apps.catalogue.abstract_models.AbstractProduct.is_purchase_permitted``
  352. * ``oscar.apps.catalogue.views.get_product_base_queryset``
  353. * ``oscar.apps.partner.abstract_models.AbstractStockRecord.is_available_to_buy``
  354. * ``oscar.apps.partner.abstract_models.AbstractStockRecord.is_purchase_permitted``
  355. * ``oscar.apps.partner.abstract_models.AbstractStockRecord.availability_code``
  356. * ``oscar.apps.partner.abstract_models.AbstractStockRecord.availability``
  357. * ``oscar.apps.partner.abstract_models.AbstractStockRecord.max_purchase_quantity``
  358. * ``oscar.apps.partner.abstract_models.AbstractStockRecord.dispatch_date``
  359. * ``oscar.apps.partner.abstract_models.AbstractStockRecord.lead_time``
  360. * ``oscar.apps.partner.abstract_models.AbstractStockRecord.price_incl_tax``
  361. * ``oscar.apps.partner.abstract_models.AbstractStockRecord.price_tax``
  362. These classes have been removed
  363. * ``oscar.apps.partner.prices.DelegateToStockRecord``
  364. * ``oscar.apps.partner.availability.DelegateToStockRecord``