Lines 1-5
Link Here
|
1 |
use Modern::Perl; |
1 |
use Modern::Perl; |
2 |
use Test::More tests => 77; |
2 |
use Test::More tests => 107; |
3 |
|
3 |
|
4 |
BEGIN { |
4 |
BEGIN { |
5 |
use_ok('C4::Budgets') |
5 |
use_ok('C4::Budgets') |
Lines 467-480
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
Link Here
|
467 |
budget_period_id => $budget_period_id, |
467 |
budget_period_id => $budget_period_id, |
468 |
budget_period_startdate => '2014-01-01', |
468 |
budget_period_startdate => '2014-01-01', |
469 |
budget_period_enddate => '2014-12-31', |
469 |
budget_period_enddate => '2014-12-31', |
470 |
reset_all_funds => 1, |
|
|
471 |
} |
470 |
} |
472 |
); |
471 |
); |
473 |
|
472 |
|
474 |
my $report = C4::Budgets::MoveOrders( |
473 |
my $report = C4::Budgets::MoveOrders( |
475 |
{ |
474 |
{ |
476 |
from_budget_period_id => $budget_period_id, |
475 |
from_budget_period_id => $budget_period_id, |
477 |
to_budget_period_id => $budget_period_id_cloned, |
476 |
to_budget_period_id => $budget_period_id_cloned, |
|
|
477 |
move_remaining_unspent => 1, |
478 |
} |
478 |
} |
479 |
); |
479 |
); |
480 |
is( scalar( @$report ), 6 , "MoveOrders has processed 6 funds" ); |
480 |
is( scalar( @$report ), 6 , "MoveOrders has processed 6 funds" ); |
Lines 483-488
my $number_of_orders_moved = 0;
Link Here
|
483 |
$number_of_orders_moved += scalar( @{ $_->{orders_moved} } ) for @$report; |
483 |
$number_of_orders_moved += scalar( @{ $_->{orders_moved} } ) for @$report; |
484 |
is( $number_of_orders_moved, $number_of_orders_to_move, "MoveOrders has moved $number_of_orders_to_move orders" ); |
484 |
is( $number_of_orders_moved, $number_of_orders_to_move, "MoveOrders has moved $number_of_orders_to_move orders" ); |
485 |
|
485 |
|
|
|
486 |
my @new_budget_ids = map { $_->{budget_id} } |
487 |
@{ C4::Budgets::GetBudgetHierarchy($budget_period_id_cloned) }; |
488 |
my @old_budget_ids = map { $_->{budget_id} } |
489 |
@{ C4::Budgets::GetBudgetHierarchy($budget_period_id) }; |
490 |
for my $budget_id ( keys %budgets ) { |
491 |
for my $ordernumber ( @{ $budgets{$budget_id} } ) { |
492 |
my $budget = GetBudgetByOrderNumber($ordernumber); |
493 |
my $is_in_new_budgets = grep /^$budget->{budget_id}$/, @new_budget_ids; |
494 |
my $is_in_old_budgets = grep /^$budget->{budget_id}$/, @old_budget_ids; |
495 |
is( $is_in_new_budgets, 1, "MoveOrders changed the budget_id for order $ordernumber" ); |
496 |
is( $is_in_old_budgets, 0, "MoveOrders changed the budget_id for order $ordernumber" ); |
497 |
} |
498 |
} |
499 |
|
500 |
|
501 |
# MoveOrders with param move_remaining_unspent |
502 |
my @new_budgets = @{ C4::Budgets::GetBudgetHierarchy($budget_period_id_cloned) }; |
503 |
my @old_budgets = @{ C4::Budgets::GetBudgetHierarchy($budget_period_id) }; |
504 |
|
505 |
for my $new_budget ( @new_budgets ) { |
506 |
my ( $old_budget ) = map { $_->{budget_code} eq $new_budget->{budget_code} ? $_ : () } @old_budgets; |
507 |
my $new_budget_amount_should_be = $old_budget->{budget_amount} * 2 - $old_budget->{total_spent}; |
508 |
is( $new_budget->{budget_amount} + 0, $new_budget_amount_should_be, "MoveOrders updated the budget amount with the previous unspent budget (for budget $new_budget->{budget_code})" ); |
509 |
} |
510 |
|
486 |
sub _get_dependencies { |
511 |
sub _get_dependencies { |
487 |
my ($budget_hierarchy) = @_; |
512 |
my ($budget_hierarchy) = @_; |
488 |
my $graph; |
513 |
my $graph; |
489 |
- |
|
|