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

(-)a/Koha/ItemType.pm (+12 lines)
Lines 138-143 sub parent { Link Here
138
    return Koha::ItemType->_new_from_dbic( $parent_rs );
138
    return Koha::ItemType->_new_from_dbic( $parent_rs );
139
139
140
}
140
}
141
142
=head3 children_with_localization
143
144
    Returns the ItemType objects of the children of this type or undef.
145
146
=cut
147
148
sub children_with_localization {
149
    my ( $self ) = @_;
150
    return Koha::ItemTypes->search_with_localization({ parent_type => $self->itemtype });
151
}
152
141
=head3 type
153
=head3 type
142
154
143
=cut
155
=cut
(-)a/Koha/Template/Plugin/ItemTypes.pm (-2 / +5 lines)
Lines 25-33 use base qw( Template::Plugin ); Link Here
25
use Koha::ItemTypes;
25
use Koha::ItemTypes;
26
26
27
sub GetDescription {
27
sub GetDescription {
28
    my ( $self, $itemtypecode ) = @_;
28
    my ( $self, $itemtypecode, $want_parent ) = @_;
29
    my $itemtype = Koha::ItemTypes->find( $itemtypecode );
29
    my $itemtype = Koha::ItemTypes->find( $itemtypecode );
30
    return $itemtype ? $itemtype->translated_description : q{};
30
    return q{} unless $itemtype;
31
    my $parent;
32
    $parent = $itemtype->parent if $want_parent;
33
    return $parent ? $parent->translated_description . "->" . $itemtype->translated_description : $itemtype->translated_description;
31
}
34
}
32
35
33
sub Get {
36
sub Get {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-1 / +14 lines)
Lines 49-54 Link Here
49
            <li>default (all libraries), all patron categories, same item type</li>
49
            <li>default (all libraries), all patron categories, same item type</li>
50
            <li>default (all libraries), all patron categories, all item types</li>
50
            <li>default (all libraries), all patron categories, all item types</li>
51
        </ul>
51
        </ul>
52
53
        <p>Where an itemtype has a parent, the rule will display as "Parent->Child" and the number of
54
        current checkouts allowed will be limited to either the maximum for the parent (counting sibling types)
55
        or the specific rule's type, whichever is less.</p>
52
        <p>To modify a rule, create a new one with the same patron category and item type.</p>
56
        <p>To modify a rule, create a new one with the same patron category and item type.</p>
53
    </div>
57
    </div>
54
    <div>
58
    <div>
Lines 166-172 Link Here
166
                        <td>[% IF rule.itemtype == '*' %]
170
                        <td>[% IF rule.itemtype == '*' %]
167
                                <em>All</em>
171
                                <em>All</em>
168
                            [% ELSE %]
172
                            [% ELSE %]
169
                                [% ItemTypes.GetDescription(rule.itemtype) | html %]
173
                                [% ItemTypes.GetDescription(rule.itemtype,1) | html %]
170
                            [% END %]
174
                            [% END %]
171
                        </td>
175
                        </td>
172
                        <td class="actions">
176
                        <td class="actions">
Lines 308-314 Link Here
308
                        <select name="itemtype" id="matrixitemtype" style="width:13em;">
312
                        <select name="itemtype" id="matrixitemtype" style="width:13em;">
309
                            <option value="*">All</option>
313
                            <option value="*">All</option>
310
                        [% FOREACH itemtypeloo IN itemtypeloop %]
314
                        [% FOREACH itemtypeloo IN itemtypeloop %]
315
                            [% NEXT IF itemtypeloo.parent_type %]
311
                            <option value="[% itemtypeloo.itemtype | html %]">[% itemtypeloo.translated_description | html %]</option>
316
                            <option value="[% itemtypeloo.itemtype | html %]">[% itemtypeloo.translated_description | html %]</option>
317
                            [% SET children = itemtypeloo.children_with_localization %]
318
                            [% IF children %]
319
                                <optgroup>
320
                                [% FOREACH child IN children %]
321
                                    <option value="[% child.itemtype | html %]">[% child.translated_description | html %]</option>
322
                                [% END %]
323
                                </optgroup>
324
                            [% END %]
312
                        [% END %]
325
                        [% END %]
313
                        </select>
326
                        </select>
314
                    </td>
327
                    </td>
(-)a/t/db_dependent/Koha/ItemTypes.t (-66 / +43 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Data::Dumper;
22
use Data::Dumper;
23
use Test::More tests => 24;
23
use Test::More tests => 13;
24
24
25
use t::lib::Mocks;
25
use t::lib::Mocks;
26
use t::lib::TestBuilder;
26
use t::lib::TestBuilder;
Lines 40-93 BEGIN { Link Here
40
my $database = Koha::Database->new();
40
my $database = Koha::Database->new();
41
my $schema   = $database->schema();
41
my $schema   = $database->schema();
42
$schema->txn_begin;
42
$schema->txn_begin;
43
Koha::ItemTypes->delete;
44
43
45
Koha::ItemType->new(
44
my $builder     = t::lib::TestBuilder->new;
46
    {
45
my $initial_count = Koha::ItemTypes->search->count;
47
        itemtype       => 'type1',
46
48
        description    => 'description',
47
my $parent1 = $builder->build_object({ class => 'Koha::ItemTypes', value => { description => 'description' } });
49
        rentalcharge   => '0.00',
48
my $child1  = $builder->build_object({
50
        imageurl       => 'imageurl',
49
        class => 'Koha::ItemTypes',
51
        summary        => 'summary',
50
        value => {
52
        checkinmsg     => 'checkinmsg',
51
            parent_type => $parent1->itemtype,
53
        checkinmsgtype => 'checkinmsgtype',
52
            description => 'description',
54
        processfee         => '0.00',
53
        }
55
        defaultreplacecost => '0.00',
54
    });
56
    }
55
my $child2  = $builder->build_object({
57
)->store;
56
        class => 'Koha::ItemTypes',
58
57
        value => {
59
Koha::ItemType->new(
58
            parent_type => $parent1->itemtype,
60
    {
59
            description => 'description',
61
        itemtype       => 'type2',
60
        }
62
        description    => 'description',
61
    });
63
        rentalcharge   => '0.00',
62
my $child3  = $builder->build_object({
64
        imageurl       => 'imageurl',
63
        class => 'Koha::ItemTypes',
65
        summary        => 'summary',
64
        value => {
66
        checkinmsg     => 'checkinmsg',
65
            parent_type => $parent1->itemtype,
67
        checkinmsgtype => 'checkinmsgtype',
66
            description => 'description',
68
        processfee         => '0.00',
67
        }
69
        defaultreplacecost => '0.00',
68
    });
70
    }
71
)->store;
72
73
Koha::ItemType->new(
74
    {
75
        itemtype       => 'type3',
76
        description    => 'description',
77
        rentalcharge   => '0.00',
78
        imageurl       => 'imageurl',
79
        summary        => 'summary',
80
        checkinmsg     => 'checkinmsg',
81
        checkinmsgtype => 'checkinmsgtype',
82
        processfee         => '0.00',
83
        defaultreplacecost => '0.00',
84
    }
85
)->store;
86
69
87
Koha::Localization->new(
70
Koha::Localization->new(
88
    {
71
    {
89
        entity      => 'itemtypes',
72
        entity      => 'itemtypes',
90
        code        => 'type1',
73
        code        => $child1->itemtype,
91
        lang        => 'en',
74
        lang        => 'en',
92
        translation => 'b translated itemtype desc'
75
        translation => 'b translated itemtype desc'
93
    }
76
    }
Lines 95-101 Koha::Localization->new( Link Here
95
Koha::Localization->new(
78
Koha::Localization->new(
96
    {
79
    {
97
        entity      => 'itemtypes',
80
        entity      => 'itemtypes',
98
        code        => 'type2',
81
        code        => $child2->itemtype,
99
        lang        => 'en',
82
        lang        => 'en',
100
        translation => 'a translated itemtype desc'
83
        translation => 'a translated itemtype desc'
101
    }
84
    }
Lines 103-138 Koha::Localization->new( Link Here
103
Koha::Localization->new(
86
Koha::Localization->new(
104
    {
87
    {
105
        entity      => 'something_else',
88
        entity      => 'something_else',
106
        code        => 'type2',
89
        code        => $child2->itemtype,
107
        lang        => 'en',
90
        lang        => 'en',
108
        translation => 'another thing'
91
        translation => 'another thing'
109
    }
92
    }
110
)->store;
93
)->store;
111
94
112
my $type = Koha::ItemTypes->find('type1');
95
my $type = Koha::ItemTypes->find($child1->itemtype);
113
ok( defined($type), 'first result' );
96
ok( defined($type), 'first result' );
114
is( $type->itemtype,       'type1',          'itemtype/code' );
97
is_deeply( $type->unblessed, $child1->unblessed, "We got back the same object" );
115
is( $type->description,    'description',    'description' );
98
116
is( $type->rentalcharge,   '0.000000',       'rentalcharge' );
99
$type = Koha::ItemTypes->find($child2->itemtype);
117
is( $type->imageurl,       'imageurl',       'imageurl' );
118
is( $type->summary,        'summary',        'summary' );
119
is( $type->checkinmsg,     'checkinmsg',     'checkinmsg' );
120
is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' );
121
122
$type = Koha::ItemTypes->find('type2');
123
ok( defined($type), 'second result' );
100
ok( defined($type), 'second result' );
124
is( $type->itemtype,       'type2',          'itemtype/code' );
101
is_deeply( $type->unblessed, $child2->unblessed, "We got back the same object" );
125
is( $type->description,    'description',    'description' );
126
is( $type->rentalcharge,   '0.000000',       'rentalcharge' );
127
is( $type->imageurl,       'imageurl',       'imageurl' );
128
is( $type->summary,        'summary',        'summary' );
129
is( $type->checkinmsg,     'checkinmsg',     'checkinmsg' );
130
is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' );
131
102
132
t::lib::Mocks::mock_preference('language', 'en');
103
t::lib::Mocks::mock_preference('language', 'en');
133
t::lib::Mocks::mock_preference('opaclanguages', 'en');
104
t::lib::Mocks::mock_preference('opaclanguages', 'en');
134
my $itemtypes = Koha::ItemTypes->search_with_localization;
105
my $itemtypes = Koha::ItemTypes->search_with_localization;
135
is( $itemtypes->count, 3, 'There are 3 item types' );
106
is( $itemtypes->count, $initial_count + 4, 'We added 4 item types' );
136
my $first_itemtype = $itemtypes->next;
107
my $first_itemtype = $itemtypes->next;
137
is(
108
is(
138
    $first_itemtype->translated_description,
109
    $first_itemtype->translated_description,
Lines 140-146 is( Link Here
140
    'item types should be sorted by translated description'
111
    'item types should be sorted by translated description'
141
);
112
);
142
113
143
my $builder = t::lib::TestBuilder->new;
114
my $children = $parent1->children_with_localization;
115
my $first_child = $children->next;
116
is(
117
    $first_child->translated_description,
118
    'a translated itemtype desc',
119
    'item types should be sorted by translated description'
120
);
121
144
my $item_type = $builder->build_object({ class => 'Koha::ItemTypes' });
122
my $item_type = $builder->build_object({ class => 'Koha::ItemTypes' });
145
123
146
is( $item_type->can_be_deleted, 1, 'An item type that is not used can be deleted');
124
is( $item_type->can_be_deleted, 1, 'An item type that is not used can be deleted');
147
- 

Return to bug 21946