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

(-)a/t/db_dependent/Koha/Account.t (-5 / +160 lines)
Lines 24-29 use Test::MockModule; Link Here
24
use Test::Exception;
24
use Test::Exception;
25
25
26
use Koha::Account;
26
use Koha::Account;
27
use Koha::Account::DebitTypes;
27
use Koha::Account::Lines;
28
use Koha::Account::Lines;
28
use Koha::Account::Offsets;
29
use Koha::Account::Offsets;
29
30
Lines 53-59 subtest 'new' => sub { Link Here
53
54
54
subtest 'outstanding_debits() tests' => sub {
55
subtest 'outstanding_debits() tests' => sub {
55
56
56
    plan tests => 22;
57
    plan tests => 23;
57
58
58
    $schema->storage->txn_begin;
59
    $schema->storage->txn_begin;
59
60
Lines 62-70 subtest 'outstanding_debits() tests' => sub { Link Here
62
63
63
    my @generated_lines;
64
    my @generated_lines;
64
    push @generated_lines, $account->add_debit({ amount => 1, interface => 'commandline', type => 'OVERDUE' });
65
    push @generated_lines, $account->add_debit({ amount => 1, interface => 'commandline', type => 'OVERDUE' });
65
    push @generated_lines, $account->add_debit({ amount => 2, interface => 'commandline', type => 'OVERDUE' });
66
    push @generated_lines, $account->add_debit({ amount => 2, interface => 'commandline', type => 'RESERVE' });
66
    push @generated_lines, $account->add_debit({ amount => 3, interface => 'commandline', type => 'OVERDUE' });
67
    push @generated_lines, $account->add_debit({ amount => 3, interface => 'commandline', type => 'RENT' });
67
    push @generated_lines, $account->add_debit({ amount => 4, interface => 'commandline', type => 'OVERDUE' });
68
    Koha::Account::DebitTypes->find_or_create(
69
        {
70
            code        => 'COPY',
71
            description => 'Fee for copie',
72
            is_system   => 0
73
        }
74
    )->store;
75
    push @generated_lines, $account->add_debit({ amount => 4, interface => 'commandline', type => 'COPY' });
68
76
69
    my $lines     = $account->outstanding_debits();
77
    my $lines     = $account->outstanding_debits();
70
    my @lines_arr = $account->outstanding_debits();
78
    my @lines_arr = $account->outstanding_debits();
Lines 142-147 subtest 'outstanding_debits() tests' => sub { Link Here
142
    is( $lines->count, 0, 'No credits are confused with debits because of the amountoutstanding value' );
150
    is( $lines->count, 0, 'No credits are confused with debits because of the amountoutstanding value' );
143
151
144
    $schema->storage->txn_rollback;
152
    $schema->storage->txn_rollback;
153
154
    subtest 'filter_by' => sub {
155
        plan tests => 21;
156
        $schema->storage->txn_begin;
157
158
        my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
159
        my $account = $patron->account;
160
161
        my $due    = 1;
162
        my $res    = 3;
163
        my $rent   = 5;
164
        my $manual = 7;
165
166
        my @generated_lines;
167
        push @generated_lines, $account->add_debit({ amount => $due, interface => 'commandline', type => 'OVERDUE' });
168
        push @generated_lines, $account->add_debit({ amount => $res, interface => 'commandline', type => 'RESERVE' });
169
        push @generated_lines, $account->add_debit({ amount => $rent, interface => 'commandline', type => 'RENT' });
170
        Koha::Account::DebitTypes->find_or_create(
171
            {
172
                code        => 'COPY',
173
                description => 'Fee for copie',
174
                is_system   => 0
175
            }
176
        )->store;
177
        push @generated_lines, $account->add_debit({ amount => $manual, interface => 'commandline', type => 'COPY' });
178
179
        t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge',   0 );
180
        t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 );
181
        t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge',  0 );
182
        my ( $total, $non_issues_charges ) = ( $account->balance, $account->outstanding_debits({filter_by => 'blocks_issue'})->total_outstanding );
183
        my $other_charges = $total - $non_issues_charges;
184
        is(
185
            $account->balance,
186
            $due + $res + $rent + $manual,
187
            'Total charges should be Due + Res + Rent + Manual'
188
        );
189
        is( $non_issues_charges, $due,
190
            'If 0|0|0 there should only have been overdue charges' );
191
        is( $other_charges, 15, 'If 0|0|0 there should only have other charges' );
192
193
        t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge',   0 );
194
        t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 );
195
        t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge',  1 );
196
        ( $total, $non_issues_charges ) = ( $account->balance, $account->outstanding_debits({filter_by => 'blocks_issue'})->total_outstanding );
197
        $other_charges = $total - $non_issues_charges;
198
        is(
199
            $total,
200
            $due + $res + $rent + $manual,
201
            'Total charges should be Res + Rent + Manual'
202
        );
203
        is( $non_issues_charges, $due + $manual,
204
            'If 0|0|1 Only Overdue + Manual should be a non issue charge' );
205
        is(
206
            $other_charges,
207
            $res + $rent,
208
            'If 0|0|1 Res + Rent should be other charges'
209
        );
210
211
        t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge',   0 );
212
        t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 );
213
        t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge',  0 );
214
        ( $total, $non_issues_charges ) = ( $account->balance, $account->outstanding_debits({filter_by => 'blocks_issue'})->total_outstanding );
215
        $other_charges = $total - $non_issues_charges;
216
        is(
217
            $total,
218
            $due + $res + $rent + $manual,
219
            'Total charges should be Res + Rent + Manual'
220
        );
221
        is( $non_issues_charges, $due + $rent,
222
            'If 0|1|0 Only Overdue + Rental should be a non issue charge' );
223
        is(
224
            $other_charges,
225
            $res + $manual,
226
            'If 0|1|0 Rent + Manual should be other charges'
227
        );
228
229
        t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge',   0 );
230
        t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 );
231
        t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge',  1 );
232
        ( $total, $non_issues_charges ) = ( $account->balance, $account->outstanding_debits({filter_by => 'blocks_issue'})->total_outstanding );
233
        $other_charges = $total - $non_issues_charges;
234
        is(
235
            $total,
236
            $due + $res + $rent + $manual,
237
            'Total charges should be Res + Rent + Manual'
238
        );
239
        is(
240
            $non_issues_charges,
241
            $due + $rent + $manual,
242
            'If 0|1|1 Due + Rent + Manual should be non issues charges'
243
        );
244
        is( $other_charges, $res, 'If 0|1|1 there should only have other charges' );
245
246
        t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge',   1 );
247
        t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 );
248
        t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge',  0 );
249
        ( $total, $non_issues_charges ) = ( $account->balance, $account->outstanding_debits({filter_by => 'blocks_issue'})->total_outstanding );
250
        $other_charges = $total - $non_issues_charges;
251
        is(
252
            $total,
253
            $due + $res + $rent + $manual,
254
            'Total charges should be Res + Rent + Manual'
255
        );
256
        is( $non_issues_charges, $due + $res,
257
            'If 1|0|0 Only Overdue + Res should be non issues charges' );
258
        is(
259
            $other_charges,
260
            $rent + $manual,
261
            'If 1|0|0 Rent + Manual should be other charges'
262
        );
263
264
        t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge',   1 );
265
        t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 );
