Bug 13098: Sum at DBMS level

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2018-10-25 16:13:27 -03:00 committed by Nick Clemens
parent 3db4926db3
commit 5c90aae36a

View file

@ -18,7 +18,6 @@ package Koha::Account::Offsets;
use Modern::Perl;
use Carp;
use List::Util qw(sum0);
use Koha::Database;
@ -41,11 +40,19 @@ Account offsets track the changes made to the balance of account lines
=cut
sub total {
my ( $self ) = @_;
my ($self) = @_;
my $total = sum0( $self->get_column('amount') );
my $offsets = $self->search(
{},
{
select => [ { sum => 'amount' } ],
as => ['total_amount'],
}
);
return $total;
return $offsets->count
? $offsets->next->get_column('total_amount') + 0
: 0;
}
=head2 Internal methods