From b59799f298aab7b04547bcd7c29a2777e015a106 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 Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- 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 8772942f82..63d94a05d7 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.39.5