Bug 32471

Summary: MARC imports can fail on replacing items when an itemnumber exists in the incoming file, but not in Koha
Product: Koha Reporter: Nick Clemens (kidclamp) <nick>
Component: ToolsAssignee: Bugs List <koha-bugs>
Status: NEW --- QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low    
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:

Description Nick Clemens (kidclamp) 2022-12-14 21:08:39 UTC
The 'replace' option for items checks whether the item can be found for barcodes - it does not do so for itemnumbers:

sub _batchCommitItems {
...
        my $duplicate_barcode = exists( $item->{'barcode'} ) && Koha::Items->find({ barcode => $item->{'barcode'} });
        my $duplicate_itemnumber = exists( $item->{'itemnumber'} );
...
        if ( $action eq "replace" && $duplicate_itemnumber ) {
            # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying
            ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber}, { skip_record_index => 1 } );

The call to ModItemFromMarc fails when the item isn't there - this can happen for orders when importing final records form the vendor, but a cop has been removed etc.

To recreate:
1 - Export a record containing items as MARCXML
2 - Edit an item record and add/update the 952$9 to a number not in the db 1234567890
2 - Stage the record for import, matching on kohabiblio and replacing items
3 - Import the batch
4 - It fails