From f2d886c3b3513ace62f428d4e42d4d144a689172 Mon Sep 17 00:00:00 2001 From: Katrin Fischer Date: Sat, 11 May 2019 21:01:51 +0000 Subject: [PATCH] Bug 4833: (QA follow-up) Add budgetname to SearchSuggestion This patch adds the budgetname to the return of SearchSuggestion to improve performance. To test: - Same test plan as for the first patch - Verify fund names show in the table - Run t/db_dependent/Suggestions.t Signed-off-by: Nick Clemens --- C4/Suggestions.pm | 4 +++- acqui/newordersuggestion.pl | 7 ------- t/db_dependent/Suggestions.t | 10 ++++++++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm index 39faddde3f..71b9000574 100644 --- a/C4/Suggestions.pm +++ b/C4/Suggestions.pm @@ -109,7 +109,8 @@ sub SearchSuggestion { B2.branchname AS branchnamesuggestedby, U2.email AS emailmanagedby, U2.branchcode AS branchcodemanagedby, - U2.borrowernumber AS borrnummanagedby + U2.borrowernumber AS borrnummanagedby, + BU.budget_name AS budget_name FROM suggestions LEFT JOIN borrowers AS U1 ON suggestedby=U1.borrowernumber LEFT JOIN branches AS B1 ON B1.branchcode=U1.branchcode @@ -117,6 +118,7 @@ sub SearchSuggestion { LEFT JOIN borrowers AS U2 ON managedby=U2.borrowernumber LEFT JOIN branches AS B2 ON B2.branchcode=U2.branchcode LEFT JOIN categories AS C2 ON C2.categorycode=U2.categorycode + LEFT JOIN aqbudgets AS BU ON budgetid=BU.budget_id WHERE 1=1 } ); diff --git a/acqui/newordersuggestion.pl b/acqui/newordersuggestion.pl index 26065559e9..54934967ab 100755 --- a/acqui/newordersuggestion.pl +++ b/acqui/newordersuggestion.pl @@ -138,13 +138,6 @@ my $suggestions_loop = SearchSuggestion( } ); -foreach my $suggestion (@$suggestions_loop) { - if ($suggestion->{budgetid}){ - my $bud = GetBudget( $suggestion->{budgetid} ); - $suggestion->{budget_name} = $bud->{budget_name} if $bud; - } -} - my $vendor = Koha::Acquisition::Booksellers->find( $booksellerid ); $template->param( suggestions_loop => $suggestions_loop, diff --git a/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t index ab08771352..46d4582006 100644 --- a/t/db_dependent/Suggestions.t +++ b/t/db_dependent/Suggestions.t @@ -18,7 +18,7 @@ use Modern::Perl; use DateTime::Duration; -use Test::More tests => 107; +use Test::More tests => 109; use Test::Warn; use t::lib::Mocks; @@ -26,7 +26,7 @@ use t::lib::TestBuilder; use C4::Context; use C4::Letters; -use C4::Budgets qw( AddBudgetPeriod AddBudget ); +use C4::Budgets qw( AddBudgetPeriod AddBudget GetBudget ); use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Libraries; @@ -369,6 +369,12 @@ $search_suggestion = SearchSuggestion({ }); is( @$search_suggestion, 3, 'SearchSuggestion (budgetid = "__ANY__") returns the correct number of suggestions' ); +$search_suggestion = SearchSuggestion({ budgetid => $budget_id }); +is( @$search_suggestion[0]->{budget_name}, GetBudget($budget_id)->{budget_name}, 'SearchSuggestion returns the correct budget name'); +$search_suggestion = SearchSuggestion({ budgetid => "__NONE__" }); +is( @$search_suggestion[0]->{budget_name}, undef, 'SearchSuggestion returns the correct budget name'); + + my $del_suggestion = { title => 'my deleted title', STATUS => 'CHECKED', -- 2.39.5