|
Lines 173-197
sub store {
Link Here
|
| 173 |
value => $self->biblio_id, |
173 |
value => $self->biblio_id, |
| 174 |
) unless ( $self->biblio ); |
174 |
) unless ( $self->biblio ); |
| 175 |
|
175 |
|
| 176 |
# Throw exception for item level booking clash |
176 |
# Skip clash detection when transitioning to a final |
| 177 |
Koha::Exceptions::Booking::Clash->throw() |
177 |
# status. During checkout C4::Circulation sets status |
| 178 |
if $self->item_id && !$self->item->check_booking( |
178 |
# to 'completed' and calls ->store; the clash checks |
| 179 |
{ |
179 |
# are irrelevant at that point and can produce false |
| 180 |
start_date => $self->start_date, |
180 |
# positives. |
| 181 |
end_date => $self->end_date, |
181 |
unless ( $self->_is_final_status_transition ) { |
| 182 |
booking_id => $self->in_storage ? $self->booking_id : undef |
182 |
|
| 183 |
} |
183 |
# Throw exception for item level booking clash |
| 184 |
); |
184 |
Koha::Exceptions::Booking::Clash->throw() |
| 185 |
|
185 |
if $self->item_id && !$self->item->check_booking( |
| 186 |
# Throw exception for biblio level booking clash |
186 |
{ |
| 187 |
Koha::Exceptions::Booking::Clash->throw() |
187 |
start_date => $self->start_date, |
| 188 |
if !$self->biblio->check_booking( |
188 |
end_date => $self->end_date, |
| 189 |
{ |
189 |
booking_id => $self->in_storage ? $self->booking_id : undef |
| 190 |
start_date => $self->start_date, |
190 |
} |
| 191 |
end_date => $self->end_date, |
191 |
); |
| 192 |
booking_id => $self->in_storage ? $self->booking_id : undef |
192 |
|
| 193 |
} |
193 |
# Throw exception for biblio level booking clash |
| 194 |
); |
194 |
Koha::Exceptions::Booking::Clash->throw() |
|
|
195 |
if !$self->biblio->check_booking( |
| 196 |
{ |
| 197 |
start_date => $self->start_date, |
| 198 |
end_date => $self->end_date, |
| 199 |
booking_id => $self->in_storage ? $self->booking_id : undef |
| 200 |
} |
| 201 |
); |
| 202 |
} |
| 195 |
|
203 |
|
| 196 |
# FIXME: We should be able to combine the above two functions into one |
204 |
# FIXME: We should be able to combine the above two functions into one |
| 197 |
|
205 |
|
|
Lines 336-341
sub to_api_mapping {
Link Here
|
| 336 |
|
344 |
|
| 337 |
=head2 Internal methods |
345 |
=head2 Internal methods |
| 338 |
|
346 |
|
|
|
347 |
=head3 _is_final_status_transition |
| 348 |
|
| 349 |
my $bool = $self->_is_final_status_transition; |
| 350 |
|
| 351 |
Returns true when the booking is being transitioned to a final status |
| 352 |
(cancelled or completed). Used to skip clash detection that is only |
| 353 |
meaningful for active bookings. |
| 354 |
|
| 355 |
=cut |
| 356 |
|
| 357 |
sub _is_final_status_transition { |
| 358 |
my ($self) = @_; |
| 359 |
|
| 360 |
return 0 unless $self->in_storage; |
| 361 |
|
| 362 |
my $updated_columns = { $self->_result->get_dirty_columns }; |
| 363 |
my $new_status = $updated_columns->{status}; |
| 364 |
|
| 365 |
return 0 unless $new_status; |
| 366 |
return 1 if any { $_ eq $new_status } qw( cancelled completed ); |
| 367 |
return 0; |
| 368 |
} |
| 369 |
|
| 339 |
=head3 _select_optimal_item |
370 |
=head3 _select_optimal_item |
| 340 |
|
371 |
|
| 341 |
my $item_id = $self->_select_optimal_item($available_items); |
372 |
my $item_id = $self->_select_optimal_item($available_items); |