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

(-)a/t/db_dependent/Circulation/Returns.t (+87 lines)
Lines 420-423 subtest 'Backdated returns should reduce fine if needed' => sub { Link Here
420
    is( $fine, undef, "Fine was removed correctly with a backdated return" );
420
    is( $fine, undef, "Fine was removed correctly with a backdated return" );
421
};
421
};
422
422
423
subtest 'Test library float limits' => sub {
424
    plan tests => 2;
425
426
    my $library1 = $builder->build( { source => 'Branch' } );
427
    my $library2 = $builder->build( { source => 'Branch' } );
428
    my $library3 = $builder->build( { source => 'Branch' } );
429
    my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes' } );
430
431
    my $biblio = $builder->build_sample_biblio();
432
433
    for ( 1 .. 5 ) {
434
        $builder->build_sample_item(
435
            {
436
                biblionumber  => $biblio->biblionumber,
437
                homebranch    => $library1->{branchcode},
438
                holdingbranch => $library1->{branchcode},
439
                itype         => $itemtype->itemtype,
440
            }
441
        );
442
    }
443
444
    for ( 1 .. 10 ) {
445
        $builder->build_sample_item(
446
            {
447
                biblionumber  => $biblio->biblionumber,
448
                homebranch    => $library2->{branchcode},
449
                holdingbranch => $library2->{branchcode},
450
                itype         => $itemtype->itemtype,
451
            }
452
        );
453
    }
454
455
    for ( 1 .. 15 ) {
456
        $builder->build_sample_item(
457
            {
458
                biblionumber  => $biblio->biblionumber,
459
                homebranch    => $library3->{branchcode},
460
                holdingbranch => $library3->{branchcode},
461
                itype         => $itemtype->itemtype,
462
            }
463
        );
464
    }
465
466
    my $item = $builder->build_sample_item(
467
        {
468
            biblionumber  => $biblio->biblionumber,
469
            homebranch    => $library1->{branchcode},
470
            holdingbranch => $library1->{branchcode},
471
            itype         => $itemtype->itemtype,
472
        }
473
    );
474
475
    my $limit1 = Koha::Library::FloatLimit->new(
476
        {
477
            branchcode  => $library1->{branchcode},
478
            itemtype    => $itemtype->itemtype,
479
            float_limit => 1,
480
        }
481
    )->store();
482
483
    my $limit2 = Koha::Library::FloatLimit->new(
484
        {
485
            branchcode  => $library2->{branchcode},
486
            itemtype    => $itemtype->itemtype,
487
            float_limit => 100,
488
        }
489
    )->store();
490
491
    my $limit3 = Koha::Library::FloatLimit->new(
492
        {
493
            branchcode  => $library3->{branchcode},
494
            itemtype    => $itemtype->itemtype,
495
            float_limit => 1000,
496
        }
497
    )->store();
498
499
    t::lib::Mocks::mock_preference( 'UseLibraryFloatLimits', '0' );
500
501
    my ( $doreturn, $messages, $iteminformation, $borrower ) = AddReturn( $item->barcode, $item->holdingbranch );
502
    is( $messages->{TransferTrigger}, undef, "Library float limit not triggered if syspref is not enabled" );
503
504
    t::lib::Mocks::mock_preference( 'UseLibraryFloatLimits', '1' );
505
506
    ( $doreturn, $messages, $iteminformation, $borrower ) = AddReturn( $item->barcode, $item->holdingbranch );
507
    is( $messages->{TransferTrigger}, 'LibraryFloatLimit', "Library float limit is triggered if syspref is enabled" );
508
};
509
423
$schema->storage->txn_rollback;
510
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Library/FloatLimits.t (-1 / +133 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2023 ByWater Solutions
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 5;
23
24
use Koha::Database;
25
use C4::Circulation qw(CreateBranchTransferLimit);
26
27
use t::lib::Mocks;
28
use t::lib::TestBuilder;
29
30
BEGIN {
31
    use_ok('Koha::Library::FloatLimit');
32
    use_ok('Koha::Library::FloatLimits');
33
}
34
35
my $schema = Koha::Database->new->schema;
36
$schema->storage->txn_begin;
37
38
my $builder  = t::lib::TestBuilder->new;
39
my $library1 = $builder->build( { source => 'Branch' } );
40
my $library2 = $builder->build( { source => 'Branch' } );
41
my $library3 = $builder->build( { source => 'Branch' } );
42
my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes' } );
43
44
my $biblio = $builder->build_sample_biblio();
45
46
for ( 1 .. 5 ) {
47
    $builder->build_sample_item(
48
        {
49
            biblionumber  => $biblio->biblionumber,
50
            homebranch    => $library1->{branchcode},
51
            holdingbranch => $library1->{branchcode},
52
            itype         => $itemtype->itemtype,
53
        }
54
    );
55
}
56
57
for ( 1 .. 10 ) {
58
    $builder->build_sample_item(
59
        {
60
            biblionumber  => $biblio->biblionumber,
61
            homebranch    => $library2->{branchcode},
62
            holdingbranch => $library2->{branchcode},
63
            itype         => $itemtype->itemtype,
64
        }
65
    );
66
}
67
68
for ( 1 .. 15 ) {
69
    $builder->build_sample_item(
70
        {
71
            biblionumber  => $biblio->biblionumber,
72
            homebranch    => $library3->{branchcode},
73
            holdingbranch => $library3->{branchcode},
74
            itype         => $itemtype->itemtype,
75
        }
76
    );
77
}
78
79
my $item = $builder->build_sample_item(
80
    {
81
        biblionumber  => $biblio->biblionumber,
82
        homebranch    => $library1->{branchcode},
83
        holdingbranch => $library1->{branchcode},
84
        itype         => $itemtype->itemtype,
85
    }
86
);
87
88
my $limit1 = Koha::Library::FloatLimit->new(
89
    {
90
        branchcode  => $library1->{branchcode},
91
        itemtype    => $itemtype->itemtype,
92
        float_limit => 1,
93
    }
94
)->store();
95
96
my $float_limit2 = Koha::Library::FloatLimit->new(
97
    {
98
        branchcode  => $library2->{branchcode},
99
        itemtype    => $itemtype->itemtype,
100
        float_limit => 100,
101
    }
102
)->store();
103
104
my $float_limit3 = Koha::Library::FloatLimit->new(
105
    {
106
        branchcode  => $library3->{branchcode},
107
        itemtype    => $itemtype->itemtype,
108
        float_limit => 1000,
109
    }
110
)->store();
111
112
is(
113
    Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} ), $library3->{branchcode},
114
    "Correct library selected for float limit transfer"
115
);
116
117
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  '1' );
118
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
119
120
my $to   = $library3->{branchcode};
121
my $from = $item->holdingbranch;
122
my $code = $itemtype->itemtype;
123
CreateBranchTransferLimit( $to, $from, $code );
124
125
is( C4::Circulation::IsBranchTransferAllowed( $to, $from, $code ), 0, "Transfer to best library is no longer allowed" );
126
say "C4::Circulation::IsBranchTransferAllowed( $to, $from, $code )";
127
128
is(
129
    Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} ), $library2->{branchcode},
130
    "Correct library selected for float limit transfer when best cannot be used"
131
);
132
133
$schema->storage->txn_rollback;

Return to bug 28530