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

(-)a/t/db_dependent/Koha/Account/Lines.t (-2 / +228 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 1;
22
use Test::More tests => 4;
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use Koha::Account;
25
use Koha::Account;
Lines 108-112 subtest 'total_outstanding() tests' => sub { Link Here
108
    $schema->storage->txn_rollback;
108
    $schema->storage->txn_rollback;
109
};
109
};
110
110
111
subtest 'total() tests' => sub {
112
113
    plan tests => 5;
114
115
    $schema->storage->txn_begin;
116
117
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
118
119
    my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
120
    is( $lines->total, 0, 'total returns 0 if no lines (undef case)' );
121
122
    my $debit_1 = Koha::Account::Line->new(
123
        {   borrowernumber    => $patron->id,
124
            accounttype       => "OVERDUE",
125
            status            => "RETURNED",
126
            amount            => 10,
127
            amountoutstanding => 10,
128
            interface         => 'commandline',
129
        }
130
    )->store;
131
132
    my $debit_2 = Koha::Account::Line->new(
133
        {   borrowernumber    => $patron->id,
134
            accounttype       => "OVERDUE",
135
            status            => "RETURNED",
136
            amount            => 10,
137
            amountoutstanding => 10,
138
            interface         => 'commandline',
139
        }
140
    )->store;
141
142
    $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
143
    is( $lines->total, 20, 'total sums correctly' );
144
145
    my $credit_1 = Koha::Account::Line->new(
146
        {   borrowernumber    => $patron->id,
147
            accounttype       => "OVERDUE",
148
            status            => "RETURNED",
149
            amount            => -10,
150
            amountoutstanding => -10,
151
            interface         => 'commandline',
152
        }
153
    )->store;
154
155
    $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
156
    is( $lines->total, 10, 'total sums correctly' );
157
158
    my $credit_2 = Koha::Account::Line->new(
159
        {   borrowernumber    => $patron->id,
160
            accounttype       => "OVERDUE",
161
            status            => "RETURNED",
162
            amount            => -10,
163
            amountoutstanding => -10,
164
            interface         => 'commandline',
165
        }
166
    )->store;
167
168
    $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
169
    is( $lines->total, 0, 'total sums correctly' );
170
171
    my $credit_3 = Koha::Account::Line->new(
172
        {   borrowernumber    => $patron->id,
173
            accounttype       => "OVERDUE",
174
            status            => "RETURNED",
175
            amount            => -100,
176
            amountoutstanding => -100,
177
            interface         => 'commandline',
178
        }
179
    )->store;
180
181
    $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
182
    is( $lines->total, -100, 'total sums correctly' );
183
184
    $schema->storage->txn_rollback;
185
};
186
187
subtest 'credits_total() tests' => sub {
188
189
    plan tests => 5;
190
191
    $schema->storage->txn_begin;
192
193
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
194
195
    my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
196
    is( $lines->credits_total, 0, 'credits_total returns 0 if no lines (undef case)' );
197
198
    my $debit_1 = Koha::Account::Line->new(
199
        {   borrowernumber    => $patron->id,
200
            accounttype       => "OVERDUE",
201
            status            => "RETURNED",
202
            amount            => 10,
203
            amountoutstanding => 10,
204
            interface         => 'commandline',
205
        }
206
    )->store;
207
208
    my $debit_2 = Koha::Account::Line->new(
209
        {   borrowernumber    => $patron->id,
210
            accounttype       => "OVERDUE",
211
            status            => "RETURNED",
212
            amount            => 10,
213
            amountoutstanding => 10,
214
            interface         => 'commandline',
215
        }
216
    )->store;
217
218
    $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
219
    is( $lines->credits_total, 0, 'credits_total sums correctly' );
220
221
    my $credit_1 = Koha::Account::Line->new(
222
        {   borrowernumber    => $patron->id,
223
            accounttype       => "OVERDUE",
224
            status            => "RETURNED",
225
            amount            => -10,
226
            amountoutstanding => -10,
227
            interface         => 'commandline',
228
        }
229
    )->store;
230
231
    $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
232
    is( $lines->credits_total, -10, 'credits_total sums correctly' );
233
234
    my $credit_2 = Koha::Account::Line->new(
235
        {   borrowernumber    => $patron->id,
236
            accounttype       => "OVERDUE",
237
            status            => "RETURNED",
238
            amount            => -10,
239
            amountoutstanding => -10,
240
            interface         => 'commandline',
241
        }
242
    )->store;
243
244
    $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
245
    is( $lines->credits_total, -20, 'credits_total sums correctly' );
246
247
    my $credit_3 = Koha::Account::Line->new(
248
        {   borrowernumber    => $patron->id,
249
            accounttype       => "OVERDUE",
250
            status            => "RETURNED",
251
            amount            => -100,
252
            amountoutstanding => -100,
253
            interface         => 'commandline',
254
        }
255
    )->store;
256
257
    $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
258
    is( $lines->credits_total, -120, 'credits_total sums correctly' );
259
260
    $schema->storage->txn_rollback;
261
};
262
263
subtest 'debits_total() tests' => sub {
264
265
    plan tests => 5;
266
267
    $schema->storage->txn_begin;
268
269
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
270
271
    my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
272
    is( $lines->debits_total, 0, 'debits_total returns 0 if no lines (undef case)' );
273
274
    my $debit_1 = Koha::Account::Line->new(
275
        {   borrowernumber    => $patron->id,
276
            accounttype       => "OVERDUE",
277
            status            => "RETURNED",
278
            amount            => 10,
279
            amountoutstanding => 0,
280
            interface         => 'commandline',
281
        }
282
    )->store;
283
284
    my $debit_2 = Koha::Account::Line->new(
285
        {   borrowernumber    => $patron->id,
286
            accounttype       => "OVERDUE",
287
            status            => "RETURNED",
288
            amount            => 10,
289
            amountoutstanding => 0,
290
            interface         => 'commandline',
291
        }
292
    )->store;
293
294
    $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
295
    is( $lines->debits_total, 20, 'debits_total sums correctly' );
296
297
    my $credit_1 = Koha::Account::Line->new(
298
        {   borrowernumber    => $patron->id,
299
            accounttype       => "OVERDUE",
300
            status            => "RETURNED",
301
            amount            => -10,
302
            amountoutstanding => 0,
303
            interface         => 'commandline',
304
        }
305
    )->store;
306
307
    $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
308
    is( $lines->debits_total, 20, 'debits_total sums correctly' );
309
310
    my $credit_2 = Koha::Account::Line->new(
311
        {   borrowernumber    => $patron->id,
312
            accounttype       => "OVERDUE",
313
            status            => "RETURNED",
314
            amount            => -10,
315
            amountoutstanding => 0,
316
            interface         => 'commandline',
317
        }
318
    )->store;
319
320
    $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
321
    is( $lines->debits_total, 20, 'debits_total sums correctly' );
322
323
    my $credit_3 = Koha::Account::Line->new(
324
        {   borrowernumber    => $patron->id,
325
            accounttype       => "OVERDUE",
326
            status            => "RETURNED",
327
            amount            => -100,
328
            amountoutstanding => 0,
329
            interface         => 'commandline',
330
        }
331
    )->store;
332
333
    $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
334
    is( $lines->debits_total, 20, 'debits_total sums correctly' );
335
336
    $schema->storage->txn_rollback;
337
};
111
338
112
1;
339
1;
113
- 

Return to bug 23355