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

(-)a/Koha/Item.pm (+14 lines)
Lines 1874-1879 sub effective_not_for_loan_status { Link Here
1874
    return ( defined($itype_notforloan) && !$self->notforloan ) ? $itype_notforloan : $self->notforloan;
1874
    return ( defined($itype_notforloan) && !$self->notforloan ) ? $itype_notforloan : $self->notforloan;
1875
}
1875
}
1876
1876
1877
=head3 effective_bookable
1878
1879
  my $bookable = $item->effective_bookable;
1880
1881
Returns the effective bookability of the current item, be that item or itemtype level
1882
1883
=cut
1884
1885
sub effective_bookable {
1886
    my ($self) = @_;
1887
1888
    return defined( $self->bookable ) ? $self->bookable : $self->itemtype->bookable;
1889
}
1890
1877
=head3 orders
1891
=head3 orders
1878
1892
1879
  my $orders = $item->orders();
1893
  my $orders = $item->orders();
(-)a/Koha/Items.pm (-5 / +10 lines)
Lines 191-202 Returns a new resultset, containing only those items that are allowed to be book Link Here
191
sub filter_by_bookable {
191
sub filter_by_bookable {
192
    my ($self) = @_;
192
    my ($self) = @_;
193
193
194
    my $params =
194
    my @bookable_itemtypes = Koha::ItemTypes->search( { bookable => 1 } )->get_column('itemtype');
195
        C4::Context->preference('item-level_booking') == 1
196
        ? { bookable => 1 }
197
        : { itype    => { -in => \'SELECT itemtype FROM itemtypes WHERE bookable = 1' } };
198
195
199
    return $self->search($params);
196
    my ( $where, $attr );
197
    if ( C4::Context->preference("item-level_itypes") ) {
198
        $where = [ { bookable => 1 }, { bookable => undef, itype => { -in => \@bookable_itemtypes } } ];
199
    } else {
200
        $where = [ { bookable => 1 }, { bookable => undef, 'biblioitem.itemtype' => { -in => \@bookable_itemtypes } } ];
201
        $attr  = { join => 'biblioitem' };
202
    }
203
204
    return $self->search( $where, $attr );
200
}
205
}
201
206
202
=head3 move_to_biblio
207
=head3 move_to_biblio
(-)a/api/v1/swagger/definitions/item.yaml (-3 / +11 lines)
Lines 24-29 properties: Link Here
24
      - "null"
24
      - "null"
25
    description: Information about the acquisition source (it is not really a vendor id)
25
    description: Information about the acquisition source (it is not really a vendor id)
26
  bookable:
26
  bookable:
27
    type:
28
      - boolean
29
      - "null"
30
    description: Item level bookability override.
31
  effective_bookable:
27
    type: boolean
32
    type: boolean
28
    description: Allow bookings on this item.
33
    description: Allow bookings on this item.
29
  home_library_id:
34
  home_library_id:
Lines 90-96 properties: Link Here
90
      - string
95
      - string
91
      - "null"
96
      - "null"
92
    format: date-time
97
    format: date-time
93
    description: The date and time an item was last marked as withdrawn, NULL if not
98
    description:
99
      The date and time an item was last marked as withdrawn, NULL if not
94
      withdrawn
100
      withdrawn
95
  callnumber:
101
  callnumber:
96
    type:
102
    type:
Lines 155-168 properties: Link Here
155
    type:
161
    type:
156
      - string
162
      - string
157
      - "null"
163
      - "null"
158
    description: Linked to the CART and PROC temporary locations feature, stores the
164
    description:
165
      Linked to the CART and PROC temporary locations feature, stores the
159
      permanent shelving location
166
      permanent shelving location
160
  checked_out_date:
167
  checked_out_date:
161
    type:
168
    type:
162
      - string
169
      - string
163
      - "null"
170
      - "null"
164
    format: date
171
    format: date
165
    description: Defines if item is checked out (NULL for not checked out, and checkout
172
    description:
173
      Defines if item is checked out (NULL for not checked out, and checkout
166
      date for checked out)
174
      date for checked out)
167
  call_number_source:
175
  call_number_source:
168
    type:
176
    type:
(-)a/api/v1/swagger/paths/biblios.yaml (+1 lines)
Lines 479-484 Link Here
479
            - cover_image_ids
479
            - cover_image_ids
