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 {
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.
=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
"Reserve",
"LostReserve",
"CancelReserve",
+ "ItemLost",
],
},
is_nullable => 1,
);
-# 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';
--- /dev/null
+$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");
+}
`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`),