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

(-)a/Koha/Item.pm (+10 lines)
Lines 210-215 returns 1 if the item is safe to delete, Link Here
210
210
211
"linked_analytics" if the item has linked analytic records.
211
"linked_analytics" if the item has linked analytic records.
212
212
213
"last_item_for_hold" if the item is the last one on a record on which a biblio-level hold is placed
214
213
=cut
215
=cut
214
216
215
sub safe_to_delete {
217
sub safe_to_delete {
Lines 230-235 sub safe_to_delete { Link Here
230
    return "linked_analytics"
232
    return "linked_analytics"
231
      if C4::Items::GetAnalyticsCount( $self->itemnumber ) > 0;
233
      if C4::Items::GetAnalyticsCount( $self->itemnumber ) > 0;
232
234
235
    return "last_item_for_hold"
236
      if $self->biblio->items->count == 1
237
      && $self->biblio->holds->search(
238
          {
239
              itemnumber => undef,
240
          }
241
        )->count;
242
233
    return 1;
243
    return 1;
234
}
244
}
235
245
(-)a/t/db_dependent/Items_DelItemCheck.t (-11 / +11 lines)
Lines 24-30 use Koha::Items; Link Here
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
25
use t::lib::Mocks;
26
26
27
use Test::More tests => 9;
27
use Test::More tests => 10;
28
use Test::MockModule;
28
use Test::MockModule;
29
29
30
BEGIN {
30
BEGIN {
Lines 71-90 my $patron = $builder->build( Link Here
71
    }
71
    }
72
);
72
);
73
73
74
my $biblio = $builder->build(
74
my $biblio = $builder->build_sample_biblio({branchcode => $branch->{branchcode}});
75
    {
76
        source => 'Biblio',
77
        value  => {
78
            branchcode => $branch->{branchcode},
79
        },
80
    }
81
);
82
75
83
my $item = $builder->build_object(
76
my $item = $builder->build_object(
84
    {
77
    {
85
        class => 'Koha::Items',
78
        class => 'Koha::Items',
86
        value  => {
79
        value  => {
87
            biblionumber  => $biblio->{biblionumber},
80
            biblionumber  => $biblio->biblionumber,
88
            homebranch    => $branch->{branchcode},
81
            homebranch    => $branch->{branchcode},
89
            holdingbranch => $branch->{branchcode},
82
            holdingbranch => $branch->{branchcode},
90
            withdrawn    => 0,       # randomly assigned value may block return.
83
            withdrawn    => 0,       # randomly assigned value may block return.
Lines 153-158 $item->set( { homebranch => $branch->{branchcode}, holdingbranch => $branch->{br Link Here
153
146
154
}
147
}
155
148
149
{ # last_item_for_hold
150
    C4::Reserves::AddReserve($branch->{branchcode}, $patron->{borrowernumber}, $item->biblionumber );
151
    is( $item->safe_to_delete, 'last_item_for_hold', 'Item cannot be deleted if a biblio-level is placed on the biblio and there is only 1 item attached to the biblio' );
152
153
    # With another item attached to the biblio, the item can be deleted
154
    $builder->build_sample_item({ biblionumber => $item->biblionumber });
155
}
156
156
is(
157
is(
157
    $item->safe_to_delete,
158
    $item->safe_to_delete,
158
    1,
159
    1,
159
- 

Return to bug 8132