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

(-)a/admin/itemtypes.pl (-65 / +66 lines)
Lines 25-34 Link Here
25
use Modern::Perl;
25
use Modern::Perl;
26
use CGI qw ( -utf8 );
26
use CGI qw ( -utf8 );
27
27
28
29
use C4::Koha qw( getImageSets GetAuthorisedValues );
28
use C4::Koha qw( getImageSets GetAuthorisedValues );
30
use C4::Context;
29
use C4::Context;
31
use C4::Auth qw( get_template_and_user );
30
use C4::Auth   qw( get_template_and_user );
32
use C4::Output qw( output_html_with_http_headers );
31
use C4::Output qw( output_html_with_http_headers );
33
use Koha::ItemTypes;
32
use Koha::ItemTypes;
34
use Koha::ItemType;
33
use Koha::ItemType;
Lines 41-50 my $op = $input->param('op') // 'list'; Link Here
41
my @messages;
40
my @messages;
42
$searchfield =~ s/\,//g if $searchfield;
41
$searchfield =~ s/\,//g if $searchfield;
43
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
42
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
44
    {   template_name   => "admin/itemtypes.tt",
43
    {
45
        query           => $input,
44
        template_name => "admin/itemtypes.tt",
46
        type            => "intranet",
45
        query         => $input,
47
        flagsrequired   => { parameters => 'manage_itemtypes' },
46
        type          => "intranet",
47
        flagsrequired => { parameters => 'manage_itemtypes' },
48
    }
48
    }
