View | Details | Raw Unified | Return to bug 27281
Collapse All | Expand All

(-)a/C4/Circulation.pm (-4 / +5 lines)
Lines 3897-3907 sub LostItem{ Link Here
3897
        MarkIssueReturned($borrowernumber,$itemnumber,undef,$patron->privacy) if $mark_returned;
3897
        MarkIssueReturned($borrowernumber,$itemnumber,undef,$patron->privacy) if $mark_returned;
3898
    }
3898
    }
3899
3899
3900
    #When item is marked lost automatically cancel its outstanding transfers and set items holdingbranch to the transfer source branch (frombranch)
3900
    # When an item is marked as lost, we should automatically cancel its outstanding transfers.
3901
    if (my ( $datesent,$frombranch,$tobranch ) = GetTransfers($itemnumber)) {
3901
    my $item = Koha::Items->find($itemnumber);
3902
        Koha::Items->find($itemnumber)->holdingbranch($frombranch)->store({ skip_record_index => $params->{skip_record_index} });
3902
    my $transfers = $item->get_transfers;
3903
    while (my $transfer = $transfers->next) {
3904
        $transfer->cancel({ reason => 'ItemLost', force => 1 });
3903
    }
3905
    }
3904
    my $transferdeleted = DeleteTransfer($itemnumber);
3905
}
3906
}
3906
3907
3907
sub GetOfflineOperations {
3908
sub GetOfflineOperations {
(-)a/Koha/Item.pm (+32 lines)
Lines 506-511 sub get_transfer { Link Here
506
    return Koha::Item::Transfer->_new_from_dbic($transfer_rs);
506
    return Koha::Item::Transfer->_new_from_dbic($transfer_rs);
507
}
507
}
508
508
509
=head3 get_transfers
510
511
  my $transfer = $item->get_transfers;
512
513
Return the list of outstanding transfers (i.e requested but not yet cancelled
514
or recieved).
515
516
Note: Transfers are retrieved in a Modified FIFO (First In First Out) order
517
whereby the most recently sent, but not received, transfer will be returned
518
first if it exists, otherwise requests are in oldest to newest request order.
519
520
This allows for transfers to queue, which is the case for stock rotation and
521
rotating collections where a manual transfer may need to take precedence but
522
we still expect the item to end up at a final location eventually.
523
524
=cut
525
526
sub get_transfers {
527
    my ($self) = @_;
528
    my $transfer_rs = $self->_result->branchtransfers->search(
529
        {
530
            datearrived   => undef,
531
            datecancelled => undef
532
        },
533
        {
534
            order_by =>
535
              [ { -desc => 'datesent' }, { -asc => 'daterequested' } ],
536
        }
537
    );
538
    return Koha::Item::Transfers->_new_from_dbic($transfer_rs);
539
}
540
509
=head3 last_returned_by
541
=head3 last_returned_by
510
542
511
Gets and sets the last borrower to return an item.
543
Gets and sets the last borrower to return an item.
(-)a/Koha/Schema/Result/Branchtransfer.pm (-3 / +4 lines)
Lines 111-117 what triggered the transfer Link Here
111
=head2 cancellation_reason
111
=head2 cancellation_reason
112
112
113
  data_type: 'enum'
113
  data_type: 'enum'
114
  extra: {list => ["Manual","StockrotationAdvance","StockrotationRepatriation","ReturnToHome","ReturnToHolding","RotatingCollection","Reserve","LostReserve","CancelReserve"]}
114
  extra: {list => ["Manual","StockrotationAdvance","StockrotationRepatriation","ReturnToHome","ReturnToHolding","RotatingCollection","Reserve","LostReserve","CancelReserve","ItemLost"]}
115
  is_nullable: 1
115
  is_nullable: 1
116
116
117
what triggered the transfer cancellation
117
what triggered the transfer cancellation
Lines 203-208 __PACKAGE__->add_columns( Link Here
203
        "Reserve",
203
        "Reserve",
204
        "LostReserve",
204
        "LostReserve",
205
        "CancelReserve",
205
        "CancelReserve",
206
        "ItemLost",
206
      ],
207
      ],
207
    },
208
    },
208
    is_nullable => 1,
209
    is_nullable => 1,
Lines 269-276 __PACKAGE__->belongs_to( Link Here
269
);
270
);
270
271
271
272
272
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-03-03 13:47:35
273
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2021-03-08 13:36:32
273
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:pL0dO9OUwImy2rv7Md3AyA
274
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:HU4Pt8CfD6lX87BjK1g3Bw
274
275
275
sub koha_object_class {
276
sub koha_object_class {
276
    'Koha::Item::Transfer';
277
    'Koha::Item::Transfer';
(-)a/installer/data/mysql/atomicupdate/bug_27281.perl (+28 lines)
Line 0 Link Here
1
$DBversion = 'XXX'; # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
4
    # Add 'LostItem' to reserves cancellation_reason enum
5
    $dbh->do(
6
        qq{
7
            ALTER TABLE
8
                `branchtransfers`
9
            MODIFY COLUMN
10
                `cancellation_reason` enum(
11
                    'Manual',
12
                    'StockrotationAdvance',
13
                    'StockrotationRepatriation',
14
                    'ReturnToHome',
15
                    'ReturnToHolding',
16
                    'RotatingCollection',
17
                    'Reserve',
18
                    'LostReserve',
19
                    'CancelReserve',
20
                    'ItemLost'
21
                )
22
            AFTER `comments`
23
          }
24
    );
25
26
    # Always end with this (adjust the bug info)
27
    NewVersion( $DBversion, 27281, "Add 'ItemLost' to cancellation_reason enum");
28
}
(-)a/installer/data/mysql/kohastructure.sql (-2 / +1 lines)
Lines 1531-1537 CREATE TABLE `branchtransfers` ( Link Here
1531
  `tobranch` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'the branch the transfer was going to',
1531
  `tobranch` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'the branch the transfer was going to',
1532
  `comments` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'any comments related to the transfer',
1532
  `comments` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'any comments related to the transfer',
1533
  `reason` enum('Manual','StockrotationAdvance','StockrotationRepatriation','ReturnToHome','ReturnToHolding','RotatingCollection','Reserve','LostReserve','CancelReserve') COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'what triggered the transfer',
1533
  `reason` enum('Manual','StockrotationAdvance','StockrotationRepatriation','ReturnToHome','ReturnToHolding','RotatingCollection','Reserve','LostReserve','CancelReserve') COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'what triggered the transfer',
1534
  `cancellation_reason` ENUM('Manual', 'StockrotationAdvance', 'StockrotationRepatriation', 'ReturnToHome', 'ReturnToHolding', 'RotatingCollection', 'Reserve', 'LostReserve', 'CancelReserve') default NULL COMMENT 'what triggered the transfer cancellation',
1534
  `cancellation_reason` ENUM('Manual', 'StockrotationAdvance', 'StockrotationRepatriation', 'ReturnToHome', 'ReturnToHolding', 'RotatingCollection', 'Reserve', 'LostReserve', 'CancelReserve', 'ItemLost') default NULL COMMENT 'what triggered the transfer cancellation',
1535
  PRIMARY KEY (`branchtransfer_id`),
1535
  PRIMARY KEY (`branchtransfer_id`),
1536
  KEY `frombranch` (`frombranch`),
1536
  KEY `frombranch` (`frombranch`),
1537
  KEY `tobranch` (`tobranch`),
1537
  KEY `tobranch` (`tobranch`),
1538
- 

Return to bug 27281