Lines 1-5
Link Here
|
1 |
use Modern::Perl; |
1 |
use Modern::Perl; |
2 |
use Test::More tests => 39; |
2 |
use Test::More tests => 69; |
3 |
|
3 |
|
4 |
BEGIN {use_ok('C4::Budgets') } |
4 |
BEGIN {use_ok('C4::Budgets') } |
5 |
use C4::Context; |
5 |
use C4::Context; |
Lines 435-448
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
Link Here
|
435 |
budget_period_id => $budget_period_id, |
435 |
budget_period_id => $budget_period_id, |
436 |
budget_period_startdate => '2014-01-01', |
436 |
budget_period_startdate => '2014-01-01', |
437 |
budget_period_enddate => '2014-12-31', |
437 |
budget_period_enddate => '2014-12-31', |
438 |
reset_all_funds => 1, |
|
|
439 |
} |
438 |
} |
440 |
); |
439 |
); |
441 |
|
440 |
|
442 |
my $report = C4::Budgets::MoveOrders( |
441 |
my $report = C4::Budgets::MoveOrders( |
443 |
{ |
442 |
{ |
444 |
from_budget_period_id => $budget_period_id, |
443 |
from_budget_period_id => $budget_period_id, |
445 |
to_budget_period_id => $budget_period_id_cloned, |
444 |
to_budget_period_id => $budget_period_id_cloned, |
|
|
445 |
move_remaining_unspent => 1, |
446 |
} |
446 |
} |
447 |
); |
447 |
); |
448 |
is( scalar( @$report ), 6 , "MoveOrders has processed 6 funds" ); |
448 |
is( scalar( @$report ), 6 , "MoveOrders has processed 6 funds" ); |
Lines 451-456
my $number_of_orders_moved = 0;
Link Here
|
451 |
$number_of_orders_moved += scalar( @{ $_->{orders_moved} } ) for @$report; |
451 |
$number_of_orders_moved += scalar( @{ $_->{orders_moved} } ) for @$report; |
452 |
is( $number_of_orders_moved, $number_of_orders_to_move, "MoveOrders has moved $number_of_orders_to_move orders" ); |
452 |
is( $number_of_orders_moved, $number_of_orders_to_move, "MoveOrders has moved $number_of_orders_to_move orders" ); |
453 |
|
453 |
|
|
|
454 |
my @new_budget_ids = map { $_->{budget_id} } |
455 |
@{ C4::Budgets::GetBudgetHierarchy($budget_period_id_cloned) }; |
456 |
my @old_budget_ids = map { $_->{budget_id} } |
457 |
@{ C4::Budgets::GetBudgetHierarchy($budget_period_id) }; |
458 |
for my $budget_id ( keys %budgets ) { |
459 |
for my $ordernumber ( @{ $budgets{$budget_id} } ) { |
460 |
my $budget = GetBudgetByOrderNumber($ordernumber); |
461 |
my $is_in_new_budgets = grep /^$budget->{budget_id}$/, @new_budget_ids; |
462 |
my $is_in_old_budgets = grep /^$budget->{budget_id}$/, @old_budget_ids; |
463 |
is( $is_in_new_budgets, 1, "MoveOrders changed the budget_id for order $ordernumber" ); |
464 |
is( $is_in_old_budgets, 0, "MoveOrders changed the budget_id for order $ordernumber" ); |
465 |
} |
466 |
} |
467 |
|
468 |
|
469 |
# MoveOrders with param move_remaining_unspent |
470 |
my @new_budgets = @{ C4::Budgets::GetBudgetHierarchy($budget_period_id_cloned) }; |
471 |
my @old_budgets = @{ C4::Budgets::GetBudgetHierarchy($budget_period_id) }; |
472 |
|
473 |
for my $new_budget ( @new_budgets ) { |
474 |
my ( $old_budget ) = map { $_->{budget_code} eq $new_budget->{budget_code} ? $_ : () } @old_budgets; |
475 |
my $new_budget_amount_should_be = $old_budget->{budget_amount} * 2 - $old_budget->{total_spent}; |
476 |
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})" ); |
477 |
} |
478 |
|
454 |
sub _get_dependencies { |
479 |
sub _get_dependencies { |
455 |
my ($budget_hierarchy) = @_; |
480 |
my ($budget_hierarchy) = @_; |
456 |
my $graph; |
481 |
my $graph; |
457 |
- |
|
|