Bug 31051: (QA follow-up) Use a single query and avoid duplicated sums
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 9 Feb 2023 14:26:56 +0000 (11:26 -0300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Wed, 22 Feb 2023 13:03:36 +0000 (10:03 -0300)
commit39a2763109ba2604b9fa738f302b3666760265c0
tree70791ab88a222f9cf3fc62eef6fd15000ddf42fe
parentf177d30ab43c64e9f0f5c06cf041fcfb37e53797
Bug 31051: (QA follow-up) Use a single query and avoid duplicated sums

This patch makes the `get_savings` method use a single query to
calculate the sum of the replacement prices. This way we save one query
per item and just rely on the DB features.

It has a side effect: we are not summing items twice.

Added tests for the 'itenumber is null' pathological but common use
case (specially in old_issues), as mentioned by Lucas. Handling for this
is added (grep filtering out undefined ones) and also in the return, for
the empty case, with // 0.

To test:
1. Apply this patch
2. Run:
   qa -c 6 --run-tests
=> SUCCESS: All good
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/Patron.pm
t/db_dependent/Koha/Patron.t