Bugzilla – Attachment 156650 Details for
Bug 30708
Creation of a new 'Preservation' module
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30708: Do not allow copy item to a train if the item already exists in a non-received train
Bug-30708-Do-not-allow-copy-item-to-a-train-if-the.patch (text/plain), 6.80 KB, created by
Marcel de Rooy
on 2023-10-07 06:40:41 UTC
(
hide
)
Description:
Bug 30708: Do not allow copy item to a train if the item already exists in a non-received train
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2023-10-07 06:40:41 UTC
Size:
6.80 KB
patch
obsolete
>From 9a8a4389cf8d1431911ba999b974ea0292f20fc0 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 7 Apr 2023 12:07:29 +0200 >Subject: [PATCH] Bug 30708: Do not allow copy item to a train if the item > already exists in a non-received train >Content-Type: text/plain; charset=utf-8 > >Sponsored-by: BULAC - http://www.bulac.fr/ >Signed-off-by: BULAC - http://www.bulac.fr/ >Signed-off-by: Heather Hernandez <heather_hernandez@nps.gov> >Signed-off-by: Laurence Rault <laurence.rault@biblibre.com> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/Exceptions/Preservation.pm | 5 +++++ > Koha/Preservation/Train.pm | 11 ++++++++++ > Koha/REST/V1/Preservation/Trains.pm | 11 ++++++++++ > .../components/Preservation/TrainsShow.vue | 12 +++++++++-- > t/db_dependent/Koha/Preservation/Trains.t | 21 ++++++++++++++++++- > 5 files changed, 57 insertions(+), 3 deletions(-) > >diff --git a/Koha/Exceptions/Preservation.pm b/Koha/Exceptions/Preservation.pm >index 332a76536a..2224a9a233 100644 >--- a/Koha/Exceptions/Preservation.pm >+++ b/Koha/Exceptions/Preservation.pm >@@ -33,6 +33,11 @@ use Exception::Class ( > isa => 'Koha::Exceptions::Preservation', > description => "Cannot add item to waiting list, it is already in a non-received train", > }, >+ 'Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain' => { >+ isa => 'Koha::Exceptions::Preservation', >+ description => "Cannot add item to this train, it is already in an other non-received train", >+ fields => ['train_id'], >+ }, > 'Koha::Exceptions::Preservation::ItemNotInWaitingList' => { > isa => 'Koha::Exceptions::Preservation', > description => "Cannot add item to train, it is not in the waiting list", >diff --git a/Koha/Preservation/Train.pm b/Koha/Preservation/Train.pm >index b87f0eb878..3622cb4461 100644 >--- a/Koha/Preservation/Train.pm >+++ b/Koha/Preservation/Train.pm >@@ -77,6 +77,17 @@ sub add_item { > Koha::Exceptions::Preservation::ItemNotInWaitingList->throw > if !$skip_waiting_list_check && $item->notforloan != $not_for_loan; > >+ my $already_in_train = Koha::Preservation::Train::Items->search( >+ { item_id => $train_item->{item_id}, 'train.received_on' => undef }, >+ { >+ join => 'train' >+ } >+ ); >+ if ( $already_in_train->count ) { >+ my $train_id = $already_in_train->next->train_id; >+ Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain->throw( train_id => $train_id ); >+ } >+ > # FIXME We need a LOCK here > # Not important for now as we have add_items > # Note that there are several other places in Koha with this max+1 problem >diff --git a/Koha/REST/V1/Preservation/Trains.pm b/Koha/REST/V1/Preservation/Trains.pm >index cb70d2f74b..44075a1d7b 100644 >--- a/Koha/REST/V1/Preservation/Trains.pm >+++ b/Koha/REST/V1/Preservation/Trains.pm >@@ -382,7 +382,13 @@ sub add_item { > status => 400, > openapi => { error => 'Item not in waiting list' } > ); >+ } elsif ( $_->isa('Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain') ) { >+ return $c->render( >+ status => 409, >+ openapi => { error => 'Item already in a non-received train', train_id => $_->train_id } >+ ); > } >+ > } > > $c->unhandled_exception($_); >@@ -474,6 +480,11 @@ sub copy_item { > status => 400, > openapi => { error => 'Item not in waiting list' } > ); >+ } elsif ( $_->isa('Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain') ) { >+ return $c->render( >+ status => 409, >+ openapi => { error => 'Item already in a non-received train', train_id => $_->train_id } >+ ); > } > } > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue >index 6d522f88da..db8096ff28 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue >@@ -197,7 +197,8 @@ export default { > const AVStore = inject("AVStore") > const { get_lib_from_av } = AVStore > >- const { setConfirmationDialog, setMessage } = inject("mainStore") >+ const { setConfirmationDialog, setMessage, setWarning } = >+ inject("mainStore") > > const table_id = "item_list" > useDataTable(table_id) >@@ -208,6 +209,7 @@ export default { > table_id, > setConfirmationDialog, > setMessage, >+ setWarning, > } > }, > data() { >@@ -421,7 +423,13 @@ export default { > this.setMessage(this.$__("Item copied successfully.")) > this.show_modal = false > }, >- error => {} >+ error => { >+ this.setWarning( >+ this.$__( >+ "Item cannot be copied to a train, it is already in a non-received train." >+ ) >+ ) >+ } > ) > }, > build_datatable: function () { >diff --git a/t/db_dependent/Koha/Preservation/Trains.t b/t/db_dependent/Koha/Preservation/Trains.t >index 7bf7398ae4..cd41e49d90 100755 >--- a/t/db_dependent/Koha/Preservation/Trains.t >+++ b/t/db_dependent/Koha/Preservation/Trains.t >@@ -23,6 +23,7 @@ use Test::Warn; > > use Koha::Preservation::Trains; > use Koha::Database; >+use Koha::DateUtils qw( dt_from_string ); > > use t::lib::TestBuilder; > use t::lib::Mocks; >@@ -52,7 +53,7 @@ subtest 'default_processing' => sub { > }; > > subtest 'add_items & items' => sub { >- plan tests => 12; >+ plan tests => 13; > > $schema->storage->txn_begin; > >@@ -104,5 +105,23 @@ subtest 'add_items & items' => sub { > is( $train->items->count, 3, 'the item has been added to the train' ); > is( $item_2->get_from_storage->notforloan, $not_for_loan_train_in ); > >+ my $another_train = $builder->build_object( >+ { >+ class => 'Koha::Preservation::Trains', >+ value => { >+ not_for_loan => $not_for_loan_train_in, >+ closed_on => undef, >+ sent_on => undef, >+ received_on => undef >+ } >+ } >+ ); >+ >+ $train->closed_on(dt_from_string)->store; >+ >+ throws_ok { >+ $another_train->add_item( { item_id => $item_1->itemnumber }, { skip_waiting_list_check => 1 }); >+ } 'Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain'; >+ > $schema->storage->txn_rollback; > }; >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30708
:
134715
|
134716
|
134732
|
134733
|
134734
|
134736
|
134737
|
134738
|
134782
|
134783
|
134784
|
134785
|
152939
|
152940
|
152941
|
152942
|
152943
|
152944
|
152945
|
152946
|
152947
|
152948
|
152949
|
152950
|
152951
|
152952
|
152953
|
152954
|
152955
|
152956
|
152957
|
152958
|
152959
|
152960
|
152961
|
152962
|
152963
|
152964
|
152965
|
152966
|
152967
|
152968
|
152969
|
152970
|
153102
|
153576
|
154167
|
154168
|
154169
|
154170
|
154171
|
154172
|
154173
|
154174
|
154175
|
154176
|
154177
|
154178
|
154179
|
154180
|
154181
|
154182
|
154183
|
154184
|
154185
|
154186
|
154187
|
154188
|
154189
|
154190
|
154191
|
154192
|
154193
|
154194
|
154195
|
154196
|
154197
|
154198
|
154199
|
154200
|
154201
|
154202
|
154203
|
156592
|
156596
|
156597
|
156636
|
156637
|
156638
|
156639
|
156640
|
156641
|
156642
|
156643
|
156644
|
156645
|
156646
|
156647
|
156648
|
156649
| 156650 |
156651
|
156652
|
156653
|
156654
|
156655
|
156656
|
156657
|
156658
|
156659
|
156660
|
156661
|
156662
|
156663
|
156664
|
156665
|
156666
|
156667
|
156668
|
156669
|
156670
|
156671
|
156672
|
156673
|
156674
|
156675
|
157502
|
157503
|
157506
|
157508
|
157512
|
157514
|
157557