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

(-)a/Koha/Item.pm (-14 / +23 lines)
Lines 289-317 returns 1 if the item is safe to delete, Link Here
289
sub safe_to_delete {
289
sub safe_to_delete {
290
    my ($self) = @_;
290
    my ($self) = @_;
291
291
292
    return Koha::Result::Boolean->new(0)->add_message({ message => "book_on_loan" })
292
    my $error;
293
      if $self->checkout;
294
293
295
    return Koha::Result::Boolean->new(0)->add_message({ message => "not_same_branch" })
294
    $error = "book_on_loan" if $self->checkout;
296
      if defined C4::Context->userenv
297
      and !C4::Context->IsSuperLibrarian()
298
      and C4::Context->preference("IndependentBranches")
299
      and ( C4::Context->userenv->{branch} ne $self->homebranch );
300
295
301
    return Koha::Result::Boolean->new(0)->add_message({ message => "book_reserved" })
296
    $error = "not_same_branch"
302
      if $self->holds->filter_by_found->count;
297
      if !$error
298
      && defined C4::Context->userenv
299
      && !C4::Context->IsSuperLibrarian()
300
      && C4::Context->preference("IndependentBranches")
301
      && ( C4::Context->userenv->{branch} ne $self->homebranch );
303
302
304
    return Koha::Result::Boolean->new(0)->add_message({ message => "linked_analytics" })
303
    # check it doesn't have a waiting reserve
305
      if C4::Items::GetAnalyticsCount( $self->itemnumber ) > 0;
304
    $error = "book_reserved"
305
      if !$error
306
      && $self->holds->filter_by_found->count;
306
307
307
    return Koha::Result::Boolean->new(0)->add_message({ message => "last_item_for_hold" })
308
    $error = "linked_analytics"
308
      if $self->biblio->items->count == 1
309
      if !$error
310
      && C4::Items::GetAnalyticsCount( $self->itemnumber ) > 0;
311
312
    $error = "last_item_for_hold"
313
      if !$error
314
      && $self->biblio->items->count == 1
309
      && $self->biblio->holds->search(
315
      && $self->biblio->holds->search(
310
          {
316
          {
311
              itemnumber => undef,
317
              itemnumber => undef,
312
          }
318
          }
313
        )->count;
319
        )->count;
314
320
321
    if ( $error ) {
322
        return Koha::Result::Boolean->new(0)->add_message({ message => $error });
323
    }
324
315
    return Koha::Result::Boolean->new(1);
325
    return Koha::Result::Boolean->new(1);
316
}
326
}
317
327
318
- 

Return to bug 32528