Bugzilla – Attachment 33265 Details for
Bug 13014
Sent an email to the fund owner when a suggestion can be treated
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13014: Notify budget owner on new suggestion - UT
Bug-13014-Notify-budget-owner-on-new-suggestion---.patch (text/plain), 6.38 KB, created by
Frédéric Demians
on 2014-11-05 16:58:01 UTC
(
hide
)
Description:
Bug 13014: Notify budget owner on new suggestion - UT
Filename:
MIME Type:
Creator:
Frédéric Demians
Created:
2014-11-05 16:58:01 UTC
Size:
6.38 KB
patch
obsolete
>From 80ee6545f58bff44aa65c7f6ec813f005fcc6d84 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Tue, 30 Sep 2014 16:56:46 +0200 >Subject: [PATCH] Bug 13014: Notify budget owner on new suggestion - UT > >When a suggestion is created and linked to a fund, a mail will be >generated, using a cronjob, to notify the budget owner. > >A suggestion is considered as "can be treated" if its status is "ASKED". > >Signed-off-by: Frederic Demians <f.demians@tamil.fr> >--- > C4/Suggestions.pm | 18 ++++++++++++++++ > t/db_dependent/Suggestions.t | 49 ++++++++++++++++++++++++++++++++++++++++++-- > 2 files changed, 65 insertions(+), 2 deletions(-) > >diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm >index b543293..4188941 100644 >--- a/C4/Suggestions.pm >+++ b/C4/Suggestions.pm >@@ -48,6 +48,7 @@ our @EXPORT = qw( > NewSuggestion > SearchSuggestion > DelSuggestionsOlderThan >+ GetUnprocessedSuggestions > ); > > =head1 NAME >@@ -552,6 +553,23 @@ sub DelSuggestionsOlderThan { > $sth->execute("-$days"); > } > >+sub GetUnprocessedSuggestions { >+ my ( $number_of_days_since_the_last_modification ) = @_; >+ >+ $number_of_days_since_the_last_modification ||= 0; >+ >+ my $dbh = C4::Context->dbh; >+ >+ my $s = $dbh->selectall_arrayref(q| >+ SELECT * >+ FROM suggestions >+ WHERE STATUS = 'ASKED' >+ AND budgetid IS NOT NULL >+ AND CAST(NOW() AS DATE) - CAST(suggesteddate AS DATE) = ? >+ |, { Slice => {} }, $number_of_days_since_the_last_modification ); >+ return $s; >+} >+ > 1; > __END__ > >diff --git a/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t >index 299bdf6..7ba7a45 100644 >--- a/t/db_dependent/Suggestions.t >+++ b/t/db_dependent/Suggestions.t >@@ -18,10 +18,14 @@ > use Modern::Perl; > > use C4::Context; >+use C4::Budgets qw( AddBudgetPeriod AddBudget ); > use C4::Members; > use C4::Letters; > >-use Test::More tests => 91; >+use Koha::DateUtils qw( dt_from_string ); >+ >+use DateTime::Duration; >+use Test::More tests => 101; > use Test::Warn; > > BEGIN { >@@ -59,6 +63,20 @@ my $my_suggestion = { > biblionumber => $biblionumber1, > }; > >+# Create a fund for the budgetid value >+my $bpid = C4::Budgets::AddBudgetPeriod({ >+ budget_period_startdate => '2008-01-01', >+}); >+my $my_budget = { >+ budget_code => 'ABCD', >+ budget_amount => '123.132000', >+ budget_name => 'Periodiques', >+ budget_notes => 'This is a note', >+ budget_period_id => $bpid, >+}; >+my $budget_id = C4::Budgets::AddBudget($my_budget); >+ >+my $unprocessed_suggestions; > > is( CountSuggestion(), 0, 'CountSuggestion without the status returns 0' ); > is( CountSuggestion('ASKED'), 0, 'CountSuggestion returns the correct number of suggestions' ); >@@ -81,8 +99,12 @@ is( $suggestion->{STATUS}, 'ASKED', 'NewSuggestion stores a suggestion with the > > is( CountSuggestion('ASKED'), 1, 'CountSuggestion returns the correct number of suggestions' ); > >+$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; >+is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund' ); >+ > > is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' ); >+ > my $mod_suggestion1 = { > title => 'my modified title', > author => 'my modified author', >@@ -98,6 +120,29 @@ $suggestion = GetSuggestion($my_suggestionid); > is( $suggestion->{title}, $mod_suggestion1->{title}, 'ModSuggestion modifies the title correctly' ); > is( $suggestion->{author}, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' ); > is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'ModSuggestion modifies the publishercode correctly' ); >+is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' ); >+ >+ModSuggestion({ suggestionid => $my_suggestionid, budgetid => $budget_id }); >+$suggestion = GetSuggestion($my_suggestionid); >+is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' ); >+ >+$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; >+is( scalar( @$unprocessed_suggestions ), 1, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' ); >+ >+ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'REJECTED' } ); >+$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; >+is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' ); >+ >+ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'ASKED', suggesteddate => dt_from_string->add_duration(DateTime::Duration->new(days => -4) ) } ); >+$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions; >+is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should use 0 as default value for days' ); >+$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(4); >+is( scalar( @$unprocessed_suggestions ), 1, 'GetUnprocessedSuggestions should return the suggestion suggested 4 days ago' ); >+$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(3); >+is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 3 days ago' ); >+$unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(5); >+is( scalar( @$unprocessed_suggestions ), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 5 days ago' ); >+ > my $messages = C4::Letters::GetQueuedMessages({ > borrowernumber => $borrowernumber, > }); >@@ -106,6 +151,7 @@ is( @$messages, 0, 'ModSuggestions does not send an email if the status is not u > my $mod_suggestion2 = { > STATUS => 'STALLED', > suggestionid => $my_suggestionid, >+ > }; > warning_is { $status = ModSuggestion($mod_suggestion2) } > "No suggestions STALLED letter transported by email", >@@ -128,7 +174,6 @@ is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' ); > > is( CountSuggestion('CHECKED'), 1, 'CountSuggestion returns the correct number of suggestions' ); > >- > is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' ); > $suggestion = GetSuggestionInfo($my_suggestionid); > is( $suggestion->{suggestionid}, $my_suggestionid, 'GetSuggestionInfo returns the suggestion id correctly' ); >-- >2.1.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 13014
:
31950
|
31951
|
31952
|
33247
|
33265
|
33266
|
33267
|
33293
|
33294
|
34792
|
34793
|
34794
|
34795
|
34796
|
35603
|
35604
|
35605
|
35606
|
35607
|
36272
|
36273
|
36275
|
36276
|
36277
|
38006
|
38007
|
38009
|
38012
|
38013
|
38014
|
38015
|
38016
|
38017
|
40597