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 |
interface => 'commandline', |
63 |
interface => 'commandline', |
63 |
})->store; |
64 |
})->store; |
Lines 85-91
subtest 'total_outstanding() tests' => sub {
Link Here
|
85 |
|
86 |
|
86 |
my $debit_1 = Koha::Account::Line->new( |
87 |
my $debit_1 = Koha::Account::Line->new( |
87 |
{ borrowernumber => $patron->id, |
88 |
{ borrowernumber => $patron->id, |
88 |
accounttype => "F", |
89 |
accounttype => "OVERDUE", |
|
|
90 |
status => "RETURNED", |
89 |
amount => 10, |
91 |
amount => 10, |
90 |
amountoutstanding => 10, |
92 |
amountoutstanding => 10, |
91 |
interface => 'commandline', |
93 |
interface => 'commandline', |
Lines 94-100
subtest 'total_outstanding() tests' => sub {
Link Here
|
94 |
|
96 |
|
95 |
my $debit_2 = Koha::Account::Line->new( |
97 |
my $debit_2 = Koha::Account::Line->new( |
96 |
{ borrowernumber => $patron->id, |
98 |
{ borrowernumber => $patron->id, |
97 |
accounttype => "F", |
99 |
accounttype => "OVERDUE", |
|
|
100 |
status => "RETURNED", |
98 |
amount => 10, |
101 |
amount => 10, |
99 |
amountoutstanding => 10, |
102 |
amountoutstanding => 10, |
100 |
interface => 'commandline', |
103 |
interface => 'commandline', |
Lines 106-112
subtest 'total_outstanding() tests' => sub {
Link Here
|
106 |
|
109 |
|
107 |
my $credit_1 = Koha::Account::Line->new( |
110 |
my $credit_1 = Koha::Account::Line->new( |
108 |
{ borrowernumber => $patron->id, |
111 |
{ borrowernumber => $patron->id, |
109 |
accounttype => "F", |
112 |
accounttype => "OVERDUE", |
|
|
113 |
status => "RETURNED", |
110 |
amount => -10, |
114 |
amount => -10, |
111 |
amountoutstanding => -10, |
115 |
amountoutstanding => -10, |
112 |
interface => 'commandline', |
116 |
interface => 'commandline', |
Lines 118-124
subtest 'total_outstanding() tests' => sub {
Link Here
|
118 |
|
122 |
|
119 |
my $credit_2 = Koha::Account::Line->new( |
123 |
my $credit_2 = Koha::Account::Line->new( |
120 |
{ borrowernumber => $patron->id, |
124 |
{ borrowernumber => $patron->id, |
121 |
accounttype => "F", |
125 |
accounttype => "OVERDUE", |
|
|
126 |
status => "RETURNED", |
122 |
amount => -10, |
127 |
amount => -10, |
123 |
amountoutstanding => -10, |
128 |
amountoutstanding => -10, |
124 |
interface => 'commandline', |
129 |
interface => 'commandline', |
Lines 130-136
subtest 'total_outstanding() tests' => sub {
Link Here
|
130 |
|
135 |
|
131 |
my $credit_3 = Koha::Account::Line->new( |
136 |
my $credit_3 = Koha::Account::Line->new( |
132 |
{ borrowernumber => $patron->id, |
137 |
{ borrowernumber => $patron->id, |
133 |
accounttype => "F", |
138 |
accounttype => "OVERDUE", |
|
|
139 |
status => "RETURNED", |
134 |
amount => -100, |
140 |
amount => -100, |
135 |
amountoutstanding => -100, |
141 |
amountoutstanding => -100, |
136 |
interface => 'commandline', |
142 |
interface => 'commandline', |
Lines 160-166
subtest 'is_credit() and is_debit() tests' => sub {
Link Here
|
160 |
my $debit = Koha::Account::Line->new( |
166 |
my $debit = Koha::Account::Line->new( |
161 |
{ |
167 |
{ |
162 |
borrowernumber => $patron->id, |
168 |
borrowernumber => $patron->id, |
163 |
accounttype => "F", |
169 |
accounttype => "OVERDUE", |
|
|
170 |
status => "RETURNED", |
164 |
amount => 10, |
171 |
amount => 10, |
165 |
interface => 'commandline', |
172 |
interface => 'commandline', |
166 |
})->store; |
173 |
})->store; |
Lines 184-190
subtest 'apply() tests' => sub {
Link Here
|
184 |
|
191 |
|
185 |
my $debit_1 = Koha::Account::Line->new( |
192 |
my $debit_1 = Koha::Account::Line->new( |
186 |
{ borrowernumber => $patron->id, |
193 |
{ borrowernumber => $patron->id, |
187 |
accounttype => "F", |
194 |
accounttype => "OVERDUE", |
|
|
195 |
status => "RETURNED", |
188 |
amount => 10, |
196 |
amount => 10, |
189 |
amountoutstanding => 10, |
197 |
amountoutstanding => 10, |
190 |
interface => 'commandline', |
198 |
interface => 'commandline', |
Lines 193-199
subtest 'apply() tests' => sub {
Link Here
|
193 |
|
201 |
|
194 |
my $debit_2 = Koha::Account::Line->new( |
202 |
my $debit_2 = Koha::Account::Line->new( |
195 |
{ borrowernumber => $patron->id, |
203 |
{ borrowernumber => $patron->id, |
196 |
accounttype => "F", |
204 |
accounttype => "OVERDUE", |
|
|
205 |
status => "RETURNED", |
197 |
amount => 100, |
206 |
amount => 100, |
198 |
amountoutstanding => 100, |
207 |
amountoutstanding => 100, |
199 |
interface => 'commandline', |
208 |
interface => 'commandline', |
Lines 255-261
subtest 'apply() tests' => sub {
Link Here
|
255 |
my $credit_2 = $account->add_credit({ amount => 20, interface => 'commandline' }); |
264 |
my $credit_2 = $account->add_credit({ amount => 20, interface => 'commandline' }); |
256 |
my $debit_3 = Koha::Account::Line->new( |
265 |
my $debit_3 = Koha::Account::Line->new( |
257 |
{ borrowernumber => $patron->id, |
266 |
{ borrowernumber => $patron->id, |
258 |
accounttype => "F", |
267 |
accounttype => "OVERDUE", |
|
|
268 |
status => "RETURNED", |
259 |
amount => 100, |
269 |
amount => 100, |
260 |
amountoutstanding => 100, |
270 |
amountoutstanding => 100, |
261 |
interface => 'commandline', |
271 |
interface => 'commandline', |
Lines 304-310
subtest 'Keep account info when related patron, staff or item is deleted' => sub
Link Here
|
304 |
borrowernumber => $patron->borrowernumber, |
314 |
borrowernumber => $patron->borrowernumber, |
305 |
manager_id => $staff->borrowernumber, |
315 |
manager_id => $staff->borrowernumber, |
306 |
itemnumber => $item->itemnumber, |
316 |
itemnumber => $item->itemnumber, |
307 |
accounttype => "F", |
317 |
accounttype => "OVERDUE", |
|
|
318 |
status => "RETURNED", |
308 |
amount => 10, |
319 |
amount => 10, |
309 |
interface => 'commandline', |
320 |
interface => 'commandline', |
310 |
})->store; |
321 |
})->store; |
Lines 342-348
subtest 'adjust() tests' => sub {
Link Here
|
342 |
|
353 |
|
343 |
my $debit_1 = Koha::Account::Line->new( |
354 |
my $debit_1 = Koha::Account::Line->new( |
344 |
{ borrowernumber => $patron->id, |
355 |
{ borrowernumber => $patron->id, |
345 |
accounttype => "F", |
356 |
accounttype => "OVERDUE", |
|
|
357 |
status => "RETURNED", |
346 |
amount => 10, |
358 |
amount => 10, |
347 |
amountoutstanding => 10, |
359 |
amountoutstanding => 10, |
348 |
interface => 'commandline', |
360 |
interface => 'commandline', |
Lines 351-357
subtest 'adjust() tests' => sub {
Link Here
|
351 |
|
363 |
|
352 |
my $debit_2 = Koha::Account::Line->new( |
364 |
my $debit_2 = Koha::Account::Line->new( |
353 |
{ borrowernumber => $patron->id, |
365 |
{ borrowernumber => $patron->id, |
354 |
accounttype => "FU", |
366 |
accounttype => "OVERDUE", |
|
|
367 |
status => "UNRETURNED", |
355 |
amount => 100, |
368 |
amount => 100, |
356 |
amountoutstanding => 100, |
369 |
amountoutstanding => 100, |
357 |
interface => 'commandline' |
370 |
interface => 'commandline' |
Lines 363-374
subtest 'adjust() tests' => sub {
Link Here
|
363 |
throws_ok { $debit_1->adjust( { amount => 50, type => 'bad', interface => 'commandline' } ) } |
376 |
throws_ok { $debit_1->adjust( { amount => 50, type => 'bad', interface => 'commandline' } ) } |
364 |
qr/Update type not recognised/, 'Exception thrown for unrecognised type'; |
377 |
qr/Update type not recognised/, 'Exception thrown for unrecognised type'; |
365 |
|
378 |
|
366 |
throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_update', interface => 'commandline' } ) } |
379 |
throws_ok { $debit_1->adjust( { amount => 50, type => 'overdue_update', interface => 'commandline' } ) } |
367 |
qr/Update type not allowed on this accounttype/, |
380 |
qr/Update type not allowed on this accounttype/, |
368 |
'Exception thrown for type conflict'; |
381 |
'Exception thrown for type conflict'; |
369 |
|
382 |
|
370 |
# Increment an unpaid fine |
383 |
# Increment an unpaid fine |
371 |
$debit_2->adjust( { amount => 150, type => 'fine_update', interface => 'commandline' } )->discard_changes; |
384 |
$debit_2->adjust( { amount => 150, type => 'overdue_update', interface => 'commandline' } )->discard_changes; |
372 |
|
385 |
|
373 |
is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' ); |
386 |
is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' ); |
374 |
is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' ); |
387 |
is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' ); |
Lines 378-384
subtest 'adjust() tests' => sub {
Link Here
|
378 |
is( $offsets->count, 1, 'An offset is generated for the increment' ); |
391 |
is( $offsets->count, 1, 'An offset is generated for the increment' ); |
379 |
my $THIS_offset = $offsets->next; |
392 |
my $THIS_offset = $offsets->next; |
380 |
is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' ); |
393 |
is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' ); |
381 |
is( $THIS_offset->type, 'fine_increase', 'Adjust type stored correctly' ); |
394 |
is( $THIS_offset->type, 'OVERDUE_INCREASE', 'Adjust type stored correctly' ); |
382 |
|
395 |
|
383 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); |
396 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); |
384 |
|
397 |
|
Lines 394-400
subtest 'adjust() tests' => sub {
Link Here
|
394 |
t::lib::Mocks::mock_preference( 'FinesLog', 1 ); |
407 |
t::lib::Mocks::mock_preference( 'FinesLog', 1 ); |
395 |
|
408 |
|
396 |
# Increment the partially paid fine |
409 |
# Increment the partially paid fine |
397 |
$debit_2->adjust( { amount => 160, type => 'fine_update', interface => 'commandline' } )->discard_changes; |
410 |
$debit_2->adjust( { amount => 160, type => 'overdue_update', interface => 'commandline' } )->discard_changes; |
398 |
|
411 |
|
399 |
is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' ); |
412 |
is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' ); |
400 |
is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' ); |
413 |
is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' ); |
Lines 403-414
subtest 'adjust() tests' => sub {
Link Here
|
403 |
is( $offsets->count, 3, 'An offset is generated for the increment' ); |
416 |
is( $offsets->count, 3, 'An offset is generated for the increment' ); |
404 |
$THIS_offset = $offsets->last; |
417 |
$THIS_offset = $offsets->last; |
405 |
is( $THIS_offset->amount * 1, 10, 'Amount was calculated correctly (increment by 10)' ); |
418 |
is( $THIS_offset->amount * 1, 10, 'Amount was calculated correctly (increment by 10)' ); |
406 |
is( $THIS_offset->type, 'fine_increase', 'Adjust type stored correctly' ); |
419 |
is( $THIS_offset->type, 'OVERDUE_INCREASE', 'Adjust type stored correctly' ); |
407 |
|
420 |
|
408 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' ); |
421 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' ); |
409 |
|
422 |
|
410 |
# Decrement the partially paid fine, less than what was paid |
423 |
# Decrement the partially paid fine, less than what was paid |
411 |
$debit_2->adjust( { amount => 50, type => 'fine_update', interface => 'commandline' } )->discard_changes; |
424 |
$debit_2->adjust( { amount => 50, type => 'overdue_update', interface => 'commandline' } )->discard_changes; |
412 |
|
425 |
|
413 |
is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' ); |
426 |
is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' ); |
414 |
is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' ); |
427 |
is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' ); |
Lines 417-426
subtest 'adjust() tests' => sub {
Link Here
|
417 |
is( $offsets->count, 4, 'An offset is generated for the decrement' ); |
430 |
is( $offsets->count, 4, 'An offset is generated for the decrement' ); |
418 |
$THIS_offset = $offsets->last; |
431 |
$THIS_offset = $offsets->last; |
419 |
is( $THIS_offset->amount * 1, -110, 'Amount was calculated correctly (decrement by 110)' ); |
432 |
is( $THIS_offset->amount * 1, -110, 'Amount was calculated correctly (decrement by 110)' ); |
420 |
is( $THIS_offset->type, 'fine_decrease', 'Adjust type stored correctly' ); |
433 |
is( $THIS_offset->type, 'OVERDUE_DECREASE', 'Adjust type stored correctly' ); |
421 |
|
434 |
|
422 |
# Decrement the partially paid fine, more than what was paid |
435 |
# Decrement the partially paid fine, more than what was paid |
423 |
$debit_2->adjust( { amount => 30, type => 'fine_update', interface => 'commandline' } )->discard_changes; |
436 |
$debit_2->adjust( { amount => 30, type => 'overdue_update', interface => 'commandline' } )->discard_changes; |
424 |
is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' ); |
437 |
is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' ); |
425 |
is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' ); |
438 |
is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' ); |
426 |
|
439 |
|
Lines 428-434
subtest 'adjust() tests' => sub {
Link Here
|
428 |
is( $offsets->count, 5, 'An offset is generated for the decrement' ); |
441 |
is( $offsets->count, 5, 'An offset is generated for the decrement' ); |
429 |
$THIS_offset = $offsets->last; |
442 |
$THIS_offset = $offsets->last; |
430 |
is( $THIS_offset->amount * 1, -20, 'Amount was calculated correctly (decrement by 20)' ); |
443 |
is( $THIS_offset->amount * 1, -20, 'Amount was calculated correctly (decrement by 20)' ); |
431 |
is( $THIS_offset->type, 'fine_decrease', 'Adjust type stored correctly' ); |
444 |
is( $THIS_offset->type, 'OVERDUE_DECREASE', 'Adjust type stored correctly' ); |
432 |
|
445 |
|
433 |
my $overpayment_refund = $account->lines->last; |
446 |
my $overpayment_refund = $account->lines->last; |
434 |
is( $overpayment_refund->amount * 1, -10, 'A new credit has been added' ); |
447 |
is( $overpayment_refund->amount * 1, -10, 'A new credit has been added' ); |
Lines 455-461
subtest 'checkout() tests' => sub {
Link Here
|
455 |
interface => 'commandline', |
468 |
interface => 'commandline', |
456 |
item_id => $item->itemnumber, |
469 |
item_id => $item->itemnumber, |
457 |
issue_id => $checkout->issue_id, |
470 |
issue_id => $checkout->issue_id, |
458 |
type => 'fine', |
471 |
type => 'overdue', |
459 |
}); |
472 |
}); |
460 |
|
473 |
|
461 |
my $line_checkout = $line->checkout; |
474 |
my $line_checkout = $line->checkout; |
462 |
- |
|
|