49
);
49
);
50
50
Lines 56-104 undef($sip_media_type) if defined($sip_media_type) and $sip_media_type =~ /^\s*$ Link Here
56
if ( $op eq 'add_form' ) {
56
if ( $op eq 'add_form' ) {
57
    my $itemtype = Koha::ItemTypes->find($itemtype_code);
57
    my $itemtype = Koha::ItemTypes->find($itemtype_code);
58
58
59
    my $parent_type = $itemtype ? $itemtype->parent_type : undef;
59
    my $parent_type    = $itemtype ? $itemtype->parent_type : undef;
60
    my $parent_types = Koha::ItemTypes->search({parent_type=>undef,itemtype => {'!='=>$itemtype_code}});
60
    my $parent_types   = Koha::ItemTypes->search( { parent_type => undef, itemtype => { '!=' => $itemtype_code } } );
61
    my $imagesets = C4::Koha::getImageSets( checked => ( $itemtype ? $itemtype->imageurl : undef ) );
61
    my $imagesets      = C4::Koha::getImageSets( checked => ( $itemtype ? $itemtype->imageurl : undef ) );
62
    my $searchcategory = GetAuthorisedValues("ITEMTYPECAT");
62
    my $searchcategory = GetAuthorisedValues("ITEMTYPECAT");
63
    my $translated_languages = C4::Languages::getTranslatedLanguages( "both", C4::Context->preference('template') );
63
    my $translated_languages = C4::Languages::getTranslatedLanguages( "both", C4::Context->preference('template') );
64
    $template->param(
64
    $template->param(
65
        itemtype  => $itemtype,
65
        itemtype          => $itemtype,
66
        parent_type => $parent_type,
66
        parent_type       => $parent_type,
67
        parent_types => $parent_types,
67
        parent_types      => $parent_types,
68
        is_a_parent => $itemtype ? Koha::ItemTypes->search({parent_type=>$itemtype_code})->count : 0,
68
        is_a_parent       => $itemtype ? Koha::ItemTypes->search( { parent_type => $itemtype_code } )->count : 0,
69
        imagesets => $imagesets,
69
        imagesets         => $imagesets,
70
        searchcategory => $searchcategory,
70
        searchcategory    => $searchcategory,
71
        can_be_translated => ( scalar(@$translated_languages) > 1 ? 1 : 0 ),
71
        can_be_translated => ( scalar(@$translated_languages) > 1 ? 1 : 0 ),
72
    );
72
    );
73
} elsif ( $op eq 'cud-add_validate' ) {
73
} elsif ( $op eq 'cud-add_validate' ) {
74
    my $is_a_modif   = $input->param('is_a_modif');
74
    my $is_a_modif          = $input->param('is_a_modif');
75
    my $itemtype     = Koha::ItemTypes->find($itemtype_code);
75
    my $itemtype            = Koha::ItemTypes->find($itemtype_code);
76
    my $parent_type  = $input->param('parent_type') || undef;
76
    my $parent_type         = $input->param('parent_type') || undef;
77
    my $description  = $input->param('description');
77
    my $description         = $input->param('description');
78
    my $rentalcharge = $input->param('rentalcharge');
78
    my $rentalcharge        = $input->param('rentalcharge');
79
    my $rentalcharge_daily = $input->param('rentalcharge_daily');
79
    my $rentalcharge_daily  = $input->param('rentalcharge_daily');
80
    my $rentalcharge_hourly = $input->param('rentalcharge_hourly');
80
    my $rentalcharge_hourly = $input->param('rentalcharge_hourly');
81
    my $defaultreplacecost = $input->param('defaultreplacecost');
81
    my $defaultreplacecost  = $input->param('defaultreplacecost');
82
    my $processfee = $input->param('processfee');
82
    my $processfee          = $input->param('processfee');
83
    my $image = $input->param('image') || q||;
83
    my $image               = $input->param('image') || q||;
84
    my @branches = grep { $_ ne q{} } $input->multi_param('branches');
84
    my @branches            = grep { $_ ne q{} } $input->multi_param('branches');
85
85
86
    my $notforloan = $input->param('notforloan') ? 1 : 0;
86
    my $notforloan = $input->param('notforloan') ? 1 : 0;
87
    my $imageurl =
87
    my $imageurl =
88
      $image eq 'removeImage' ? ''
88
        $image eq 'removeImage' ? ''
89
      : (
89
        : (
90
          $image eq 'remoteImage' ? $input->param('remoteImage')
90
          $image eq 'remoteImage' ? $input->param('remoteImage')
91
        : $image
91
        : $image
92
      );
92
        );
93
    my $summary        = $input->param('summary');
93
    my $summary                      = $input->param('summary');
94
    my $checkinmsg     = $input->param('checkinmsg');
94
    my $checkinmsg                   = $input->param('checkinmsg');
95
    my $checkinmsgtype = $input->param('checkinmsgtype');
95
    my $checkinmsgtype               = $input->param('checkinmsgtype');
96
    my $hideinopac     = $input->param('hideinopac') // 0;
96
    my $hideinopac                   = $input->param('hideinopac') // 0;
97
    my $searchcategory = $input->param('searchcategory');
97
    my $searchcategory               = $input->param('searchcategory');
98
    my $rentalcharge_daily_calendar  = $input->param('rentalcharge_daily_calendar') // 0;
98
    my $rentalcharge_daily_calendar  = $input->param('rentalcharge_daily_calendar')  // 0;
99
    my $rentalcharge_hourly_calendar = $input->param('rentalcharge_hourly_calendar') // 0;
99
    my $rentalcharge_hourly_calendar = $input->param('rentalcharge_hourly_calendar') // 0;
100
    my $automatic_checkin = $input->param('automatic_checkin') // 0;
100
    my $automatic_checkin            = $input->param('automatic_checkin')            // 0;
101
    my $bookable = $input->param('bookable')// 0;
101
    my $bookable                     = $input->param('bookable')                     // 0;
102
102
103
    if ( $itemtype and $is_a_modif ) {    # it's a modification
103
    if ( $itemtype and $is_a_modif ) {    # it's a modification
104
        $itemtype->description($description);
104
        $itemtype->description($description);
Lines 122-129 if ( $op eq 'add_form' ) { Link Here
122
        $itemtype->bookable($bookable);
122
        $itemtype->bookable($bookable);
123
123
124
        eval {
124
        eval {
125
          $itemtype->store;
125
            $itemtype->store;
126
          $itemtype->replace_library_limits( \@branches );
126
            $itemtype->replace_library_limits( \@branches );
127
        };
127
        };
128
128
129
        if ($@) {
129
        if ($@) {
Lines 134-164 if ( $op eq 'add_form' ) { Link Here
134
    } elsif ( not $itemtype and not $is_a_modif ) {
134
    } elsif ( not $itemtype and not $is_a_modif ) {
135
        my $itemtype = Koha::ItemType->new(
135
        my $itemtype = Koha::ItemType->new(
136
            {
136
            {
137
                itemtype            => $itemtype_code,
137
                itemtype                     => $itemtype_code,
138
                description         => $description,
138
                description                  => $description,
139
                parent_type         => $parent_type,
139
                parent_type                  => $parent_type,
140
                rentalcharge        => $rentalcharge,
140
                rentalcharge                 => $rentalcharge,
141
                rentalcharge_daily  => $rentalcharge_daily,
141
                rentalcharge_daily           => $rentalcharge_daily,
142
                rentalcharge_hourly => $rentalcharge_hourly,
142
                rentalcharge_hourly          => $rentalcharge_hourly,
143
                defaultreplacecost  => $defaultreplacecost,
143
                defaultreplacecost           => $defaultreplacecost,
144
                processfee          => $processfee,
144
                processfee                   => $processfee,
145
                notforloan          => $notforloan,
145
                notforloan                   => $notforloan,
146
                imageurl            => $imageurl,
146
                imageurl                     => $imageurl,
147
                summary             => $summary,
147
                summary                      => $summary,
148
                checkinmsg          => $checkinmsg,
148
                checkinmsg                   => $checkinmsg,
149
                checkinmsgtype      => $checkinmsgtype,
149
                checkinmsgtype               => $checkinmsgtype,
150
                sip_media_type      => $sip_media_type,
150
                sip_media_type               => $sip_media_type,
151
                hideinopac          => $hideinopac,
151
                hideinopac                   => $hideinopac,
152
                searchcategory      => $searchcategory,
152
                searchcategory               => $searchcategory,
153
                rentalcharge_daily_calendar  => $rentalcharge_daily_calendar,
153
                rentalcharge_daily_calendar  => $rentalcharge_daily_calendar,
154
                rentalcharge_hourly_calendar => $rentalcharge_hourly_calendar,
154
                rentalcharge_hourly_calendar => $rentalcharge_hourly_calendar,
155
                automatic_checkin   => $automatic_checkin,
155
                automatic_checkin            => $automatic_checkin,
156
                bookable   => $bookable,
156
                bookable                     => $bookable,
157
            }
157
            }
158
        );
158
        );
159
        eval {
159
        eval {
160
          $itemtype->store;
160
            $itemtype->store;
161
          $itemtype->replace_library_limits( \@branches );
161
            $itemtype->replace_library_limits( \@branches );
162
        };
162
        };
163
163
164
        if ($@) {
164
        if ($@) {
Lines 168-186 if ( $op eq 'add_form' ) { Link Here
168
        }
168
        }
169
    } else {
169
    } else {
170
        push @messages,
170
        push @messages,
171
          { type => 'alert',
171
            {
172
            type => 'alert',
172
            code => 'already_exists',
173
            code => 'already_exists',
173
          };
174
            };
174
    }
175
    }
175
176
176
    $searchfield = '';
177
    $searchfield = '';
177
    $op          = 'list';
178
    $op          = 'list';
178
179
179
 } elsif ( $op eq 'delete_confirm' ) {
180
} elsif ( $op eq 'delete_confirm' ) {
180
    my $itemtype = Koha::ItemTypes->find($itemtype_code);
181
    my $itemtype       = Koha::ItemTypes->find($itemtype_code);
181
    my $can_be_deleted = $itemtype->can_be_deleted();
182
    my $can_be_deleted = $itemtype->can_be_deleted();
182
    if ($can_be_deleted == 0) {
183
    if ( $can_be_deleted == 0 ) {
183
        push @messages, { type => 'alert', code => 'cannot_be_deleted'};
184
        push @messages, { type => 'alert', code => 'cannot_be_deleted' };
184
        $op = 'list';
185
        $op = 'list';
185
    } else {
186
    } else {
186
        $template->param( itemtype => $itemtype, );
187
        $template->param( itemtype => $itemtype, );
Lines 189-195 if ( $op eq 'add_form' ) { Link Here
189
} elsif ( $op eq 'cud-delete_confirmed' ) {
190
} elsif ( $op eq 'cud-delete_confirmed' ) {
190
191
191
    my $itemtype = Koha::ItemTypes->find($itemtype_code);
192
    my $itemtype = Koha::ItemTypes->find($itemtype_code);
192
    my $deleted = eval { $itemtype->delete };
193
    my $deleted  = eval { $itemtype->delete };
193
    if ( $@ or not $deleted ) {
194
    if ( $@ or not $deleted ) {
194
        push @messages, { type => 'alert', code => 'error_on_delete' };
195
        push @messages, { type => 'alert', code => 'error_on_delete' };
195
    } else {
196
    } else {
(-)a/t/db_dependent/Koha/Items.t (-11 / +22 lines)
Lines 2180-2199 subtest 'filter_by_bookable' => sub { Link Here
2180
2180
2181
    $schema->storage->txn_begin;
2181
    $schema->storage->txn_begin;
2182
2182
2183
    t::lib::Mocks::mock_preference('item-level_itypes', 0);
2183
    t::lib::Mocks::mock_preference( 'item-level_itypes', 0 );
2184
2184
2185
    my $bookable_item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 1 } } );
2185
    my $bookable_item_type     = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 1 } } );
2186
    my $non_bookable_item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 0 } } );
2186
    my $non_bookable_item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 0 } } );
2187
    my $biblio = $builder->build_sample_biblio({ itemtype => $bookable_item_type->itemtype });
2187
    my $biblio                 = $builder->build_sample_biblio( { itemtype => $bookable_item_type->itemtype } );
2188
2188
2189
    # bookable items
2189
    # bookable items
2190
    my $bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $bookable_item_type->itemtype, bookable => 1 } );
