From fdf37a263028d69092bf7633f2969a7d8b0fcf85 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Thu, 23 Apr 2026 11:20:10 +0300 Subject: [PATCH] Bug 42699: Display Koha error message when attempting to save non-unique barcode in Edit serials When you edit an already received serial from Serial collection page using Edit serials and edit items buttons, and try to save a barcode that already exists on another item, saving leads to Error 500. There is no barcode validation for editing serials, this patch adds it. To test: 1. Go to serials module. 2. Search for a serial that is not expired to edit and click on the title. 3. Go to Serial collection from the menu. 4. Use the checkboxes to mark an already received (eg. usually older, arrived, not expected) serial and click Edit serials. 5. Click on Edit item. 6. Replace the barcode with a unique barcode that is already in use and hit save. => Error 500 is raised. 7. Apply this patch and restart services. 8. Attempt to save serial with already used barcode again. => A standard Koha error message is displayed stating that barcode must be unique. Sponsored-by: Koha-Suomi Oy Signed-off-by: David Nind Signed-off-by: Paul Derscheid Signed-off-by: Pedro Amorim --- serials/serials-edit.pl | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/serials/serials-edit.pl b/serials/serials-edit.pl index f497f4157e..382b485789 100755 --- a/serials/serials-edit.pl +++ b/serials/serials-edit.pl @@ -396,10 +396,23 @@ if ( $op and $op eq 'cud-serialchangestatus' ) { else { #modify item - my ( $oldbiblionumber, $oldbibnum, $itemnumber ) = ModItemFromMarc( - $bib_record, - $itemhash{$item}->{'bibnum'}, $item - ); + my $exists; + my ( $barcodetagfield, $barcodetagsubfield ) = GetMarcFromKohaField('items.barcode'); + if ( $bib_record->subfield( $barcodetagfield, $barcodetagsubfield ) ) { + my $barcode = $bib_record->subfield( $barcodetagfield, $barcodetagsubfield ); + $exists = Koha::Items->find( { barcode => $barcode } ); + } + + # if found itemnumber is not same as modified items itemnumber assume that barcode was changed + if ( $exists && $exists->itemnumber ne $item ) { + push @errors, 'barcode_not_unique'; + push @errseq, { serialseq => $serialseqs[$index] }; + } else { + my ( $oldbiblionumber, $oldbibnum, $itemnumber ) = ModItemFromMarc( + $bib_record, + $itemhash{$item}->{'bibnum'}, $item + ); + } } } }