480
            - item_group_item.item_group.description
480
            - item_group_item.item_group.description
481
            - serial_item.serial
481
            - serial_item.serial
482
            - effective_bookable
482
        collectionFormat: csv
483
        collectionFormat: csv
483
      - $ref: "../swagger.yaml#/parameters/match"
484
      - $ref: "../swagger.yaml#/parameters/match"
484
      - $ref: "../swagger.yaml#/parameters/order_by"
485
      - $ref: "../swagger.yaml#/parameters/order_by"
(-)a/api/v1/swagger/paths/items.yaml (-1 / +3 lines)
Lines 22-27 Link Here
22
          enum:
22
          enum:
23
            - +strings
23
            - +strings
24
            - biblio
24
            - biblio
25
            - effective_bookable
25
        collectionFormat: csv
26
        collectionFormat: csv
26
      - $ref: "../swagger.yaml#/parameters/match"
27
      - $ref: "../swagger.yaml#/parameters/match"
27
      - $ref: "../swagger.yaml#/parameters/order_by"
28
      - $ref: "../swagger.yaml#/parameters/order_by"
Lines 88-93 Link Here
88
          type: string
89
          type: string
89
          enum:
90
          enum:
90
            - +strings
91
            - +strings
92
            - effective_bookable
91
        collectionFormat: csv
93
        collectionFormat: csv
92
    consumes:
94
    consumes:
93
      - application/json
95
      - application/json
Lines 157-163 Link Here
157
            * linked_analytics: The item has linked analytic records
159
            * linked_analytics: The item has linked analytic records
158
            * not_same_branch: The item is blocked by independent branches
160
            * not_same_branch: The item is blocked by independent branches
159
        schema:
161
        schema:
160
              $ref: "../swagger.yaml#/definitions/error"
162
          $ref: "../swagger.yaml#/definitions/error"
161
      "500":
163
      "500":
162
        description: |
164
        description: |
163
          Internal server error. Possible `error_code` attribute values:
165
          Internal server error. Possible `error_code` attribute values:
(-)a/catalogue/updateitem.pl (-1 / +2 lines)
Lines 39-45 my $itemnotes_nonpublic=$cgi->param('itemnotes_nonpublic'); Link Here
39
my $withdrawn=$cgi->param('withdrawn');
39
my $withdrawn=$cgi->param('withdrawn');
40
my $damaged=$cgi->param('damaged');
40
my $damaged=$cgi->param('damaged');
41
my $exclude_from_local_holds_priority = $cgi->param('exclude_from_local_holds_priority');
41
my $exclude_from_local_holds_priority = $cgi->param('exclude_from_local_holds_priority');
42
my $bookable = $cgi->param('bookable');
42
my $bookable = $cgi->param('bookable') // q{};
43
43
44
my $confirm=$cgi->param('confirm');
44
my $confirm=$cgi->param('confirm');
45
my $dbh = C4::Context->dbh;
45
my $dbh = C4::Context->dbh;
Lines 77-82 elsif ( $op eq "cud-set_public_note" ) { # i.e., itemnotes parameter passed from Link Here
77
    $item->exclude_from_local_holds_priority($exclude_from_local_holds_priority);
77
    $item->exclude_from_local_holds_priority($exclude_from_local_holds_priority);
78
    $messages = "updated_exclude_from_local_holds_priority=$exclude_from_local_holds_priority&";
78
    $messages = "updated_exclude_from_local_holds_priority=$exclude_from_local_holds_priority&";
79
} elsif ( $op eq "cud-set_bookable" && $bookable ne $item_data_hashref->{'bookable'} ) {
79
} elsif ( $op eq "cud-set_bookable" && $bookable ne $item_data_hashref->{'bookable'} ) {
80
    undef($bookable) if $bookable eq "";
80
    $item->bookable($bookable);
81
    $item->bookable($bookable);
81
} elsif ( $op eq "cud-set_damaged" && $damaged ne $item_data_hashref->{'damaged'}) {
82
} elsif ( $op eq "cud-set_damaged" && $damaged ne $item_data_hashref->{'damaged'}) {
82
    $item->damaged($damaged);
83
    $item->damaged($damaged);
(-)a/installer/data/mysql/atomicupdate/Bug_35906_add-column-bookable-itemtype.pl (-7 / +21 lines)
Lines 7-21 return { Link Here
7
        my ($args) = @_;
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
9
10
        $dbh->do(q{
10
        $dbh->do(
11
            INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES  ('item-level_booking', 1, '', 'enables item type level for future booking', 'YesNo');
11
            q{
12
        });
13
14
        $dbh->do(q{
15
            ALTER TABLE itemtypes ADD IF NOT EXISTS bookable INT(1) DEFAULT 0
12
            ALTER TABLE itemtypes ADD IF NOT EXISTS bookable INT(1) DEFAULT 0
16
        });
13
        }
14
        );
17
15
18
        say $out "Added new system preference 'item-level_booking'";
19
        say $out "Added column 'itemtypes.bookable'";
16
        say $out "Added column 'itemtypes.bookable'";
17
18
        $dbh->do(
19
            q{
20
            ALTER TABLE items MODIFY COLUMN bookable tinyint(1) DEFAULT NULL COMMENT 'nullable boolean value defining whether this this item is available for bookings or not'
21
        }
22
        );
23
24
        say $out "Updated column 'items.bookable' allow nullable";
25
26
        $dbh->do(
27
            q{
28
            ALTER TABLE deleteditems MODIFY COLUMN bookable tinyint(1) DEFAULT NULL COMMENT 'nullable boolean value defining whether this this item is available for bookings or not'
29
        }
30
        );
31
32
        say $out "Updated column 'deleteditems.bookable' allow nullable";
33
20
    },
34
    },
