Bugzilla – Attachment 118296 Details for
Bug 24295
C4::Circulation::GetTransfers should be removed, use Koha::Item->get_transfer instead
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27281: Update LostItem to use Koha::Item[::Transfer] methods
Bug-27281-Update-LostItem-to-use-KohaItemTransfer-.patch (text/plain), 7.15 KB, created by
Martin Renvoize (ashimema)
on 2021-03-16 11:01:17 UTC
(
hide
)
Description:
Bug 27281: Update LostItem to use Koha::Item[::Transfer] methods
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-03-16 11:01:17 UTC
Size:
7.15 KB
patch
obsolete
>From e962589719adc473066955a2aeed311f1d65b91b Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 8 Mar 2021 13:43:11 +0000 >Subject: [PATCH] Bug 27281: Update LostItem to use Koha::Item[::Transfer] > methods > >This patch updates C4::Circulation::LostItem to use the Koha::Item and >Koha::Item::Transfer methods to cancel transfers when an item is marked >as lost. > >Test plan >1/ Confirm t/db_dependant/Circulation.t passes prior to applying the >patches >2/ Apply the patch and run updatedatabase.pl >3/ Confirm that t/db_dependant/Circulation.t still passes >4/ Signoff > >https://bugs.koha-community.org/show_bug.cgi?id=24295 >--- > C4/Circulation.pm | 9 +++--- > Koha/Item.pm | 32 +++++++++++++++++++ > Koha/Schema/Result/Branchtransfer.pm | 7 ++-- > .../data/mysql/atomicupdate/bug_27281.perl | 28 ++++++++++++++++ > installer/data/mysql/kohastructure.sql | 2 +- > 5 files changed, 70 insertions(+), 8 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_27281.perl > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 03fe5c78f2..c166341597 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -3912,11 +3912,12 @@ sub LostItem{ > MarkIssueReturned($borrowernumber,$itemnumber,undef,$patron->privacy) if $mark_returned; > } > >- #When item is marked lost automatically cancel its outstanding transfers and set items holdingbranch to the transfer source branch (frombranch) >- if (my ( $datesent,$frombranch,$tobranch ) = GetTransfers($itemnumber)) { >- Koha::Items->find($itemnumber)->holdingbranch($frombranch)->store({ skip_record_index => $params->{skip_record_index} }); >+ # When an item is marked as lost, we should automatically cancel its outstanding transfers. >+ my $item = Koha::Items->find($itemnumber); >+ my $transfers = $item->get_transfers; >+ while (my $transfer = $transfers->next) { >+ $transfer->cancel({ reason => 'ItemLost', force => 1 }); > } >- my $transferdeleted = DeleteTransfer($itemnumber); > } > > sub GetOfflineOperations { >diff --git a/Koha/Item.pm b/Koha/Item.pm >index c0da07c4b9..b1e43e06f2 100644 >--- a/Koha/Item.pm >+++ b/Koha/Item.pm >@@ -506,6 +506,38 @@ sub get_transfer { > return Koha::Item::Transfer->_new_from_dbic($transfer_rs); > } > >+=head3 get_transfers >+ >+ my $transfer = $item->get_transfers; >+ >+Return the list of outstanding transfers (i.e requested but not yet cancelled >+or recieved). >+ >+Note: Transfers are retrieved in a Modified FIFO (First In First Out) order >+whereby the most recently sent, but not received, transfer will be returned >+first if it exists, otherwise requests are in oldest to newest request order. >+ >+This allows for transfers to queue, which is the case for stock rotation and >+rotating collections where a manual transfer may need to take precedence but >+we still expect the item to end up at a final location eventually. >+ >+=cut >+ >+sub get_transfers { >+ my ($self) = @_; >+ my $transfer_rs = $self->_result->branchtransfers->search( >+ { >+ datearrived => undef, >+ datecancelled => undef >+ }, >+ { >+ order_by => >+ [ { -desc => 'datesent' }, { -asc => 'daterequested' } ], >+ } >+ ); >+ return Koha::Item::Transfers->_new_from_dbic($transfer_rs); >+} >+ > =head3 last_returned_by > > Gets and sets the last borrower to return an item. >diff --git a/Koha/Schema/Result/Branchtransfer.pm b/Koha/Schema/Result/Branchtransfer.pm >index b4bf37b55c..2994efd70c 100644 >--- a/Koha/Schema/Result/Branchtransfer.pm >+++ b/Koha/Schema/Result/Branchtransfer.pm >@@ -111,7 +111,7 @@ what triggered the transfer > =head2 cancellation_reason > > data_type: 'enum' >- extra: {list => ["Manual","StockrotationAdvance","StockrotationRepatriation","ReturnToHome","ReturnToHolding","RotatingCollection","Reserve","LostReserve","CancelReserve"]} >+ extra: {list => ["Manual","StockrotationAdvance","StockrotationRepatriation","ReturnToHome","ReturnToHolding","RotatingCollection","Reserve","LostReserve","CancelReserve","ItemLost"]} > is_nullable: 1 > > what triggered the transfer cancellation >@@ -203,6 +203,7 @@ __PACKAGE__->add_columns( > "Reserve", > "LostReserve", > "CancelReserve", >+ "ItemLost", > ], > }, > is_nullable => 1, >@@ -269,8 +270,8 @@ __PACKAGE__->belongs_to( > ); > > >-# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-03-03 13:47:35 >-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:pL0dO9OUwImy2rv7Md3AyA >+# Created by DBIx::Class::Schema::Loader v0.07046 @ 2021-03-08 13:36:32 >+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:HU4Pt8CfD6lX87BjK1g3Bw > > sub koha_object_class { > 'Koha::Item::Transfer'; >diff --git a/installer/data/mysql/atomicupdate/bug_27281.perl b/installer/data/mysql/atomicupdate/bug_27281.perl >new file mode 100644 >index 0000000000..0d18397a99 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_27281.perl >@@ -0,0 +1,28 @@ >+$DBversion = 'XXX'; # will be replaced by the RM >+if( CheckVersion( $DBversion ) ) { >+ >+ # Add 'LostItem' to reserves cancellation_reason enum >+ $dbh->do( >+ qq{ >+ ALTER TABLE >+ `branchtransfers` >+ MODIFY COLUMN >+ `cancellation_reason` enum( >+ 'Manual', >+ 'StockrotationAdvance', >+ 'StockrotationRepatriation', >+ 'ReturnToHome', >+ 'ReturnToHolding', >+ 'RotatingCollection', >+ 'Reserve', >+ 'LostReserve', >+ 'CancelReserve', >+ 'ItemLost' >+ ) >+ AFTER `comments` >+ } >+ ); >+ >+ # Always end with this (adjust the bug info) >+ NewVersion( $DBversion, 27281, "Add 'ItemLost' to cancellation_reason enum"); >+} >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index ae247e67c8..9c31cb8cac 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -1531,7 +1531,7 @@ CREATE TABLE `branchtransfers` ( > `tobranch` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'the branch the transfer was going to', > `comments` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'any comments related to the transfer', > `reason` enum('Manual','StockrotationAdvance','StockrotationRepatriation','ReturnToHome','ReturnToHolding','RotatingCollection','Reserve','LostReserve','CancelReserve') COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'what triggered the transfer', >- `cancellation_reason` ENUM('Manual', 'StockrotationAdvance', 'StockrotationRepatriation', 'ReturnToHome', 'ReturnToHolding', 'RotatingCollection', 'Reserve', 'LostReserve', 'CancelReserve') default NULL COMMENT 'what triggered the transfer cancellation', >+ `cancellation_reason` ENUM('Manual', 'StockrotationAdvance', 'StockrotationRepatriation', 'ReturnToHome', 'ReturnToHolding', 'RotatingCollection', 'Reserve', 'LostReserve', 'CancelReserve', 'ItemLost') default NULL COMMENT 'what triggered the transfer cancellation', > PRIMARY KEY (`branchtransfer_id`), > KEY `frombranch` (`frombranch`), > KEY `tobranch` (`tobranch`), >-- >2.20.1
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 24295
:
118242
|
118243
|
118244
|
118245
|
118246
|
118247
|
118248
|
118249
|
118250
|
118287
|
118295
|
118296
|
118297
|
118298
|
118299
|
118300
|
118301
|
118302
|
118303
|
118304
|
118305
|
118306
|
118307
|
118308
|
118309
|
118310
|
119854
|
119855
|
119856
|
119857
|
119858
|
119859
|
119860
|
119861
|
119862
|
119863
|
119864
|
119866
|
119867
|
127465
|
127466
|
127467
|
127468
|
127469
|
127470
|
127471
|
127472
|
127473
|
127474
|
127475
|
127476
|
127477
|
130430
|
130431
|
130432
|
130433
|
130434
|
130435
|
130436
|
130437
|
130438
|
130439
|
130440
|
130441
|
130442
|
139546
|
139547
|
139548
|
139549
|
139550
|
139551
|
139552
|
139553
|
139554
|
139555
|
139556
|
139557
|
139558
|
139655
|
139656
|
139657
|
139658
|
139659
|
139660
|
139661
|
139662
|
139663
|
139664
|
139665
|
139666
|
139667