use C4::Dates qw(format_date format_date_in_iso);
use C4::Debug;
use C4::Letters;
+use Koha::DateUtils qw( dt_from_string );
+
use List::MoreUtils qw(any);
use C4::Dates qw(format_date_in_iso);
use base qw(Exporter);
sub NewSuggestion {
my ($suggestion) = @_;
+ for my $field ( qw(
+ suggestedby
+ managedby
+ manageddate
+ acceptedby
+ accepteddate
+ rejectedby
+ rejecteddate
+ ) ) {
+ # Set the fields to NULL if not given.
+ $suggestion->{$field} ||= undef;
+ }
+
$suggestion->{STATUS} = "ASKED" unless $suggestion->{STATUS};
+ $suggestion->{suggesteddate} = dt_from_string unless $suggestion->{suggesteddate};
+
my $rs = Koha::Database->new->schema->resultset('Suggestion');
return $rs->create($suggestion)->id;
}
my ($suggestion) = @_;
return unless( $suggestion and defined($suggestion->{suggestionid}) );
+ for my $field ( qw(
+ suggestedby
+ managedby
+ manageddate
+ acceptedby
+ accepteddate
+ rejectedby
+ rejecteddate
+ ) ) {
+ # Set the fields to NULL if not given.
+ $suggestion->{$field} = undef
+ if exists $suggestion->{$field}
+ and ($suggestion->{$field} eq '0'
+ or $suggestion->{$field} eq '' );
+ }
+
my $rs = Koha::Database->new->schema->resultset('Suggestion')->find($suggestion->{suggestionid});
my $status_update_table = 1;
eval {
use C4::Members;
use C4::Letters;
-use Test::More tests => 91;
+use Koha::DateUtils qw( dt_from_string );
+
+use Test::More tests => 97;
use Test::Warn;
BEGIN {
publishercode => 'my publishercode',
suggestedby => $borrowernumber,
biblionumber => $biblionumber1,
+ managedby => '',
+ manageddate => '',
+ accepteddate => dt_from_string,
+ note => 'my note',
};
is( CountSuggestion('ACCEPTED'), 0, 'CountSuggestion returns the correct number of suggestions' );
is( CountSuggestion('REJECTED'), 0, 'CountSuggestion returns the correct number of suggestions' );
-
my $my_suggestionid = NewSuggestion($my_suggestion);
isnt( $my_suggestionid, 0, 'NewSuggestion returns an not null id' );
is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'NewSuggestion stores the borrower number correctly' );
is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'NewSuggestion stores the biblio number correctly' );
is( $suggestion->{STATUS}, 'ASKED', 'NewSuggestion stores a suggestion with the status ASKED by default' );
-
+is( $suggestion->{managedby}, undef, 'NewSuggestion stores empty string as undef for non existent foreign key (integer)' );
+is( $suggestion->{manageddate}, undef, 'NewSuggestion stores empty string as undef for date' );
is( CountSuggestion('ASKED'), 1, 'CountSuggestion returns the correct number of suggestions' );
title => 'my modified title',
author => 'my modified author',
publishercode => 'my modified publishercode',
+ managedby => '',
+ manageddate => '',
};
my $status = ModSuggestion($mod_suggestion1);
is( $status, undef, 'ModSuggestion without the suggestion id returns undef' );
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->{managedby}, undef, 'ModSuggestion stores empty string as undef for non existent foreign key (integer)' );
+is( $suggestion->{manageddate}, undef, 'ModSuggestion stores empty string as undef for date' );
+isnt( $suggestion->{accepteddate}, undef, 'ModSuggestion does not update a non given date value' );
+is( $suggestion->{note}, 'my note', 'ModSuggestion should not erase data if not given' );
+
my $messages = C4::Letters::GetQueuedMessages({
borrowernumber => $borrowernumber,
});