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

(-)a/C4/Reserves.pm (-2 / +9 lines)
Lines 220-227 sub AddReserve { Link Here
220
    my $reserve_id = $hold->id();
220
    my $reserve_id = $hold->id();
221
221
222
    # add a reserve fee if needed
222
    # add a reserve fee if needed
223
    my $fee = GetReserveFee( $borrowernumber, $biblionumber );
223
    if ( C4::Context->preference('HoldFeeMode') ne 'any_time_is_collected' ) {
224
    ChargeReserveFee( $borrowernumber, $fee, $title );
224
        my $reserve_fee = GetReserveFee( $borrowernumber, $biblionumber );
225
        ChargeReserveFee( $borrowernumber, $reserve_fee, $title );
226
    }
225
227
226
    _FixPriority({ biblionumber => $biblionumber});
228
    _FixPriority({ biblionumber => $biblionumber});
227
229
Lines 1248-1253 sub ModReserveFill { Link Here
1248
1250
1249
    $hold->delete();
1251
    $hold->delete();
1250
1252
1253
    if ( C4::Context->preference('HoldFeeMode') eq 'any_time_is_collected' ) {
1254
        my $reserve_fee = GetReserveFee( $hold->borrowernumber );
1255
        ChargeReserveFee( $hold->borrowernumber, $reserve_fee, $hold->biblio->title );
1256
    }
1257
1251
    # now fix the priority on the others (if the priority wasn't
1258
    # now fix the priority on the others (if the priority wasn't
1252
    # already sorted!)....
1259
    # already sorted!)....
1253
    unless ( $priority == 0 ) {
1260
    unless ( $priority == 0 ) {
(-)a/t/db_dependent/Reserves/GetReserveFee.t (-20 / +87 lines)
Lines 21-27 Link Here
21
21
22
use Modern::Perl;
22
use Modern::Perl;
23
23
24
use Test::More tests => 2;
24
use Test::More tests => 3;
25
use Test::MockModule;
25
use Test::MockModule;
26
use t::lib::TestBuilder;
26
use t::lib::TestBuilder;
27
use t::lib::Mocks;
27
use t::lib::Mocks;
Lines 64-69 my $patron2 = $builder->build({ Link Here
64
        categorycode => 'XYZ1',
64
        categorycode => 'XYZ1',
65
    },
65
    },
66
});
66
});
67
my $patron3 = $builder->build({
68
    source => 'Borrower',
69
});
67
70
68
# One biblio and two items
71
# One biblio and two items
69
my $biblio = $builder->build({
72
my $biblio = $builder->build({
Lines 76-105 my $item1 = $builder->build({ Link Here
76
    source => 'Item',
79
    source => 'Item',
77
    value  => {
80
    value  => {
78
        biblionumber => $biblio->{biblionumber},
81
        biblionumber => $biblio->{biblionumber},
82
        notforloan => 0,
79
    },
83
    },
80
});
84
});
81
my $item2 = $builder->build({
85
my $item2 = $builder->build({
82
    source => 'Item',
86
    source => 'Item',
83
    value  => {
87
    value  => {
84
        biblionumber => $biblio->{biblionumber},
88
        biblionumber => $biblio->{biblionumber},
89
        notforloan => 0,
85
    },
90
    },
86
});
91
});
87
92
88
89
# Actual testing starts here!
90
# Add reserve for patron1, no fee expected
91
# Note: AddReserve calls GetReserveFee and ChargeReserveFee
92
my $acc1 = acctlines( $patron1->{borrowernumber} );
93
my $res1 = addreserve( $patron1->{borrowernumber} );
94
is( acctlines( $patron1->{borrowernumber} ), $acc1, 'No fee charged for patron 1' );
95
96
subtest 'GetReserveFee' => sub {
93
subtest 'GetReserveFee' => sub {
97
    plan tests => 7;
94
    plan tests => 5;
98
95
99
    # Issue item1 to patron1. Since there is still a reserve too, we should
100
    # expect a charge for patron2.
101
    C4::Circulation::AddIssue( $patron1, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} ); # the date does not really matter
96
    C4::Circulation::AddIssue( $patron1, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} ); # the date does not really matter
102
    my $acc2 = acctlines( $patron2->{borrowernumber} );
97
    my $acc2 = acctlines( $patron2->{borrowernumber} );
98
    my $res1 = addreserve( $patron1->{borrowernumber} );
103
99
104
    t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
100
    t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
105
    my $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
101
    my $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
Lines 108-114 subtest 'GetReserveFee' => sub { Link Here
108
    is( acctlines( $patron2->{borrowernumber} ), $acc2 + 1, 'Patron 2 has been charged by ChargeReserveFee' );
104
    is( acctlines( $patron2->{borrowernumber} ), $acc2 + 1, 'Patron 2 has been charged by ChargeReserveFee' );
109
105
110
    # If we delete the reserve, there should be no charge
106
    # If we delete the reserve, there should be no charge
111
    $dbh->do( "DELETE FROM reserves WHERE reserve_id=?", undef, ( $res1 ) );
107
    $dbh->do( "DELETE FROM reserves WHERE borrowernumber = ?", undef, ( $patron1->{borrowernumber}) );
112
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
108
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
113
    is( $fee, 0, 'HoldFeeMode=not_always, Patron 2 should not be charged' );
109
    is( $fee, 0, 'HoldFeeMode=not_always, Patron 2 should not be charged' );
114
110
Lines 119-134 subtest 'GetReserveFee' => sub { Link Here
119
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
115
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
120
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
116
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
121
    is( int($fee), 2, 'HoldFeeMode=any_time_is_collected, Patron 2 should be charged' );
117
    is( int($fee), 2, 'HoldFeeMode=any_time_is_collected, Patron 2 should be charged' );
118
};
119
120
subtest 'Integration with AddReserve' => sub {
121
    plan tests => 2;
122
123
    my $dbh = C4::Context->dbh;
124
125
    subtest 'Items are not issued' => sub {
126
        plan tests => 3;
127
128
        t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
129
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->{biblionumber} );
130
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
131
        addreserve( $patron1->{borrowernumber} );
132
        is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - No fee charged for patron 1 if not issued' );
133
134
        t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
135
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->{biblionumber} );
136
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
137
        addreserve( $patron1->{borrowernumber} );
138
        is( acctlines( $patron1->{borrowernumber} ), 1, 'any_time_is_placed - Patron should be always charged' );
139
140
        t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
141
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->{biblionumber} );
142
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
143
        addreserve( $patron1->{borrowernumber} );
144
        is( acctlines( $patron1->{borrowernumber} ), 0, 'any_time_is_collected - Patron should not be charged when placing a hold' );
145
    };
146
147
    subtest 'Items are issued' => sub {
148
        plan tests => 3;
149
150
        C4::Circulation::AddIssue( $patron2, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} );
151
152
        t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
153
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->{biblionumber} );
154
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
155
        addreserve( $patron1->{borrowernumber} );