21
};
35
};
(-)a/installer/data/mysql/kohastructure.sql (-2 / +2 lines)
Lines 2754-2760 CREATE TABLE `deleteditems` ( Link Here
2754
  `biblionumber` int(11) NOT NULL DEFAULT 0 COMMENT 'foreign key from biblio table used to link this item to the right bib record',
2754
  `biblionumber` int(11) NOT NULL DEFAULT 0 COMMENT 'foreign key from biblio table used to link this item to the right bib record',
2755
  `biblioitemnumber` int(11) NOT NULL DEFAULT 0 COMMENT 'foreign key from the biblioitems table to link to item to additional information',
2755
  `biblioitemnumber` int(11) NOT NULL DEFAULT 0 COMMENT 'foreign key from the biblioitems table to link to item to additional information',
2756
  `barcode` varchar(20) DEFAULT NULL COMMENT 'item barcode (MARC21 952$p)',
2756
  `barcode` varchar(20) DEFAULT NULL COMMENT 'item barcode (MARC21 952$p)',
2757
  `bookable` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'boolean value defining whether this item is available for bookings or not',
2757
  `bookable` tinyint(1) DEFAULT NULL COMMENT 'nullable boolean value defining whether this this item is available for bookings or not',
2758
  `dateaccessioned` date DEFAULT NULL COMMENT 'date the item was acquired or added to Koha (MARC21 952$d)',
2758
  `dateaccessioned` date DEFAULT NULL COMMENT 'date the item was acquired or added to Koha (MARC21 952$d)',
2759
  `booksellerid` longtext DEFAULT NULL COMMENT 'where the item was purchased (MARC21 952$e)',
2759
  `booksellerid` longtext DEFAULT NULL COMMENT 'where the item was purchased (MARC21 952$e)',
2760
  `homebranch` varchar(10) DEFAULT NULL COMMENT 'foreign key from the branches table for the library that owns this item (MARC21 952$a)',
2760
  `homebranch` varchar(10) DEFAULT NULL COMMENT 'foreign key from the branches table for the library that owns this item (MARC21 952$a)',
Lines 4012-4018 CREATE TABLE `items` ( Link Here
4012
  `biblionumber` int(11) NOT NULL DEFAULT 0 COMMENT 'foreign key from biblio table used to link this item to the right bib record',
4012
  `biblionumber` int(11) NOT NULL DEFAULT 0 COMMENT 'foreign key from biblio table used to link this item to the right bib record',
4013
  `biblioitemnumber` int(11) NOT NULL DEFAULT 0 COMMENT 'foreign key from the biblioitems table to link to item to additional information',
4013
  `biblioitemnumber` int(11) NOT NULL DEFAULT 0 COMMENT 'foreign key from the biblioitems table to link to item to additional information',
4014
  `barcode` varchar(20) DEFAULT NULL COMMENT 'item barcode (MARC21 952$p)',
4014
  `barcode` varchar(20) DEFAULT NULL COMMENT 'item barcode (MARC21 952$p)',
4015
  `bookable` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'boolean value defining whether this item is available for bookings or not',
4015
  `bookable` tinyint(1) DEFAULT NULL COMMENT 'nullable boolean value defining whether this this item is available for bookings or not',
4016
  `dateaccessioned` date DEFAULT NULL COMMENT 'date the item was acquired or added to Koha (MARC21 952$d)',
4016
  `dateaccessioned` date DEFAULT NULL COMMENT 'date the item was acquired or added to Koha (MARC21 952$d)',
4017
  `booksellerid` longtext DEFAULT NULL COMMENT 'where the item was purchased (MARC21 952$e)',
4017
  `booksellerid` longtext DEFAULT NULL COMMENT 'where the item was purchased (MARC21 952$e)',
4018
  `homebranch` varchar(10) DEFAULT NULL COMMENT 'foreign key from the branches table for the library that owns this item (MARC21 952$a)',
4018
  `homebranch` varchar(10) DEFAULT NULL COMMENT 'foreign key from the branches table for the library that owns this item (MARC21 952$a)',
(-)a/installer/data/mysql/mandatory/sysprefs.sql (-1 lines)
Lines 354-360 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
354
('IssueLostItem','alert','Defines what should be done when an attempt is made to issue an item that has been marked as lost.','alert|confirm|nothing','Choice'),
354
('IssueLostItem','alert','Defines what should be done when an attempt is made to issue an item that has been marked as lost.','alert|confirm|nothing','Choice'),
355
('IssuingInProcess','0',NULL,'If ON, disables fines if the patron is issuing item that accumulate debt','YesNo'),
355
('IssuingInProcess','0',NULL,'If ON, disables fines if the patron is issuing item that accumulate debt','YesNo'),
356
('item-level_itypes','1','','If ON, enables Item-level Itemtype / Issuing Rules','YesNo'),
356
('item-level_itypes','1','','If ON, enables Item-level Itemtype / Issuing Rules','YesNo'),
357
('item-level_booking','1','','If ON, enables Item-level for future booking feature','YesNo'),
358
('itemBarcodeFallbackSearch','0',NULL,'If set, uses scanned item barcodes as a catalogue search if not found as barcodes','YesNo'),
357
('itemBarcodeFallbackSearch','0',NULL,'If set, uses scanned item barcodes as a catalogue search if not found as barcodes','YesNo'),
359
('itemBarcodeInputFilter','','whitespace|T-prefix|cuecat|libsuite8|EAN13','If set, allows specification of a item barcode input filter','Choice'),
358
('itemBarcodeInputFilter','','whitespace|T-prefix|cuecat|libsuite8|EAN13','If set, allows specification of a item barcode input filter','Choice'),
360
('itemcallnumber','',NULL,'The MARC field/subfield that is used to calculate the itemcallnumber (Dewey would be 082ab or 092ab; LOC would be 050ab or 090ab) could be 852hi from an item record','free'),
359
('itemcallnumber','',NULL,'The MARC field/subfield that is used to calculate the itemcallnumber (Dewey would be 082ab or 092ab; LOC would be 050ab or 090ab) could be 852hi from an item record','free'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt (-11 / +9 lines)
Lines 258-274 Link Here
258
                        [% END %]
258
                        [% END %]
259
                        <span class="hint">If checked, items will be automatically checked in once they've reached their due date. This feature requires the <code>misc/cronjobs/automatic_checkin.pl</code> cronjob. Ask your system administrator to schedule it.</span>
259
                        <span class="hint">If checked, items will be automatically checked in once they've reached their due date. This feature requires the <code>misc/cronjobs/automatic_checkin.pl</code> cronjob. Ask your system administrator to schedule it.</span>
260
                </li>
260
                </li>
261
                [% IF Koha.Preference('item-level_booking') == 0 %]
261
                <li>
262
                    <li>
262
                    <label for="bookable">Bookable: </label>
263
                        <label for="bookable">Bookable: </label>
263
                        [% IF itemtype.bookable %]
264
                            [% IF itemtype.bookable %]
264
                            <input type="checkbox" id="bookable" name="bookable" checked="checked" value="1" />
265
                                <input type="checkbox" id="bookable" name="bookable" checked="checked" value="1" />
265
                        [% ELSE %]
266
                            [% ELSE %]
266
                            <input type="checkbox" id="bookable" name="bookable" value="1" />
267
                                <input type="checkbox" id="bookable" name="bookable" value="1" />
267
                        [% END %]
268
                            [% END %]
268
                        <span class="hint">If checked, all items of this type will be enabled for future bookings unless overridden at the item level.</span>
269
                            <span class="hint">If checked, all items of this type will be enabled for future bookings.</span>
269
                </li>
270
                    </li>
271
                [% END %]
272
                <li>
270
                <li>
273
                    <label for="rentalcharge">Rental charge: </label>
271
                    <label for="rentalcharge">Rental charge: </label>
274
                    <input type="text" id="rentalcharge" name="rentalcharge" size="10" value="[% itemtype.rentalcharge | $Price on_editing => 1 %]" min="0" />
272
                    <input type="text" id="rentalcharge" name="rentalcharge" size="10" value="[% itemtype.rentalcharge | $Price on_editing => 1 %]" min="0" />
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (-7 lines)
Lines 1082-1094 Circulation: Link Here
1082
                  1: "Do"
1082
                  1: "Do"
1083
                  0: "Don't"
1083
                  0: "Don't"
1084
            - place a hold when ordering from a suggestion.
1084
            - place a hold when ordering from a suggestion.
1085
        -
1086
            - Use the type of the
1087
            - pref: item-level_booking
1088
              choices:
1089
                  1: item
1090
                  0: itemtype
1091
            - level to defined witch items can be bookable in future.
1092
    Patron restrictions:
1085
    Patron restrictions:
1093
        -
1086
        -
1094
            - pref: PatronRestrictionTypes
1087
            - pref: PatronRestrictionTypes
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt (-5 / +12 lines)
Lines 359-379 Link Here
359
                                                    <input type="hidden" name="biblionumber" value="[% ITEM_DAT.biblionumber | html %]" />
359
                                                    <input type="hidden" name="biblionumber" value="[% ITEM_DAT.biblionumber | html %]" />
360
                                                    <input type="hidden" name="biblioitemnumber" value="[% ITEM_DAT.biblioitemnumber | html %]" />
360
                                                    <input type="hidden" name="biblioitemnumber" value="[% ITEM_DAT.biblioitemnumber | html %]" />
361
                                                    <input type="hidden" name="itemnumber" value="[% ITEM_DAT.itemnumber | html %]" />
361
                                                    <input type="hidden" name="itemnumber" value="[% ITEM_DAT.itemnumber | html %]" />
362
                                                    <select name="bookable" [% IF ITEM_DAT.effective_itemtype.bookable == 1 && Koha.Preference('item-level_booking') == 0 %]disabled[% END %]>
362
                                                    <select name="bookable">
363
                                                    [% IF ITEM_DAT.bookable == 1 || ITEM_DAT.effective_itemtype.bookable == 1 %]
363
                                                    [% IF ITEM_DAT.bookable == 1 %]
364
                                                        <option value="">Follow item type</option>
364
                                                        <option value="1" selected="selected">Yes</option>
365
                                                        <option value="1" selected="selected">Yes</option>
365
                                                        <option value="0">No</option>
366
                                                        <option value="0">No</option>
366
                                                        [% ELSE %]
367
                                                    [% ELSIF ITEM_DAT.bookable == 0 %]
368
                                                        <option value="">Follow item type</option>
367
                                                        <option value="1">Yes</option>
369
                                                        <option value="1">Yes</option>
368
                                                        <option value="0" selected="selected">No</option>
370
                                                        <option value="0" selected="selected">No</option>
369
                                                        [% END %]
371
                                                    [% ELSE %]
372
                                                        <option value="" selected="selected">Follow item type</option>
373
                                                        <option value="1">Yes</option>
374
                                                        <option value="0">No</option>
375
                                                    [% END %]
370
                                                    </select>
376
                                                    </select>
371
                                                    <input type="hidden" name="op" value="cud-set_bookable" />
377
                                                    <input type="hidden" name="op" value="cud-set_bookable" />
372
                                                    <input type="submit" name="submit" class="btn btn-primary btn-xs" value="Update" />
378
                                                    <input type="submit" name="submit" class="btn btn-primary btn-xs" value="Update" />
373
                                                </form>
379
                                                </form>
374
                                            [% ELSE %]
380
                                            [% ELSE %]
375
                                                [% IF ITEM_DAT.bookable == 1 %] Yes [% ELSE %] No [% END %]
381
                                                [% IF ITEM_DAT.bookable == 1 %] Yes [% ELSIF ITEM_DAT.bookable == 0 %] No [% ELSE %] Follow item type [% END %]
376
                                            [% END %]
382
                                            [% END %]
383
                                            <span class="hint"> Item type bookable: [% IF ITEM_DAT.effective_itemtype.bookable == 1 %]Yes[% ELSE %]No[% END %]</span>
377
                                        </li>
384
                                        </li>
378
385
379
                                    </ol> <!-- /.bibliodetails -->
386
                                    </ol> <!-- /.bibliodetails -->
(-)a/t/db_dependent/Koha/Items.t (-23 / +18 lines)
Lines 2112-2152 subtest 'filter_by_for_hold' => sub { Link Here
2112
};
2112
};
2113
2113
2114
subtest 'filter_by_bookable' => sub {
2114
subtest 'filter_by_bookable' => sub {
2115
    plan tests => 3;
2115
    plan tests => 4;
2116
2116
2117
    $schema->storage->txn_begin;
2117
    $schema->storage->txn_begin;
2118
2118
2119
    my $biblio = $builder->build_sample_biblio;
2119
    t::lib::Mocks::mock_preference('item-level_itypes', 0);
2120
2121
    my $bookable_item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 1 } } );
2122
    my $non_bookable_item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 0 } } );
