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

(-)a/C4/Suggestions.pm (+33 lines)
Lines 28-33 use C4::Output; Link Here
28
use C4::Dates qw(format_date format_date_in_iso);
28
use C4::Dates qw(format_date format_date_in_iso);
29
use C4::Debug;
29
use C4::Debug;
30
use C4::Letters;
30
use C4::Letters;
31
use Koha::DateUtils qw( dt_from_string );
32
31
use List::MoreUtils qw(any);
33
use List::MoreUtils qw(any);
32
use C4::Dates qw(format_date_in_iso);
34
use C4::Dates qw(format_date_in_iso);
33
use base qw(Exporter);
35
use base qw(Exporter);
Lines 426-433 Insert a new suggestion on database with value given on input arg. Link Here
426
sub NewSuggestion {
428
sub NewSuggestion {
427
    my ($suggestion) = @_;
429
    my ($suggestion) = @_;
428
430
431
    for my $field ( qw(
432
        suggestedby
433
        managedby
434
        manageddate
435
        acceptedby
436
        accepteddate
437
        rejectedby
438
        rejecteddate
439
    ) ) {
440
        # Set the fields to NULL if not given.
441
        $suggestion->{$field} ||= undef;
442
    }
443
429
    $suggestion->{STATUS} = "ASKED" unless $suggestion->{STATUS};
444
    $suggestion->{STATUS} = "ASKED" unless $suggestion->{STATUS};
430
445
446
    $suggestion->{suggesteddate} = dt_from_string unless $suggestion->{suggesteddate};
447
431
    my $rs = Koha::Database->new->schema->resultset('Suggestion');
448
    my $rs = Koha::Database->new->schema->resultset('Suggestion');
432
    return $rs->create($suggestion)->id;
449
    return $rs->create($suggestion)->id;
433
}
450
}
Lines 449-454 sub ModSuggestion { Link Here
449
    my ($suggestion) = @_;
466
    my ($suggestion) = @_;
450
    return unless( $suggestion and defined($suggestion->{suggestionid}) );
467
    return unless( $suggestion and defined($suggestion->{suggestionid}) );
451
468
469
    for my $field ( qw(
470
        suggestedby
471
        managedby
472
        manageddate
473
        acceptedby
474
        accepteddate
475
        rejectedby
476
        rejecteddate
477
    ) ) {
478
        # Set the fields to NULL if not given.
479
        $suggestion->{$field} = undef
480
          if exists $suggestion->{$field}
481
          and ($suggestion->{$field} eq '0'
482
            or $suggestion->{$field} eq '' );
483
    }
484
452
    my $rs = Koha::Database->new->schema->resultset('Suggestion')->find($suggestion->{suggestionid});
485
    my $rs = Koha::Database->new->schema->resultset('Suggestion')->find($suggestion->{suggestionid});
453
    my $status_update_table = 1;
486
    my $status_update_table = 1;
454
    eval {
487
    eval {
(-)a/suggestion/suggestion.pl (-1 / +4 lines)
Lines 115-121 $template->param('borrowernumber' => $borrowernumber); Link Here
115
##  Operations
115
##  Operations
116
##
116
##
117
if ( $op =~ /save/i ) {
117
if ( $op =~ /save/i ) {
118
        if ( $suggestion_only->{"STATUS"} ) {
118
    $suggestion_only->{suggesteddate} = dt_from_string( $suggestion_only->{suggesteddate} )
119
        if $suggestion_only->{suggesteddate};
120
121
    if ( $suggestion_only->{"STATUS"} ) {
119
        if ( my $tmpstatus = lc( $suggestion_only->{"STATUS"} ) =~ /ACCEPTED|REJECTED/i ) {
122
        if ( my $tmpstatus = lc( $suggestion_only->{"STATUS"} ) =~ /ACCEPTED|REJECTED/i ) {
120
            $suggestion_only->{ lc( $suggestion_only->{"STATUS"}) . "date" } = dt_from_string;
123
            $suggestion_only->{ lc( $suggestion_only->{"STATUS"}) . "date" } = dt_from_string;
121
            $suggestion_only->{ lc( $suggestion_only->{"STATUS"}) . "by" }   = C4::Context->userenv->{number};
124
            $suggestion_only->{ lc( $suggestion_only->{"STATUS"}) . "by" }   = C4::Context->userenv->{number};
(-)a/t/db_dependent/Suggestions.t (-4 / +16 lines)
Lines 21-27 use C4::Context; Link Here
21
use C4::Members;
21
use C4::Members;
22
use C4::Letters;
22
use C4::Letters;
23
23
24
use Test::More tests => 91;
24
use Koha::DateUtils qw( dt_from_string );
25
26
use Test::More tests => 97;
25
use Test::Warn;
27
use Test::Warn;
26
28
27
BEGIN {
29
BEGIN {
Lines 57-62 my $my_suggestion = { Link Here
57
    publishercode => 'my publishercode',
59
    publishercode => 'my publishercode',
58
    suggestedby   => $borrowernumber,
60
    suggestedby   => $borrowernumber,
59
    biblionumber  => $biblionumber1,
61
    biblionumber  => $biblionumber1,
62
    managedby     => '',
63
    manageddate   => '',
64
    accepteddate  => dt_from_string,
65
    note          => 'my note',
60
};
66
};
61
67
62
68
Lines 66-72 is( CountSuggestion('CHECKED'), 0, 'CountSuggestion returns the correct number o Link Here
66
is( CountSuggestion('ACCEPTED'), 0, 'CountSuggestion returns the correct number of suggestions' );
72
is( CountSuggestion('ACCEPTED'), 0, 'CountSuggestion returns the correct number of suggestions' );
67
is( CountSuggestion('REJECTED'), 0, 'CountSuggestion returns the correct number of suggestions' );
73
is( CountSuggestion('REJECTED'), 0, 'CountSuggestion returns the correct number of suggestions' );
68
74
69
70
my $my_suggestionid = NewSuggestion($my_suggestion);
75
my $my_suggestionid = NewSuggestion($my_suggestion);
71
isnt( $my_suggestionid, 0, 'NewSuggestion returns an not null id' );
76
isnt( $my_suggestionid, 0, 'NewSuggestion returns an not null id' );
72
77
Lines 78-84 is( $suggestion->{publishercode}, $my_suggestion->{publishercode}, 'NewSuggestio Link Here
78
is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'NewSuggestion stores the borrower number correctly' );
83
is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'NewSuggestion stores the borrower number correctly' );
79
is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'NewSuggestion stores the biblio number correctly' );
84
is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'NewSuggestion stores the biblio number correctly' );
80
is( $suggestion->{STATUS}, 'ASKED', 'NewSuggestion stores a suggestion with the status ASKED by default' );
85
is( $suggestion->{STATUS}, 'ASKED', 'NewSuggestion stores a suggestion with the status ASKED by default' );
81
86
is( $suggestion->{managedby}, undef, 'NewSuggestion stores empty string as undef for non existent foreign key (integer)' );
87
is( $suggestion->{manageddate}, undef, 'NewSuggestion stores empty string as undef for date' );
82
is( CountSuggestion('ASKED'), 1, 'CountSuggestion returns the correct number of suggestions' );
88
is( CountSuggestion('ASKED'), 1, 'CountSuggestion returns the correct number of suggestions' );
83
89
84
90
Lines 87-92 my $mod_suggestion1 = { Link Here
87
    title         => 'my modified title',
93
    title         => 'my modified title',
88
    author        => 'my modified author',
94
    author        => 'my modified author',
89
    publishercode => 'my modified publishercode',
95
    publishercode => 'my modified publishercode',
96
    managedby     => '',
97
    manageddate   => '',
90
};
98
};
91
my $status = ModSuggestion($mod_suggestion1);
99
my $status = ModSuggestion($mod_suggestion1);
92
is( $status, undef, 'ModSuggestion without the suggestion id returns undef' );
100
is( $status, undef, 'ModSuggestion without the suggestion id returns undef' );
Lines 98-103 $suggestion = GetSuggestion($my_suggestionid); Link Here
98
is( $suggestion->{title}, $mod_suggestion1->{title}, 'ModSuggestion modifies the title  correctly' );
106
is( $suggestion->{title}, $mod_suggestion1->{title}, 'ModSuggestion modifies the title  correctly' );
99
is( $suggestion->{author}, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' );
107
is( $suggestion->{author}, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' );
100
is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'ModSuggestion modifies the publishercode correctly' );
108
is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'ModSuggestion modifies the publishercode correctly' );
109
is( $suggestion->{managedby}, undef, 'ModSuggestion stores empty string as undef for non existent foreign key (integer)' );
110
is( $suggestion->{manageddate}, undef, 'ModSuggestion stores empty string as undef for date' );
111
isnt( $suggestion->{accepteddate}, undef, 'ModSuggestion does not update a non given date value' );
112
is( $suggestion->{note}, 'my note', 'ModSuggestion should not erase data if not given' );
113
101
my $messages = C4::Letters::GetQueuedMessages({
114
my $messages = C4::Letters::GetQueuedMessages({
102
    borrowernumber => $borrowernumber,
115
    borrowernumber => $borrowernumber,
103
});
116
});
104
- 

Return to bug 12627