@@ -, +, @@ suggestion -> A new purchase suggestion has been submitted duplicate ISBN, and Submit --- C4/Suggestions.pm | 28 +++++++++++++++++++--------- suggestion/suggestion.pl | 1 + t/db_dependent/Suggestions.t | 22 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 9 deletions(-) --- a/C4/Suggestions.pm +++ a/C4/Suggestions.pm @@ -615,19 +615,29 @@ sub MarcRecordFromNewSuggestion { my ($suggestion) = @_; my $record = MARC::Record->new(); - my ($title_tag, $title_subfield) = GetMarcFromKohaField('biblio.title', ''); - $record->append_fields( - MARC::Field->new($title_tag, ' ', ' ', $title_subfield => $suggestion->{title}) - ); - - my ($author_tag, $author_subfield) = GetMarcFromKohaField('biblio.author', ''); - if ($record->field( $author_tag )) { - $record->field( $author_tag )->add_subfields( $author_subfield => $suggestion->{author} ); + if (my $isbn = $suggestion->{isbn}) { + for my $field (qw(biblioitems.isbn biblioitems.issn)) { + my ($tag, $subfield) = GetMarcFromKohaField($field, ''); + $record->append_fields( + MARC::Field->new($tag, ' ', ' ', $subfield => $isbn) + ); + } } else { + my ($title_tag, $title_subfield) = GetMarcFromKohaField('biblio.title', ''); $record->append_fields( - MARC::Field->new($author_tag, ' ', ' ', $author_subfield => $suggestion->{author}) + MARC::Field->new($title_tag, ' ', ' ', $title_subfield => $suggestion->{title}) ); + + my ($author_tag, $author_subfield) = GetMarcFromKohaField('biblio.author', ''); + if ($record->field( $author_tag )) { + $record->field( $author_tag )->add_subfields( $author_subfield => $suggestion->{author} ); + } + else { + $record->append_fields( + MARC::Field->new($author_tag, ' ', ' ', $author_subfield => $suggestion->{author}) + ); + } } my ($it_tag, $it_subfield) = GetMarcFromKohaField('biblioitems.itemtype', ''); --- a/suggestion/suggestion.pl +++ a/suggestion/suggestion.pl @@ -132,6 +132,7 @@ if ( $op =~ /save/i ) { title => $suggestion_only->{title}, author => $suggestion_only->{author}, itemtype => $suggestion_only->{itemtype}, + isbn => $suggestion_only->{isbn}, }); my $manager = Koha::Patrons->find( $suggestion_only->{managedby} ); --- a/t/db_dependent/Suggestions.t +++ a/t/db_dependent/Suggestions.t @@ -648,4 +648,26 @@ subtest 'ModSuggestion should work on suggestions without a suggester' => sub { is( $suggestion->{note}, "Test note", "ModSuggestion works on suggestions without a suggester" ); }; +subtest 'Suggestion with ISBN' => sub { + my $suggestion_with_isbn = { + isbn => '1940997232', + title => "The Clouds", + author => "Aristophanes", + }; + my $record = MarcRecordFromNewSuggestion( $suggestion_with_isbn ); + is("MARC::Record", ref($record), "MarcRecordFromNewSuggestion should return a MARC::Record object"); + + my ($isbn_tag, $isbn_subfield) = C4::Biblio::GetMarcFromKohaField('biblioitems.isbn', ''); + is($record->field( $isbn_tag )->subfield( $isbn_subfield ), "1940997232", "ISBN Record from suggestion ISBN should be '1940997232'"); + + my ($issn_tag, $issn_subfield) = C4::Biblio::GetMarcFromKohaField('biblioitems.issn', ''); + is($record->field( $issn_tag )->subfield( $issn_subfield ), "1940997232", "ISSN Record from suggestion ISBN should also be '1940997232'"); + + my ($title_tag, $title_subfield) = C4::Biblio::GetMarcFromKohaField('biblio.title', ''); + is($record->field( $title_tag), undef, "Record from suggestion title should be empty"); + + my ($author_tag, $author_subfield) = C4::Biblio::GetMarcFromKohaField('biblio.author', ''); + is($record->field( $author_tag), undef, "Record from suggestion author should be emtpy"); +} + $schema->storage->txn_rollback; --