2123
    my $biblio = $builder->build_sample_biblio({ itemtype => $bookable_item_type->itemtype });
2120
2124
2121
    # bookable items
2125
    # bookable items
2122
    my $bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 1 } );
2126
    my $bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $bookable_item_type->itemtype, bookable => 1 } );
2123
2127
2124
    # not bookable items
2128
    # not bookable items
2125
    my $non_bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 0 } );
2129
    my $non_bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $non_bookable_item_type->itemtype, bookable => 0 } );
2126
    my $non_bookable_item2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 0 } );
2130
    my $non_bookable_item2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $non_bookable_item_type->itemtype, bookable => 0 } );
2127
2131
2128
    is( $biblio->items->filter_by_bookable->count, 1, "filter_by_bookable returns the correct number of items" );
2132
    is( $biblio->items->filter_by_bookable->count, 1, "filter_by_bookable returns the correct number of items set at item level" );
2129
    is(
2133
    is(
2130
        $biblio->items->filter_by_bookable->next->itemnumber, $bookable_item1->itemnumber,
2134
        $biblio->items->filter_by_bookable->next->itemnumber, $bookable_item1->itemnumber,
2131
        "the correct item is returned from filter_by_bookable"
2135
        "the correct item is returned from filter_by_bookable at the item level"
2132
    );
2136
    );
