From e2d0d9427952140237bbcc31e744c329a425eb5f Mon Sep 17 00:00:00 2001 From: Baptiste Wojtkowski Date: Fri, 3 Feb 2017 15:22:36 +0000 Subject: [PATCH] Bug 15408: Remove fund's timestamp when cloning a budget To duplicate the budget, the function CloneBudgetHierarchy create a new budget from the old without the parameter timestamp, so that the database generates a new one. Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens Added unit tests to patch Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens Modified to run properly the QA tests Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens (cherry picked from commit f4615a2f817dc08e8d89c667646bff8dcc0b1c28) Signed-off-by: Martin Renvoize --- C4/Budgets.pm | 1 + t/db_dependent/Budgets.t | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/C4/Budgets.pm b/C4/Budgets.pm index 644c5e59c9..0b82055a01 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -1210,6 +1210,7 @@ sub CloneBudgetHierarchy { my $tidy_budget = { map { join( ' ', @columns ) =~ /$_/ ? ( $_ => $budget->{$_} ) : () } keys %$budget }; + delete $tidy_budget->{timestamp}; my $new_budget_id = AddBudget( { %$tidy_budget, diff --git a/t/db_dependent/Budgets.t b/t/db_dependent/Budgets.t index 21f2d59b1f..0e4d07d9cb 100755 --- a/t/db_dependent/Budgets.t +++ b/t/db_dependent/Budgets.t @@ -1,6 +1,6 @@ #!/usr/bin/perl use Modern::Perl; -use Test::More tests => 144; +use Test::More tests => 145; BEGIN { use_ok('C4::Budgets') @@ -14,6 +14,7 @@ use Koha::Acquisition::Booksellers; use Koha::Acquisition::Orders; use t::lib::TestBuilder; +use Koha::DateUtils; use YAML; @@ -488,6 +489,16 @@ my $budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod( my $budget_period_cloned = C4::Budgets::GetBudgetPeriod($budget_period_id_cloned); is($budget_period_cloned->{budget_period_description}, 'Budget Period Cloned', 'Cloned budget\'s description is updated.'); +my $budget_cloned = C4::Budgets::GetBudgets({ budget_period_id => $budget_period_id_cloned }); +my $test = $budget_cloned->[0]->{timestamp}; +my $budget_time = Koha::DateUtils::dt_from_string($test); +my $local_time = Koha::DateUtils::dt_from_string(); + + +is(DateTime::compare($budget_time, $local_time), 0, "New budget got the right timestamp"); + + + my $budget_hierarchy = GetBudgetHierarchy($budget_period_id); my $budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned); -- 2.39.5