From f834f3e748f97c6223f7201166830df0d2685f6d Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 14 Jul 2020 13:59:06 +0100 Subject: [PATCH] Bug 23091: Make relations more explicit This patch simply makes the queries built for the ->debits and ->credits relations in Koha::Account::Line more explicit. Test plan 1/ Ensure tests continue to pass 2/ Run tests with DBIC_TRACE=1 DBIC_TRACE_PROFILE=console and note that the related queries not include 'credit.' and 'debit.' as appropriate. Signed-off-by: Andrew Fuerste-Henry --- Koha/Account/Line.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm index 98d7ef3c15..a9aae85cb0 100644 --- a/Koha/Account/Line.pm +++ b/Koha/Account/Line.pm @@ -167,14 +167,15 @@ sub credits { my ( $self, $cond, $attr ) = @_; unless ( $self->is_debit ) { - Koha::Exceptions::Account::IsNotCredit->throw( + Koha::Exceptions::Account::IsNotDebit->throw( error => 'Account line ' . $self->id . ' is not a debit' ); } + my $cond_m = { map { "credit.".$_ => $cond->{$_} } keys %{$cond}}; my $rs = $self->_result->search_related('account_offsets_debits') - ->search_related( 'credit', $cond, $attr ); + ->search_related( 'credit', $cond_m, $attr ); return unless $rs; return Koha::Account::Lines->_new_from_dbic($rs); } @@ -199,9 +200,10 @@ sub debits { ); } + my $cond_m = { map { "debit.".$_ => $cond->{$_} } keys %{$cond}}; my $rs = $self->_result->search_related('account_offsets_credits') - ->search_related( 'debit', $cond, $attr ); + ->search_related( 'debit', $cond_m, $attr ); return unless $rs; return Koha::Account::Lines->_new_from_dbic($rs); } -- 2.20.1