From 46a13422264bf35560d032550c05574879d927fc Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 27 Aug 2021 14:34:00 +0200 Subject: [PATCH] Bug 22690: Remove uneeded return and add no_triggers * C4/Items.pm - Koha::Biblios not used * Koha/Item.pm - Koha::Item->orders must return an empty set if no order attached - no_triggers should be passed to other update calls * Item.t - No need to build a fund - Add new test to test Koha::Item->orders when no order attached Signed-off-by: Jonathan Druart --- C4/Items.pm | 1 - Koha/Item.pm | 11 +++-------- t/db_dependent/Koha/Item.t | 15 +++++---------- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index cc9ec54b79..7f83736ace 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -64,7 +64,6 @@ use Koha::AuthorisedValues; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Database; -use Koha::Biblios; use Koha::Biblioitems; use Koha::Items; use Koha::ItemTypes; diff --git a/Koha/Item.pm b/Koha/Item.pm index 3419305019..60d80a5c3e 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -1185,7 +1185,6 @@ sub orders { my ( $self ) = @_; my $orders = $self->_result->item_orders; - return unless $orders; return Koha::Acquisition::Orders->_new_from_dbic($orders); } @@ -1245,13 +1244,10 @@ sub move_to_biblio { } # Acquisition orders - my $orders = $self->orders; - if ($orders) { - $orders->update({ biblionumber => $to_biblionumber }, { no_triggers => 1 }); - } + $self->orders->update({ biblionumber => $to_biblionumber }, { no_triggers => 1 }); # Holds - $self->holds->update({ biblionumber => $to_biblionumber }); + $self->holds->update({ biblionumber => $to_biblionumber }, { no_triggers => 1 }); # hold_fill_target (there's no Koha object available yet) my $hold_fill_target = $self->_result->hold_fill_target; @@ -1271,8 +1267,7 @@ sub move_to_biblio { ); # tracked_links - my $tracked_links = $self->tracked_links; - $tracked_links->update({ biblionumber => $to_biblionumber }); + $self->tracked_links->update({ biblionumber => $to_biblionumber }, { no_triggers => 1 }); return $to_biblionumber; } diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index 9260ca5282..e9cc993cd7 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -834,18 +834,15 @@ subtest 'get_transfers' => sub { }; subtest 'Tests for relationship between item and item_orders via aqorders_item' => sub { - plan tests => 2; + plan tests => 3; $schema->storage->txn_begin; my $biblio = $builder->build_sample_biblio(); my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); - my $aq_budget = $builder->build({ - source => 'Aqbudget', - value => { - budget_notes => 'test', - }, - }); + + my $orders = $item->orders; + is ($orders->count, 0, 'No order on this item yet'); my $order_note = 'Order for ' . $item->itemnumber; @@ -853,7 +850,6 @@ subtest 'Tests for relationship between item and item_orders via aqorders_item' class => 'Koha::Acquisition::Orders', value => { biblionumber => $biblio->biblionumber, - budget_id => $aq_budget->{budget_id}, order_internalnote => $order_note, }, }); @@ -861,7 +857,6 @@ subtest 'Tests for relationship between item and item_orders via aqorders_item' class => 'Koha::Acquisition::Orders', value => { biblionumber => $biblio->biblionumber, - budget_id => $aq_budget->{budget_id}, }, }); my $aq_order_item1 = $builder->build({ @@ -872,7 +867,7 @@ subtest 'Tests for relationship between item and item_orders via aqorders_item' }, }); - my $orders = $item->orders; + $orders = $item->orders; is ($orders->count, 1, 'One order found by item with the relationship'); is ($orders->next->order_internalnote, $order_note, 'Correct order found by item with the relationship'); }; -- 2.39.5