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

(-)a/Koha/Hold.pm (-10 / +6 lines)
Lines 187-194 $hold->move_hold_item(); Link Here
187
sub move_hold_item {
187
sub move_hold_item {
188
    my ( $self, $args ) = @_;
188
    my ( $self, $args ) = @_;
189
189
190
    my $new_itemnumber        = $args->{new_itemnumber};
190
    my $new_itemnumber   = $args->{new_itemnumber};
191
    my $new_biblionumber      = $args->{new_biblionumber};
191
    my $new_biblionumber = $args->{new_biblionumber};
192
    my $priority         = $args->{priority};
193
192
    my $original              = $self;
194
    my $original              = $self;
193
    my $original_biblionumber = $self->biblionumber;
195
    my $original_biblionumber = $self->biblionumber;
194
196
Lines 203-221 sub move_hold_item { Link Here
203
205
204
        if ( $canReserve->{status} eq 'OK' ) {
206
        if ( $canReserve->{status} eq 'OK' ) {
205
207
206
            # Find the lowest priority among holds on the new item
208
            my $new_priority = C4::Reserves::_ShiftPriority( $new_biblionumber, $priority );
207
            my $highest_new_priority = Koha::Holds->search(
208
                { biblionumber => $new_biblionumber },
209
                { order_by     => { -desc => 'priority' }, rows => 1 }
210
            )->next;
211
            my $next_available_priority =
212
                $highest_new_priority ? $highest_new_priority->priority + 1 : 1;    # Always start at 1 if empty
213
209
214
            $self->update(
210
            $self->update(
215
                {
211
                {
216
                    itemnumber   => $new_item->itemnumber,
212
                    itemnumber   => $new_item->itemnumber,
217
                    biblionumber => $new_item->biblionumber,
213
                    biblionumber => $new_item->biblionumber,
218
                    priority     => $next_available_priority,
214
                    priority     => $new_priority,
219
                }
215
                }
220
            );
216
            );
221
217
(-)a/reserve/request.pl (-6 / +24 lines)
Lines 120-146 if ( $op eq 'cud-move' ) { Link Here
120
    my @success_messages;
120
    my @success_messages;
121
    my @error_messages;
121
    my @error_messages;
122
122
123
    foreach my $hold_id (@hold_ids) {
123
    #Get a list of all the holds to move, ordered by current priority
124
        my $hold            = Koha::Holds->find($hold_id);
124
    my @moving_holds = Koha::Holds->search(
125
        { reserve_id => \@hold_ids },
126
        { order_by   => { -asc => 'priority' } }
127
    )->as_list;
128
129
    #Get the highest current priority of the target biblio
130
    my $highest_priority = Koha::Holds->search(
131
        { biblionumber => $new_biblionumber },
132
        { order_by     => { -desc => 'priority' }, rows => 1 }
133
    )->next;
134
135
    #Get a starting priority point to increment from on the new biblio
136
    my $base_priority = $highest_priority ? $highest_priority->priority : 0;
137
138
    my $offset = 0;
139
    foreach my $hold (@moving_holds) {
125
        my $original_biblio = Koha::Biblios->find( $hold->biblionumber );
140
        my $original_biblio = Koha::Biblios->find( $hold->biblionumber );
126
        my $result          = $hold->move_hold_item(
141
142
        #increment priority
143
        my $priority = ( $base_priority + $offset++ ) + 1;
144
        my $result   = $hold->move_hold_item(
127
            {
145
            {
128
                new_itemnumber   => $new_itemnumber,
146
                new_itemnumber   => $new_itemnumber,
129
                new_biblionumber => $new_biblionumber,
147
                new_biblionumber => $new_biblionumber,
148
                priority         => $priority
130
            }
149
            }
131
        );
150
        );
132
151
133
        #push info about successes and errors to the template
152
        #push info about successes and errors to the template
134
        if ( $result->{success} ) {
153
        if ( $result->{success} ) {
135
            push @success_messages, {
154
            push @success_messages, {
136
                hold_id         => $hold_id,
155
                hold_id         => $hold->id,
137
                success         => 1,
156
                success         => 1,
138
                original_biblio => $original_biblio,
157
                original_biblio => $original_biblio,
139
                target_biblio   => $target_biblio,
158
                target_biblio   => $target_biblio,
140
            };
159
            };
141
        } else {
160
        } else {
142
            push @error_messages, {
161
            push @error_messages, {
143
                hold_id         => $hold_id,
162
                hold_id         => $hold->id,
144
                success         => 0,
163
                success         => 0,
145
                original_biblio => $original_biblio,
164
                original_biblio => $original_biblio,
146
                target_biblio   => $target_biblio,
165
                target_biblio   => $target_biblio,
147
- 

Return to bug 31698