Bug 14388: Funds should be sorted by budget_code
authorJonathan Druart <jonathan.druart@koha-community.org>
Thu, 2 Jul 2015 15:42:16 +0000 (16:42 +0100)
committerLiz Rea <wizzyrea@gmail.com>
Thu, 10 Dec 2015 02:05:08 +0000 (15:05 +1300)
Before this patch, the funds were sorted by budget_id, which does not
make any sense.

This patch adds a sort by budget_code on the fund list (acqui/acqui-home.pl and
admin/aqbudgets.pl)

Test plan:
On both pages (acqui/acqui-home.pl and admin/aqbudgets.pl) confirm that
the funds are now sorted by fund code (DB column budget_code)

Signed-off-by: Nicole Engard <nengard@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit e0032c46e98b4cf31d76abb93d12041ea362d81e)
Signed-off-by: Frédéric Demians <f.demians@tamil.fr>
(cherry picked from commit 1cd654313bd539e22eacf4322fc419331ed80d44)
Signed-off-by: Liz Rea <wizzyrea@gmail.com>

C4/Budgets.pm
t/db_dependent/Budgets.t

index f2f376a..6d8bf21 100644 (file)
@@ -529,8 +529,8 @@ sub GetBudgetHierarchy {
 
     # link child to parent
     my @first_parents;
-    foreach ( sort keys %links ) {
-        my $child = $links{$_};
+    foreach my $budget ( sort { $a->{budget_code} cmp $b->{budget_code} } values %links ) {
+        my $child = $links{$budget->{budget_id}};
         if ( $child->{'budget_parent_id'} ) {
             my $parent = $links{ $child->{'budget_parent_id'} };
             if ($parent) {
index 11838c8..d74213c 100755 (executable)
@@ -1,5 +1,5 @@
 use Modern::Perl;
-use Test::More tests => 120;
+use Test::More tests => 122;
 
 BEGIN {
     use_ok('C4::Budgets')
@@ -226,22 +226,22 @@ my $budget_id2 = AddBudget(
         budget_amount    => $budget_2_total,
     }
 );
-my $budget_id11 = AddBudget(
+my $budget_id12 = AddBudget(
     {
-        budget_code      => 'budget_11',
-        budget_name      => 'budget_11',
+        budget_code      => 'budget_12',
+        budget_name      => 'budget_12',
         budget_period_id => $budget_period_id,
         budget_parent_id => $budget_id1,
-        budget_amount    => $budget_11_total,
+        budget_amount    => $budget_12_total,
     }
 );
-my $budget_id12 = AddBudget(
+my $budget_id11 = AddBudget(
     {
-        budget_code      => 'budget_12',
-        budget_name      => 'budget_12',
+        budget_code      => 'budget_11',
+        budget_name      => 'budget_11',
         budget_period_id => $budget_period_id,
         budget_parent_id => $budget_id1,
-        budget_amount    => $budget_12_total,
+        budget_amount    => $budget_11_total,
     }
 );
 my $budget_id111 = AddBudget(
@@ -425,6 +425,10 @@ $budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
 );
 
 $budget_hierarchy        = GetBudgetHierarchy($budget_period_id);
+is( $budget_hierarchy->[0]->{children}->[0]->{budget_name}, 'budget_11', 'GetBudgetHierarchy should return budgets ordered by name, first child is budget_11' );
+is( $budget_hierarchy->[0]->{children}->[1]->{budget_name}, 'budget_12', 'GetBudgetHierarchy should return budgets ordered by name, second child is budget_12' );
+
+$budget_hierarchy        = GetBudgetHierarchy($budget_period_id);
 $budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
 
 is( scalar(@$budget_hierarchy_cloned), scalar(@$budget_hierarchy),