266
        t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge',  0 );
267
        ( $total, $non_issues_charges ) = ( $account->balance, $account->outstanding_debits({filter_by => 'blocks_issue'})->total_outstanding );
268
        $other_charges = $total - $non_issues_charges;
269
        is(
270
            $total,
271
            $due + $res + $rent + $manual,
272
            'Total charges should be Res + Rent + Manual'
273
        );
274
        is(
275
            $non_issues_charges,
276
            $due + $res + $rent,
277
            'If 1|1|0 Overdue + Res + Rent should be non issues charges'
278
        );
279
        is( $other_charges, $manual,
280
            'If 1|1|0 Only Manual should be other charges' );
281
282
        t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge',   1 );
283
        t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 );
284
        t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge',  1 );
285
        ( $total, $non_issues_charges ) = ( $account->balance, $account->outstanding_debits({filter_by => 'blocks_issue'})->total_outstanding );
286
        $other_charges = $total - $non_issues_charges;
287
        is(
288
            $total,
289
            $due + $res + $rent + $manual,
290
            'Total charges should be Res + Rent + Manual'
291
        );
292
        is(
293
            $non_issues_charges,
294
            $due + $res + $rent + $manual,
295
            'If 1|1|1 Res + Rent + Manual should be non issues charges'
296
        );
297
        is( $other_charges, 0, 'If 1|1|1 there should not have any other charges' );
298
299
        $schema->storage->txn_rollback;
300
    }
145
};
301
};
146
302
147
subtest 'outstanding_credits() tests' => sub {
303
subtest 'outstanding_credits() tests' => sub {
148
- 

Return to bug 23596