2133
2137
2134
    # unset level booking on item (for itemtype)
2138
    $bookable_item1->bookable(undef)->store();
2135
    t::lib::Mocks::mock_preference( 'item-level_booking', 0 );
2139
    $non_bookable_item1->bookable(undef)->store();
2136
2140
    $non_bookable_item2->bookable(undef)->store();
2137
    # test with itemtype directly bookable
2141
    $biblio->get_from_storage;
2138
    my $item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 1 } } );
2142
    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" );
2139
    my $biblio2   = $builder->build_sample_biblio( { itemtype => $item_type->itemtype } );
2140
2143
2141
    # bookable items
2144
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
2142
    my $bookable_item3 = $builder->build_sample_item(
2145
    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" );
2143
        { biblionumber => $biblio2->biblionumber, itype => $item_type->itemtype, bookable => 1 } );
2144
    my $bookable_item4 = $builder->build_sample_item(
2145
        { biblionumber => $biblio2->biblionumber, itype => $item_type->itemtype, bookable => 0 } );
2146
2147
    # items are bookable even if bookable => 0 on item (due to itemtype bookable => 1)
2148
    is( $biblio2->items->filter_by_bookable->count, 2, "filter_by_bookable returns the correct number of items" );
2149
2146
2150
    $schema->storage->txn_rollback;
2147
    $schema->storage->txn_rollback;
2151
2152
};
2148
};
2153
- 

Return to bug 35906