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 <david@davidnind.com>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Emmi Takkinen 2026-04-23 11:20:10 +03:00 committed by Pedro Amorim
parent 7355dade3b
commit fdf37a2630
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
1 changed files with 17 additions and 4 deletions

View File

@ -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
);
}
}
}
}