2190
    my $bookable_item1 = $builder->build_sample_item(
2191
        { biblionumber => $biblio->biblionumber, itype => $bookable_item_type->itemtype, bookable => 1 } );
2191
2192
2192
    # not bookable items
2193
    # not bookable items
2193
    my $non_bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $non_bookable_item_type->itemtype, bookable => 0 } );
2194
    my $non_bookable_item1 = $builder->build_sample_item(
2194
    my $non_bookable_item2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $non_bookable_item_type->itemtype, bookable => 0 } );
2195
        { biblionumber => $biblio->biblionumber, itype => $non_bookable_item_type->itemtype, bookable => 0 } );
2196
    my $non_bookable_item2 = $builder->build_sample_item(
2197
        { biblionumber => $biblio->biblionumber, itype => $non_bookable_item_type->itemtype, bookable => 0 } );
2195
2198
2196
    is( $biblio->items->filter_by_bookable->count, 1, "filter_by_bookable returns the correct number of items set at item level" );
2199
    is(
2200
        $biblio->items->filter_by_bookable->count, 1,
2201
        "filter_by_bookable returns the correct number of items set at item level"
2202
    );
2197
    is(
2203
    is(
2198
        $biblio->items->filter_by_bookable->next->itemnumber, $bookable_item1->itemnumber,
2204
        $biblio->items->filter_by_bookable->next->itemnumber, $bookable_item1->itemnumber,
2199
        "the correct item is returned from filter_by_bookable at the item level"
2205
        "the correct item is returned from filter_by_bookable at the item level"
Lines 2203-2212 subtest 'filter_by_bookable' => sub { Link Here
2203
    $non_bookable_item1->bookable(undef)->store();
2209
    $non_bookable_item1->bookable(undef)->store();
2204
    $non_bookable_item2->bookable(undef)->store();
2210
    $non_bookable_item2->bookable(undef)->store();
2205
    $biblio->get_from_storage;
2211
    $biblio->get_from_storage;
2206
    is( $biblio->items->filter_by_bookable->count, 3, "filter_by_bookable returns the correct number of items when not set at item level and using biblio level itemtypes" );
2212
    is(
2213
        $biblio->items->filter_by_bookable->count, 3,
2214
        "filter_by_bookable returns the correct number of items when not set at item level and using biblio level itemtypes"
2215
    );
2207
2216
2208
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
2217
    t::lib::Mocks::mock_preference( 'item-level_itypes', 1 );
2209
    is( $biblio->items->filter_by_bookable->count, 1, "filter_by_bookable returns the correct number of items when not set at item level and using item level itemtypes" );
2218
    is(
2219
        $biblio->items->filter_by_bookable->count, 1,
2220
        "filter_by_bookable returns the correct number of items when not set at item level and using item level itemtypes"
2221
    );
2210
2222
2211
    $schema->storage->txn_rollback;
2223
    $schema->storage->txn_rollback;
2212
};
2224
};
2213
- 

Return to bug 35906