Bug 12164: On cloning budget period, mark original budget as inactive

This patch adds a checkbox "mark original budget as inactive" (budget
period).
If it is checked, the original budget will be marked as inactive.

Signed-off-by: Paola Rossi <paola.rossi@cineca.it>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
Jonathan Druart 2014-06-02 10:14:52 +02:00 committed by Tomas Cohen Arazi
parent a12e96e938
commit cd191642cd
4 changed files with 60 additions and 4 deletions

View file

@ -1014,10 +1014,13 @@ sub ConvertCurrency {
my $new_budget_period_id = CloneBudgetPeriod({
budget_period_id => $budget_period_id,
budget_period_startdate => $budget_period_startdate;
$budget_period_enddate => $budget_period_enddate;
budget_period_enddate => $budget_period_enddate;
mark_original_budget_as_inactive => 1
});
Clone a budget period with all budgets.
If the mark_origin_budget_as_inactive is set (0 by default),
the original budget will be marked as inactive.
=cut
@ -1026,6 +1029,8 @@ sub CloneBudgetPeriod {
my $budget_period_id = $params->{budget_period_id};
my $budget_period_startdate = $params->{budget_period_startdate};
my $budget_period_enddate = $params->{budget_period_enddate};
my $mark_original_budget_as_inactive =
$params->{mark_original_budget_as_inactive} || 0;
my $budget_period = GetBudgetPeriod($budget_period_id);
@ -1037,8 +1042,21 @@ sub CloneBudgetPeriod {
my $budgets = GetBudgetHierarchy($budget_period_id);
CloneBudgetHierarchy(
{ budgets => $budgets, new_budget_period_id => $new_budget_period_id }
{
budgets => $budgets,
new_budget_period_id => $new_budget_period_id
}
);
if ($mark_original_budget_as_inactive) {
ModBudgetPeriod(
{
budget_period_id => $budget_period_id,
budget_period_active => 0,
}
);
}
return $new_budget_period_id;
}

View file

@ -189,12 +189,14 @@ elsif ( $op eq 'duplicate_budget' ){
my $budget_period_startdate = dt_from_string $input->param('budget_period_startdate');
my $budget_period_enddate = dt_from_string $input->param('budget_period_enddate');
my $mark_original_budget_as_inactive = $input->param('mark_original_budget_as_inactive');
my $new_budget_period_id = C4::Budgets::CloneBudgetPeriod(
{
budget_period_id => $budget_period_id,
budget_period_startdate => $budget_period_startdate,
budget_period_enddate => $budget_period_enddate,
mark_original_budget_as_inactive => $mark_original_budget_as_inactive,
}
);

View file

@ -185,6 +185,11 @@
<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
</li>
<li>
<label for="mark_as_inactive">Mark the original budget as inactive</label>
<input type="checkbox" id="mark_as_inactive" name="mark_original_budget_as_inactive" />
</li>
</ol>
</fieldset>

View file

@ -1,5 +1,5 @@
use Modern::Perl;
use Test::More tests => 65;
use Test::More tests => 69;
BEGIN {
use_ok('C4::Budgets')
@ -373,7 +373,38 @@ is(
is_deeply(
_get_dependencies($budget_hierarchy),
_get_dependencies($budget_hierarchy_cloned),
'CloneBudgetPeriod keep the same dependencies order'
'CloneBudgetPeriod keeps the same dependencies order'
);
# CloneBudgetPeriod with param mark_original_budget_as_inactive
my $budget_period = C4::Budgets::GetBudgetPeriod($budget_period_id);
is( $budget_period->{budget_period_active}, 1,
'CloneBudgetPeriod does not mark as inactive the budgetperiod if not needed'
);
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
{
budget_period_id => $budget_period_id,
budget_period_startdate => '2014-01-01',
budget_period_enddate => '2014-12-31',
mark_original_budget_as_inactive => 1,
}
);
$budget_hierarchy = GetBudgetHierarchy($budget_period_id);
$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
is( scalar(@$budget_hierarchy_cloned), scalar(@$budget_hierarchy),
'CloneBudgetPeriod (with inactive param) clones the same number of budgets (funds)'
);
is_deeply(
_get_dependencies($budget_hierarchy),
_get_dependencies($budget_hierarchy_cloned),
'CloneBudgetPeriod (with inactive param) keeps the same dependencies order'
);
$budget_period = C4::Budgets::GetBudgetPeriod($budget_period_id);
is( $budget_period->{budget_period_active}, 0,
'CloneBudgetPeriod (with inactive param) marks as inactive the budgetperiod'
);
sub _get_dependencies {