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 <andrew@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Martin Renvoize 2020-07-14 13:59:06 +01:00 committed by Jonathan Druart
parent e7d4bacfc6
commit b59799f298

View file

@ -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);
}