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

(-)a/Koha/SearchEngine/Elasticsearch.pm (-2 / +6 lines)
Lines 952-962 sub marc_records_to_documents { Link Here
952
            my ( $tag, $code ) = C4::Biblio::GetMarcFromKohaField('biblio.biblionumber');
952
            my ( $tag, $code ) = C4::Biblio::GetMarcFromKohaField('biblio.biblionumber');
953
            my $field = $record->field($tag);
953
            my $field = $record->field($tag);
954
            if ($field) {
954
            if ($field) {
955
                my $biblionumber = $field->is_control_field ? $field->data : $field->subfield($code);
955
                my $biblionumber           = $field->is_control_field ? $field->data : $field->subfield($code);
956
                my $avail_items  = Koha::Items->search(
956
                my $unavailable_notforloan = [ split ',', C4::Context->preference('UnavailableNotForLoan') ];
957
                my $unavailable_withdrawn  = [ split ',', C4::Context->preference('UnavailableWithDrawn') ];
958
                my $avail_items            = Koha::Items->search(
957
                    {
959
                    {
958
                        biblionumber => $biblionumber,
960
                        biblionumber => $biblionumber,
959
                        onloan       => undef,
961
                        onloan       => undef,
962
                        notforloan   => { 'not in' => $unavailable_notforloan },
963
                        withdrawn    => { 'not in' => $unavailable_withdrawn },
960
                        itemlost     => 0,
964
                        itemlost     => 0,
961
                    }
965
                    }
962
                )->count;
966
                )->count;
(-)a/installer/data/mysql/atomicupdate/bug_37680.pl (+31 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_success say_info);
3
4
return {
5
    bug_number  => "37680",
6
    description => "Adds new system preferences 'UnavailableNotForLoan' and 'UnavailableWithDrawn'",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        # Do you stuffs here
12
        $dbh->do(
13
            q{
14
            INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
15
            ('UnavailableNotForLoan', '', NULL,'Choose which notforloan values should be considered as NOT available.', 'Choice')
16
            }
17
        );
18
19
        # Do you stuffs here
20
        $dbh->do(
21
            q{
22
            INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
23
            ('UnavailableWithDrawn', '', NULL,'Choose which withdrawn values should be considered as NOT available.', 'Choice')
24
            }
25
        );
26
27
        # sysprefs
28
        say $out "Added new system preference 'UnavailableNotForLoan'";
29
        say $out "Added new system preference 'UnavailableWithDrawn'";
30
    },
31
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+2 lines)
Lines 831-836 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
831
('TranslateNotices','0',NULL, 'Allow notices to be translated','YesNo'),
831
('TranslateNotices','0',NULL, 'Allow notices to be translated','YesNo'),
832
('TrapHoldsOnOrder','1',NULL,'If enabled, Koha will trap holds for on order items ( notforloan < 0 )','YesNo'),
832
('TrapHoldsOnOrder','1',NULL,'If enabled, Koha will trap holds for on order items ( notforloan < 0 )','YesNo'),
833
('TwoFactorAuthentication', 'disabled', 'enforced|enabled|disabled', 'Enables two-factor authentication', 'Choice'),
833
('TwoFactorAuthentication', 'disabled', 'enforced|enabled|disabled', 'Enables two-factor authentication', 'Choice'),
834
('UnavailableNotForLoan', '', NULL, 'Choose which notforloan values should be considered as NOT available.','Choice'),
835
('UnavailableWithDrawn', '', NULL, 'Choose which withdrawn values should be considered as NOT available.','Choice'),
834
('UNIMARCAuthorityField100','afrey50      ba0',NULL,'Define the contents of UNIMARC authority control field 100 position 08-35','Textarea'),
836
('UNIMARCAuthorityField100','afrey50      ba0',NULL,'Define the contents of UNIMARC authority control field 100 position 08-35','Textarea'),
835
('UNIMARCAuthorsFacetsSeparator',', ',NULL,'UNIMARC authors facets separator','short'),
837
('UNIMARCAuthorsFacetsSeparator',', ',NULL,'UNIMARC authors facets separator','short'),
836
('UNIMARCField100Language','fre',NULL,'UNIMARC field 100 default language','short'),
838
('UNIMARCField100Language','fre',NULL,'UNIMARC field 100 default language','short'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (+15 lines)
Lines 359-364 Cataloging: Link Here
359
                  dsc: descending.
359
                  dsc: descending.
360
                  az: from A to Z.
360
                  az: from A to Z.
361
                  za: from Z to A.
361
                  za: from Z to A.
362
        -
363
            - pref: UnavailableNotForLoan
364
              choices: authval
365
              source: NOT_LOAN
366
              class: multiple
367
            - Should be considered as not available.
368
            - Rebuild the bibliographic index after making changes.
369
        -
370
            - pref: UnavailableWithDrawn
371
              choices: authval
372
              source: WITHDRAWN
373
              class: multiple
374
            - Should be considered as not available.
375
            - Rebuild the bibliographic index after making changes.
376
362
    Importing:
377
    Importing:
363
        -
378
        -
364
            - When matching on ISBN with the record import tool,
379
            - When matching on ISBN with the record import tool,
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t (-3 / +65 lines)
Lines 1216-1224 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents with Inclu Link Here
1216
};
1216
};
1217
1217
1218
subtest 'marc_records_to_documents should set the "available" field' => sub {
1218
subtest 'marc_records_to_documents should set the "available" field' => sub {
1219
    plan tests => 8;
1219
    plan tests => 14;
1220
1220
1221
    t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
1221
    t::lib::Mocks::mock_preference( 'marcflavour',           'MARC21' );
1222
    t::lib::Mocks::mock_preference( 'UnavailableNotForLoan', undef );
1222
    my $dbh = C4::Context->dbh;
1223
    my $dbh = C4::Context->dbh;
1223
1224
1224
    my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch');
1225
    my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch');
Lines 1276-1281 subtest 'marc_records_to_documents should set the "available" field' => sub { Link Here
1276
        $docs->[0]->{available}, \1,
1277
        $docs->[0]->{available}, \1,
1277
        'a biblio with at least one item that has no particular status is available'
1278
        'a biblio with at least one item that has no particular status is available'
1278
    );
1279
    );
1280
1281
    t::lib::Mocks::mock_preference( 'UnavailableNotForLoan', join( ',', '-1', '1' ) );
1282
    $biblio        = $builder->build_sample_biblio;
1283
    $marc_record_1 = $biblio->metadata->record;
1284
1285
    $item = $builder->build_sample_item(
1286
        {
1287
            biblionumber => $biblio->biblionumber,
1288
        }
1289
    );
1290
1291
    $item->notforloan(-1)->store();
1292
    $docs = $see->marc_records_to_documents( [$marc_record_1] );
1293
    is_deeply(
1294
        $docs->[0]->{available}, \0,
1295
        'A biblio with one item whose notforloan value is selected in UnavailableNotForLoan should be considered not available'
1296
    );
1297
1298
    $item->set( { notforloan => 1 } )->store();
1299
    $docs = $see->marc_records_to_documents( [$marc_record_1] );
1300
    is_deeply(
1301
        $docs->[0]->{available}, \0,
1302
        'A biblio with one item whose notforloan value is selected in UnavailableNotForLoan should be considered not available'
1303
    );
1304
1305
    $item->set( { notforloan => 2 } )->store();
1306
    $docs = $see->marc_records_to_documents( [$marc_record_1] );
1307
    is_deeply(
1308
        $docs->[0]->{available}, \1,
1309
        'A biblio with one item whose notforloan value is not selected in UnavailableNotForLoan should be considered available'
1310
    );
1311
1312
    t::lib::Mocks::mock_preference( 'UnavailableWithDrawn', join( ',', '-1', '1' ) );
1313
    $biblio        = $builder->build_sample_biblio;
1314
    $marc_record_1 = $biblio->metadata->record;
1315
1316
    $item = $builder->build_sample_item(
1317
        {
1318
            biblionumber => $biblio->biblionumber,
1319
        }
1320
    );
1321
1322
    $item->withdrawn(-1)->store();
1323
    $docs = $see->marc_records_to_documents( [$marc_record_1] );
1324
    is_deeply(
1325
        $docs->[0]->{available}, \0,
1326
        'A biblio with one item whose withdrawn value is selected in UnavailableWithDrawn should be considered not available'
1327
    );
1328
1329
    $item->set( { withdrawn => 1 } )->store();
1330
    $docs = $see->marc_records_to_documents( [$marc_record_1] );
1331
    is_deeply(
1332
        $docs->[0]->{available}, \0,
1333
        'A biblio with one item whose withdrawn value is selected in UnavailableWithDrawn should be considered not available'
1334
    );
1335
1336
    $item->set( { withdrawn => 2 } )->store();
1337
    $docs = $see->marc_records_to_documents( [$marc_record_1] );
1338
    is_deeply(
1339
        $docs->[0]->{available}, \1,
1340
        'A biblio with one item whose withdrawn value is not selected in UnavailableWithDrawn should be considered available'
1341
    );
1279
};
1342
};
1280
1343
1281
$schema->storage->txn_rollback;
1344
$schema->storage->txn_rollback;
1282
- 

Return to bug 37680