Bug 26082: Call store on new items to update itemnumber
authorColin Campbell <colin.campbell@ptfs-europe.com>
Wed, 29 Jul 2020 12:23:14 +0000 (13:23 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 20 Aug 2020 08:23:59 +0000 (10:23 +0200)
Need to add call to store to Koha::Item->new so that itemnumber
is returned - otherwise is not defined and causes an error
Bug is a side-effect of Bug 23463 as this was implicitly
done in AddItem

Also set biblioitemnumber explicitly for item adds this also
used to be done explicitly but can now cause an FK error

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Koha/EDI.pm

index a692da1..3b89d4e 100644 (file)
@@ -719,7 +719,8 @@ sub quote_item {
             my $created = 0;
             while ( $created < $order_quantity ) {
                 $item_hash->{biblionumber} = $bib->{biblionumber};
-                my $item = Koha::Item->new( $item_hash );
+                $item_hash->{biblioitemnumber} = $bib->{biblioitemnumber};
+                my $item = Koha::Item->new( $item_hash )->store;
                 my $itemnumber = $item->itemnumber;
                 $logger->trace("Added item:$itemnumber");
                 $schema->resultset('AqordersItem')->create(
@@ -810,7 +811,8 @@ sub quote_item {
                     }
 
                     $item_hash->{biblionumber} = $bib->{biblionumber};
-                    my $item = Koha::Item->new( $item_hash );
+                    $item_hash->{biblioitemnumber} = $bib->{biblioitemnumber};
+                    my $item = Koha::Item->new( $item_hash )->store;
                     my $itemnumber = $item->itemnumber;
                     $logger->trace("New item $itemnumber added");
                     $schema->resultset('AqordersItem')->create(
@@ -879,7 +881,8 @@ sub quote_item {
                         homebranch => $item->girfield( 'branch', $occurrence ),
                     };
                     $new_item->{biblionumber} = $bib->{biblionumber};
-                    my $item = Koha::Item->new( $new_item );
+                    $new_item->{biblioitemnumber} = $bib->{biblioitemnumber};
+                    my $item = Koha::Item->new( $new_item )->store;
                     my $itemnumber = $item->itemnumber;
                     $logger->trace("New item $itemnumber added");
                     $schema->resultset('AqordersItem')->create(