Backport sale-order-dates from v8

This brings in most of the changes from v8 regarding sale-order-dates.
Those changes have been incubating a very long time on our instance (since v5 days!).
As far as I know it should not break any other module.

The first 2 commits by @odony are plain backports from v8 before the module was changed to new API.
The third one is a backport from v8 too (it just landed on v8 and master).