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 Signed-off-by: Petro Vashchuk <stalkernoid@gmail.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
bb3c38f4c4
commit
115ed5eb5b
|
|
@ -3897,11 +3897,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 {
|
||||
|
|
|
|||
32
Koha/Item.pm
32
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.
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
|
@ -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`),
|
||||
|
|
|
|||
Loading…
Reference in New Issue