156
        is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged if items are not all checked out' );
157
158
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->{biblionumber} );
159
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
160
        addreserve( $patron3->{borrowernumber} );
161
        addreserve( $patron1->{borrowernumber} );
162
        # FIXME Are we sure it's the expected behavior?
163
        is( acctlines( $patron1->{borrowernumber} ), 1, 'not_always - Patron should be charged if all the items are not checked out and at least 1 hold is already placed' );
164
165
        C4::Circulation::AddIssue( $patron3, $item2->{barcode}, '2015-12-31', 0, undef, 0, {} );
166
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->{biblionumber} );
167
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
168
        addreserve( $patron1->{borrowernumber} );
169
        is( acctlines( $patron1->{borrowernumber} ), 1, 'not_always - Patron should be charged if all items are checked out' );
170
    };
171
};
172
173
subtest 'Integration with AddIssue' => sub {
174
    plan tests => 5;
175
176
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->{borrowernumber} );
177
    $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->{biblionumber} );
178
    $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
179
180
    t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
181
    C4::Circulation::AddIssue( $patron1, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} );
182
    is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged' );
122
183
123
    # If we delete the second item, there should be a charge
124
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
184
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
125
    $dbh->do( "DELETE FROM items WHERE itemnumber=?", undef, ( $item2->{itemnumber} ) );
185
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->{borrowernumber} );
126
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
186
    C4::Circulation::AddIssue( $patron1, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} );
127
    is( int($fee), 2, 'Patron 2 should be charged again this time' );
187
    is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged' );
128
188
129
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
189
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
130
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
190
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->{borrowernumber} );
131
    is( int($fee), 2, 'HoldFeeMode=any_time_is_collected, Patron 2 should be charged' );
191
    C4::Circulation::AddIssue( $patron1, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} );
192
    is( acctlines( $patron1->{borrowernumber} ), 0, 'any_time_is_collected - Patron should not be charged when checking out an item which was not placed hold for him' );
193
194
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->{borrowernumber} );
195
    my $id = addreserve( $patron1->{borrowernumber} );
196
    my $r = C4::Reserves::GetReserveInfo($id);
197
    is( acctlines( $patron1->{borrowernumber} ), 0, 'any_time_is_collected - Patron should not be charged yet (just checking to make sure)');
198
    C4::Circulation::AddIssue( $patron1, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} );
199
    is( acctlines( $patron1->{borrowernumber} ), 1, 'any_time_is_collected - Patron should not be charged when checking out an item which was not placed hold for him' );
132
};
200
};
133
201
134
sub acctlines { #calculate number of accountlines for a patron
202
sub acctlines { #calculate number of accountlines for a patron
135
- 

Return to bug 17560