Lines 57-63
subtest 'item() tests' => sub {
Link Here
|
57 |
{ |
57 |
{ |
58 |
borrowernumber => $patron->{borrowernumber}, |
58 |
borrowernumber => $patron->{borrowernumber}, |
59 |
itemnumber => $item->itemnumber, |
59 |
itemnumber => $item->itemnumber, |
60 |
accounttype => "F", |
60 |
accounttype => "OVERDUE", |
|
|
61 |
status => "RETURNED", |
61 |
amount => 10, |
62 |
amount => 10, |
62 |
})->store; |
63 |
})->store; |
63 |
|
64 |
|
Lines 84-90
subtest 'total_outstanding() tests' => sub {
Link Here
|
84 |
|
85 |
|
85 |
my $debit_1 = Koha::Account::Line->new( |
86 |
my $debit_1 = Koha::Account::Line->new( |
86 |
{ borrowernumber => $patron->id, |
87 |
{ borrowernumber => $patron->id, |
87 |
accounttype => "F", |
88 |
accounttype => "OVERDUE", |
|
|
89 |
status => "RETURNED", |
88 |
amount => 10, |
90 |
amount => 10, |
89 |
amountoutstanding => 10 |
91 |
amountoutstanding => 10 |
90 |
} |
92 |
} |
Lines 92-98
subtest 'total_outstanding() tests' => sub {
Link Here
|
92 |
|
94 |
|
93 |
my $debit_2 = Koha::Account::Line->new( |
95 |
my $debit_2 = Koha::Account::Line->new( |
94 |
{ borrowernumber => $patron->id, |
96 |
{ borrowernumber => $patron->id, |
95 |
accounttype => "F", |
97 |
accounttype => "OVERDUE", |
|
|
98 |
status => "RETURNED", |
96 |
amount => 10, |
99 |
amount => 10, |
97 |
amountoutstanding => 10 |
100 |
amountoutstanding => 10 |
98 |
} |
101 |
} |
Lines 103-109
subtest 'total_outstanding() tests' => sub {
Link Here
|
103 |
|
106 |
|
104 |
my $credit_1 = Koha::Account::Line->new( |
107 |
my $credit_1 = Koha::Account::Line->new( |
105 |
{ borrowernumber => $patron->id, |
108 |
{ borrowernumber => $patron->id, |
106 |
accounttype => "F", |
109 |
accounttype => "OVERDUE", |
|
|
110 |
status => "RETURNED", |
107 |
amount => -10, |
111 |
amount => -10, |
108 |
amountoutstanding => -10 |
112 |
amountoutstanding => -10 |
109 |
} |
113 |
} |
Lines 114-120
subtest 'total_outstanding() tests' => sub {
Link Here
|
114 |
|
118 |
|
115 |
my $credit_2 = Koha::Account::Line->new( |
119 |
my $credit_2 = Koha::Account::Line->new( |
116 |
{ borrowernumber => $patron->id, |
120 |
{ borrowernumber => $patron->id, |
117 |
accounttype => "F", |
121 |
accounttype => "OVERDUE", |
|
|
122 |
status => "RETURNED", |
118 |
amount => -10, |
123 |
amount => -10, |
119 |
amountoutstanding => -10 |
124 |
amountoutstanding => -10 |
120 |
} |
125 |
} |
Lines 125-131
subtest 'total_outstanding() tests' => sub {
Link Here
|
125 |
|
130 |
|
126 |
my $credit_3 = Koha::Account::Line->new( |
131 |
my $credit_3 = Koha::Account::Line->new( |
127 |
{ borrowernumber => $patron->id, |
132 |
{ borrowernumber => $patron->id, |
128 |
accounttype => "F", |
133 |
accounttype => "OVERDUE", |
|
|
134 |
status => "RETURNED", |
129 |
amount => -100, |
135 |
amount => -100, |
130 |
amountoutstanding => -100 |
136 |
amountoutstanding => -100 |
131 |
} |
137 |
} |
Lines 154-160
subtest 'is_credit() and is_debit() tests' => sub {
Link Here
|
154 |
my $debit = Koha::Account::Line->new( |
160 |
my $debit = Koha::Account::Line->new( |
155 |
{ |
161 |
{ |
156 |
borrowernumber => $patron->id, |
162 |
borrowernumber => $patron->id, |
157 |
accounttype => "F", |
163 |
accounttype => "OVERDUE", |
|
|
164 |
status => "RETURNED", |
158 |
amount => 10, |
165 |
amount => 10, |
159 |
})->store; |
166 |
})->store; |
160 |
|
167 |
|
Lines 177-183
subtest 'apply() tests' => sub {
Link Here
|
177 |
|
184 |
|
178 |
my $debit_1 = Koha::Account::Line->new( |
185 |
my $debit_1 = Koha::Account::Line->new( |
179 |
{ borrowernumber => $patron->id, |
186 |
{ borrowernumber => $patron->id, |
180 |
accounttype => "F", |
187 |
accounttype => "OVERDUE", |
|
|
188 |
status => "RETURNED", |
181 |
amount => 10, |
189 |
amount => 10, |
182 |
amountoutstanding => 10 |
190 |
amountoutstanding => 10 |
183 |
} |
191 |
} |
Lines 185-191
subtest 'apply() tests' => sub {
Link Here
|
185 |
|
193 |
|
186 |
my $debit_2 = Koha::Account::Line->new( |
194 |
my $debit_2 = Koha::Account::Line->new( |
187 |
{ borrowernumber => $patron->id, |
195 |
{ borrowernumber => $patron->id, |
188 |
accounttype => "F", |
196 |
accounttype => "OVERDUE", |
|
|
197 |
status => "RETURNED", |
189 |
amount => 100, |
198 |
amount => 100, |
190 |
amountoutstanding => 100 |
199 |
amountoutstanding => 100 |
191 |
} |
200 |
} |
Lines 246-252
subtest 'apply() tests' => sub {
Link Here
|
246 |
my $credit_2 = $account->add_credit({ amount => 20 }); |
255 |
my $credit_2 = $account->add_credit({ amount => 20 }); |
247 |
my $debit_3 = Koha::Account::Line->new( |
256 |
my $debit_3 = Koha::Account::Line->new( |
248 |
{ borrowernumber => $patron->id, |
257 |
{ borrowernumber => $patron->id, |
249 |
accounttype => "F", |
258 |
accounttype => "OVERDUE", |
|
|
259 |
status => "RETURNED", |
250 |
amount => 100, |
260 |
amount => 100, |
251 |
amountoutstanding => 100 |
261 |
amountoutstanding => 100 |
252 |
} |
262 |
} |
Lines 294-300
subtest 'Keep account info when related patron, staff or item is deleted' => sub
Link Here
|
294 |
borrowernumber => $patron->borrowernumber, |
304 |
borrowernumber => $patron->borrowernumber, |
295 |
manager_id => $staff->borrowernumber, |
305 |
manager_id => $staff->borrowernumber, |
296 |
itemnumber => $item->itemnumber, |
306 |
itemnumber => $item->itemnumber, |
297 |
accounttype => "F", |
307 |
accounttype => "OVERDUE", |
|
|
308 |
status => "RETURNED", |
298 |
amount => 10, |
309 |
amount => 10, |
299 |
})->store; |
310 |
})->store; |
300 |
|
311 |
|
Lines 331-337
subtest 'adjust() tests' => sub {
Link Here
|
331 |
|
342 |
|
332 |
my $debit_1 = Koha::Account::Line->new( |
343 |
my $debit_1 = Koha::Account::Line->new( |
333 |
{ borrowernumber => $patron->id, |
344 |
{ borrowernumber => $patron->id, |
334 |
accounttype => "F", |
345 |
accounttype => "OVERDUE", |
|
|
346 |
status => "RETURNED", |
335 |
amount => 10, |
347 |
amount => 10, |
336 |
amountoutstanding => 10 |
348 |
amountoutstanding => 10 |
337 |
} |
349 |
} |
Lines 339-345
subtest 'adjust() tests' => sub {
Link Here
|
339 |
|
351 |
|
340 |
my $debit_2 = Koha::Account::Line->new( |
352 |
my $debit_2 = Koha::Account::Line->new( |
341 |
{ borrowernumber => $patron->id, |
353 |
{ borrowernumber => $patron->id, |
342 |
accounttype => "FU", |
354 |
accounttype => "OVERDUE", |
|
|
355 |
status => "UNRETURNED", |
343 |
amount => 100, |
356 |
amount => 100, |
344 |
amountoutstanding => 100 |
357 |
amountoutstanding => 100 |
345 |
} |
358 |
} |
Lines 350-361
subtest 'adjust() tests' => sub {
Link Here
|
350 |
throws_ok { $debit_1->adjust( { amount => 50, type => 'bad' } ) } |
363 |
throws_ok { $debit_1->adjust( { amount => 50, type => 'bad' } ) } |
351 |
qr/Update type not recognised/, 'Exception thrown for unrecognised type'; |
364 |
qr/Update type not recognised/, 'Exception thrown for unrecognised type'; |
352 |
|
365 |
|
353 |
throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_update' } ) } |
366 |
throws_ok { $debit_1->adjust( { amount => 50, type => 'overdue_update' } ) } |
354 |
qr/Update type not allowed on this accounttype/, |
367 |
qr/Update type not allowed on this accounttype/, |
355 |
'Exception thrown for type conflict'; |
368 |
'Exception thrown for type conflict'; |
356 |
|
369 |
|
357 |
# Increment an unpaid fine |
370 |
# Increment an unpaid fine |
358 |
$debit_2->adjust( { amount => 150, type => 'fine_update' } )->discard_changes; |
371 |
$debit_2->adjust( { amount => 150, type => 'overdue_update' } )->discard_changes; |
359 |
|
372 |
|
360 |
is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' ); |
373 |
is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' ); |
361 |
is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' ); |
374 |
is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' ); |
Lines 366-372
subtest 'adjust() tests' => sub {
Link Here
|
366 |
is( $offsets->count, 1, 'An offset is generated for the increment' ); |
379 |
is( $offsets->count, 1, 'An offset is generated for the increment' ); |
367 |
my $THIS_offset = $offsets->next; |
380 |
my $THIS_offset = $offsets->next; |
368 |
is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' ); |
381 |
is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' ); |
369 |
is( $THIS_offset->type, 'fine_increase', 'Adjust type stored correctly' ); |
382 |
is( $THIS_offset->type, 'OVERDUE_INCREASE', 'Adjust type stored correctly' ); |
370 |
|
383 |
|
371 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); |
384 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); |
372 |
|
385 |
|
Lines 382-388
subtest 'adjust() tests' => sub {
Link Here
|
382 |
t::lib::Mocks::mock_preference( 'FinesLog', 1 ); |
395 |
t::lib::Mocks::mock_preference( 'FinesLog', 1 ); |
383 |
|
396 |
|
384 |
# Increment the partially paid fine |
397 |
# Increment the partially paid fine |
385 |
$debit_2->adjust( { amount => 160, type => 'fine_update' } )->discard_changes; |
398 |
$debit_2->adjust( { amount => 160, type => 'overdue_update' } )->discard_changes; |
386 |
|
399 |
|
387 |
is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' ); |
400 |
is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' ); |
388 |
is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' ); |
401 |
is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' ); |
Lines 392-403
subtest 'adjust() tests' => sub {
Link Here
|
392 |
is( $offsets->count, 3, 'An offset is generated for the increment' ); |
405 |
is( $offsets->count, 3, 'An offset is generated for the increment' ); |
393 |
$THIS_offset = $offsets->last; |
406 |
$THIS_offset = $offsets->last; |
394 |
is( $THIS_offset->amount * 1, 10, 'Amount was calculated correctly (increment by 10)' ); |
407 |
is( $THIS_offset->amount * 1, 10, 'Amount was calculated correctly (increment by 10)' ); |
395 |
is( $THIS_offset->type, 'fine_increase', 'Adjust type stored correctly' ); |
408 |
is( $THIS_offset->type, 'OVERDUE_INCREASE', 'Adjust type stored correctly' ); |
396 |
|
409 |
|
397 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' ); |
410 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' ); |
398 |
|
411 |
|
399 |
# Decrement the partially paid fine, less than what was paid |
412 |
# Decrement the partially paid fine, less than what was paid |
400 |
$debit_2->adjust( { amount => 50, type => 'fine_update' } )->discard_changes; |
413 |
$debit_2->adjust( { amount => 50, type => 'overdue_update' } )->discard_changes; |
401 |
|
414 |
|
402 |
is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' ); |
415 |
is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' ); |
403 |
is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' ); |
416 |
is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' ); |
Lines 407-416
subtest 'adjust() tests' => sub {
Link Here
|
407 |
is( $offsets->count, 4, 'An offset is generated for the decrement' ); |
420 |
is( $offsets->count, 4, 'An offset is generated for the decrement' ); |
408 |
$THIS_offset = $offsets->last; |
421 |
$THIS_offset = $offsets->last; |
409 |
is( $THIS_offset->amount * 1, -110, 'Amount was calculated correctly (decrement by 110)' ); |
422 |
is( $THIS_offset->amount * 1, -110, 'Amount was calculated correctly (decrement by 110)' ); |
410 |
is( $THIS_offset->type, 'fine_decrease', 'Adjust type stored correctly' ); |
423 |
is( $THIS_offset->type, 'OVERDUE_DECREASE', 'Adjust type stored correctly' ); |
411 |
|
424 |
|
412 |
# Decrement the partially paid fine, more than what was paid |
425 |
# Decrement the partially paid fine, more than what was paid |
413 |
$debit_2->adjust( { amount => 30, type => 'fine_update' } )->discard_changes; |
426 |
$debit_2->adjust( { amount => 30, type => 'overdue_update' } )->discard_changes; |
414 |
is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' ); |
427 |
is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' ); |
415 |
is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' ); |
428 |
is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' ); |
416 |
is( $debit_2->lastincrement * 1, -20, 'lastincrement is the to the right value' ); |
429 |
is( $debit_2->lastincrement * 1, -20, 'lastincrement is the to the right value' ); |
Lines 419-425
subtest 'adjust() tests' => sub {
Link Here
|
419 |
is( $offsets->count, 5, 'An offset is generated for the decrement' ); |
432 |
is( $offsets->count, 5, 'An offset is generated for the decrement' ); |
420 |
$THIS_offset = $offsets->last; |
433 |
$THIS_offset = $offsets->last; |
421 |
is( $THIS_offset->amount * 1, -20, 'Amount was calculated correctly (decrement by 20)' ); |
434 |
is( $THIS_offset->amount * 1, -20, 'Amount was calculated correctly (decrement by 20)' ); |
422 |
is( $THIS_offset->type, 'fine_decrease', 'Adjust type stored correctly' ); |
435 |
is( $THIS_offset->type, 'OVERDUE_DECREASE', 'Adjust type stored correctly' ); |
423 |
|
436 |
|
424 |
my $overpayment_refund = $account->lines->last; |
437 |
my $overpayment_refund = $account->lines->last; |
425 |
is( $overpayment_refund->amount * 1, -10, 'A new credit has been added' ); |
438 |
is( $overpayment_refund->amount * 1, -10, 'A new credit has been added' ); |
Lines 445-451
subtest 'checkout() tests' => sub {
Link Here
|
445 |
amount => 10, |
458 |
amount => 10, |
446 |
item_id => $item->itemnumber, |
459 |
item_id => $item->itemnumber, |
447 |
issue_id => $checkout->issue_id, |
460 |
issue_id => $checkout->issue_id, |
448 |
type => 'fine', |
461 |
type => 'overdue', |
449 |
}); |
462 |
}); |
450 |
|
463 |
|
451 |
my $line_checkout = $line->checkout; |
464 |
my $line_checkout = $line->checkout; |
452 |
- |
|
|