This keeps the `OrderBalance` abstraction but removes the old code now
that the feature is enabled for all users in all instances and there are
no bugs reported. It's become dead code.
Enumerable#uniq is fine (eg calling #uniq on an Array object), but now using #uniq on an ActiveRecord::Relation is deprecated in favour of #distinct (which modifies the query itself, as opposed to iterating over the results of the query).
This class is currently used and it gets skipped when the
:customer_balance toggle is enabled, so there's no point on abstracting
the balance with `OrderBalance`. It'll never go through its
`#new_outstanding_balance` branch and it'll be removed once we active
that toggle to everyone.
This will let us branch by abstraction. All existing calls to
`#outstanding_balance` will go through `OrderBalance` hence, will
check the feature toggle.
Note that by default, `OrderBalance` will end up calling
`#old_outstanding_balance`. As the name states, that's exactly what
`#outstanding_balance` was so far. This means no consumers will see any
change in behavior. We just added on item in the call stack (sort of).
This almost removes the responsibility of fetching orders from this
class, that has too many. Ideally, I'd go on and leave this up to the
caller of this class making `Reports::LineItems` rely completely on the
passed in `orders_relation`. Not today.
I saw the row were returned not respecting any ordering when refreshing
the page locally. It made it hard to debug whether or not the customer
balance was right.
It's less than ideal to use `allow_any_instance_of` but with this legacy
and very coupled code, it's the best we can do.
This enables toggling features as best fits us in each case. With this
new approach we can then toggle :customer_balance to an entire instance,
which is what we want in France.
This makes it possible to deploy it without releasing it to users since
the toggle is not enabled for anyone.
It aims to make the balance calculation consistent across pages.
This enables showing features to individual users only, which enables us
to deploy features that are not yet released to gather feedback from
product and testing, while no users have access to it.