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

(-)a/C4/Suggestions.pm (-20 lines)
Lines 35-41 our @EXPORT = qw( Link Here
35
    DelSuggestion
35
    DelSuggestion
36
    ModStatus
36
    ModStatus
37
    ModSuggestion
37
    ModSuggestion
38
    GetUnprocessedSuggestions
39
    MarcRecordFromNewSuggestion
38
    MarcRecordFromNewSuggestion
40
);
39
);
41
40
Lines 173-197 sub DelSuggestion { Link Here
173
    }
172
    }
174
}
173
}
175
174
176
sub GetUnprocessedSuggestions {
177
    my ($number_of_days_since_the_last_modification) = @_;
178
179
    $number_of_days_since_the_last_modification ||= 0;
180
181
    my $dbh = C4::Context->dbh;
182
183
    my $s = $dbh->selectall_arrayref(
184
        q|
185
        SELECT *
186
        FROM suggestions
187
        WHERE STATUS = 'ASKED'
188
            AND budgetid IS NOT NULL
189
            AND CAST(NOW() AS DATE) - INTERVAL ? DAY = CAST(suggesteddate AS DATE)
190
    |, { Slice => {} }, $number_of_days_since_the_last_modification
191
    );
192
    return $s;
193
}
194
195
=head2 MarcRecordFromNewSuggestion
175
=head2 MarcRecordFromNewSuggestion
196
176
197
    $record = MarcRecordFromNewSuggestion ( $suggestion )
177
    $record = MarcRecordFromNewSuggestion ( $suggestion )
(-)a/misc/cronjobs/notice_unprocessed_suggestions.pl (-2 / +11 lines)
Lines 37-44 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
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;
42
    say "No suggestion found" if $verbose and not @$suggestions;
51
    say "No suggestion found" if $verbose and not @$suggestions;
43
52
44
    for my $suggestion (@$suggestions) {
53
    for my $suggestion (@$suggestions) {
(-)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 => 51;
22
use Test::More tests => 50;
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 369-434 is( Link Here
369
    "Record from suggestion author should be 'Catherine'"
369
    "Record from suggestion author should be 'Catherine'"
370
);
370
);
371
371
372
subtest 'GetUnprocessedSuggestions' => sub {
373
    plan tests => 11;
374
    $dbh->do(q|DELETE FROM suggestions|);
375
    my $my_suggestionid         = Koha::Suggestion->new($my_suggestion)->store->id;
376
    my $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
377
    is(
378
        scalar(@$unprocessed_suggestions), 0,
379
        'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund'
380
    );
381
    my $status     = ModSuggestion($mod_suggestion1);
382
    my $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
383
    is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' );
384
    ModSuggestion( { suggestionid => $my_suggestionid, budgetid => $budget_id } );
385
    $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
386
    is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' );
387
388
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
389
    is(
390
        scalar(@$unprocessed_suggestions), 1,
391
        'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet'
392
    );
393
394
    warning_is { ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'REJECTED' } ) }
395
    'No suggestions REJECTED letter transported by email',
396
        'Warning raised if no REJECTED letter by email';
397
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
398
    is(
399
        scalar(@$unprocessed_suggestions), 0,
400
        'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet'
401
    );
402
403
    warning_is {
404
        ModSuggestion(
405
            {
406
                suggestionid  => $my_suggestionid, STATUS => 'ASKED',
407
                suggesteddate => dt_from_string->add_duration( DateTime::Duration->new( days => -4 ) )
408
            }
409
        );
410
    }
411
    'No suggestions ASKED letter transported by email',
412
        'Warning raised if no ASKED letter by email';
413
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
414
    is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should use 0 as default value for days' );
415
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(4);
416
    is(
417
        scalar(@$unprocessed_suggestions), 1,
418
        'GetUnprocessedSuggestions should return the suggestion suggested 4 days ago'
419
    );
420
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(3);
421
    is(
422
        scalar(@$unprocessed_suggestions), 0,
423
        'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 3 days ago'
424
    );
425
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(5);
426
    is(
427
        scalar(@$unprocessed_suggestions), 0,
428
        'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 5 days ago'
429
    );
430
};
431
432
subtest 'EmailPurchaseSuggestions' => sub {
372
subtest 'EmailPurchaseSuggestions' => sub {
433
    plan tests => 11;
373
    plan tests => 11;
434
374
435
- 

Return to bug 39728