Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

v0.8.rst 20KB

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