View | Details | Raw Unified | Return to bug 39728
Collapse All | Expand All

(-)a/C4/Suggestions.pm (-26 lines)
Lines 27-33 BEGIN { Link Here
27
        GetSuggestion
27
        GetSuggestion
28
        ModStatus
28
        ModStatus
29
        ModSuggestion
29
        ModSuggestion
30
        GetUnprocessedSuggestions
31
        MarcRecordFromNewSuggestion
30
        MarcRecordFromNewSuggestion
32
    );
31
    );
33
}
32
}
Lines 187-217 sub DelSuggestion { Link Here
187
    }
186
    }
188
}
187
}
189
188
190
=head2 GetUnprocessedSuggestions
191
192
Missing POD for GetUnprocessedSuggestions.
193
194
=cut
195
196
sub GetUnprocessedSuggestions {
197
    my ($number_of_days_since_the_last_modification) = @_;
198
199
    $number_of_days_since_the_last_modification ||= 0;
200
201
    my $dbh = C4::Context->dbh;
202
203
    my $s = $dbh->selectall_arrayref(
204
        q|
205
        SELECT *
206
        FROM suggestions
207
        WHERE STATUS = 'ASKED'
208
            AND budgetid IS NOT NULL
209
            AND CAST(NOW() AS DATE) - INTERVAL ? DAY = CAST(suggesteddate AS DATE)
210
    |, { Slice => {} }, $number_of_days_since_the_last_modification
211
    );
212
    return $s;
213
}
214
215
=head2 MarcRecordFromNewSuggestion
189
=head2 MarcRecordFromNewSuggestion
216
190
217
    $record = MarcRecordFromNewSuggestion ( $suggestion )
191
    $record = MarcRecordFromNewSuggestion ( $suggestion )
(-)a/misc/cronjobs/notice_unprocessed_suggestions.pl (-1 / +11 lines)
Lines 37-43 unless ($confirm) { Link Here
37
for my $number_of_days (@days) {
37
for my $number_of_days (@days) {
38
    say "Searching suggestions suggested $number_of_days days ago" if $verbose;
38
    say "Searching suggestions suggested $number_of_days days ago" if $verbose;
39
39
40
    my $suggestions = C4::Suggestions::GetUnprocessedSuggestions($number_of_days);
40
    my $suggestions = Koha::Suggestions->search(
41
        {
42
            STATUS   => 'ASKED',
43
            budgetid => { '!=' => undef }
44
        }
45
    )->filter_by_last_update(
46
        {
47
            exact_days            => $number_of_days,
48
            timestamp_column_name => 'suggesteddate',
49
        }
50
    )->as_list;
41
51
42
    say "No suggestion found" if $verbose and not @$suggestions;
52
    say "No suggestion found" if $verbose and not @$suggestions;
43
53
(-)a/t/db_dependent/Suggestions.t (-63 / +2 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use DateTime::Duration;
20
use DateTime::Duration;
21
use Test::NoWarnings;
21
use Test::NoWarnings;
22
use Test::More tests => 49;
22
use Test::More tests => 48;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use t::lib::Mocks;
25
use t::lib::Mocks;
Lines 38-44 use Koha::Suggestions; Link Here
38
BEGIN {
38
BEGIN {
39
    use_ok(
39
    use_ok(
40
        'C4::Suggestions',
40
        'C4::Suggestions',
41
        qw( ModSuggestion DelSuggestion MarcRecordFromNewSuggestion GetUnprocessedSuggestions )
41
        qw( ModSuggestion DelSuggestion MarcRecordFromNewSuggestion )
42
    );
42
    );
43
}
43
}
44
44
Lines 363-428 is( Link Here
363
    "Record from suggestion author should be 'Catherine'"
363
    "Record from suggestion author should be 'Catherine'"
364
);
364
);
365
365
366
subtest 'GetUnprocessedSuggestions' => sub {
367
    plan tests => 11;
368
    $dbh->do(q|DELETE FROM suggestions|);
369
    my $my_suggestionid         = Koha::Suggestion->new($my_suggestion)->store->id;
370
    my $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
371
    is(
372
        scalar(@$unprocessed_suggestions), 0,
373
        'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund'
374
    );
375
    my $status     = ModSuggestion($mod_suggestion1);
376
    my $suggestion = Koha::Suggestions->find($my_suggestionid);
377
    is( $suggestion->budgetid, undef, 'ModSuggestion should set budgetid to NULL if not given' );
378
    ModSuggestion( { suggestionid => $my_suggestionid, budgetid => $budget_id } );
379
    $suggestion = Koha::Suggestions->find($my_suggestionid);
380
    is( $suggestion->budgetid, $budget_id, 'ModSuggestion should modify budgetid if given' );
381
382
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
383
    is(
384
        scalar(@$unprocessed_suggestions), 1,
385
        'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet'
386
    );
387
388
    warning_is { ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'REJECTED' } ) }
389
    'No suggestions REJECTED letter transported by email',
390
        'Warning raised if no REJECTED letter by email';
391
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
392
    is(
393
        scalar(@$unprocessed_suggestions), 0,
394
        'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet'
395
    );
396
397
    warning_is {
398
        ModSuggestion(
399
            {
400
                suggestionid  => $my_suggestionid, STATUS => 'ASKED',
401
                suggesteddate => dt_from_string->add_duration( DateTime::Duration->new( days => -4 ) )
402
            }
403
        );
404
    }
405
    'No suggestions ASKED letter transported by email',
406
        'Warning raised if no ASKED letter by email';
407
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
408
    is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should use 0 as default value for days' );
409
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(4);
410
    is(
411
        scalar(@$unprocessed_suggestions), 1,
412
        'GetUnprocessedSuggestions should return the suggestion suggested 4 days ago'
413
    );
414
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(3);
415
    is(
416
        scalar(@$unprocessed_suggestions), 0,
417
        'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 3 days ago'
418
    );
419
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(5);
420
    is(
421
        scalar(@$unprocessed_suggestions), 0,
422
        'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 5 days ago'
423
    );
424
};
425
426
subtest 'EmailPurchaseSuggestions' => sub {
366
subtest 'EmailPurchaseSuggestions' => sub {
427
    plan tests => 11;
367
    plan tests => 11;
428
368
429
- 

Return to bug 39728