|
Lines 64-87
my $retrieved_item_1 = Koha::Items->find( $new_item_1->itemnumber );
Link Here
|
| 64 |
is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' ); |
64 |
is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' ); |
| 65 |
|
65 |
|
| 66 |
subtest 'store' => sub { |
66 |
subtest 'store' => sub { |
| 67 |
plan tests => 4; |
67 |
plan tests => 5; |
| 68 |
my $biblio = $builder->build_sample_biblio; |
68 |
my $biblio = $builder->build_sample_biblio; |
| 69 |
my $today = dt_from_string->set( hour => 0, minute => 0, second => 0 ); |
69 |
my $today = dt_from_string->set( hour => 0, minute => 0, second => 0 ); |
| 70 |
my $item = Koha::Item->new( |
70 |
my $item = Koha::Item->new( |
| 71 |
{ |
71 |
{ |
| 72 |
homebranch => $library->{branchcode}, |
72 |
homebranch => $library->{branchcode}, |
| 73 |
holdingbranch => $library->{branchcode}, |
73 |
holdingbranch => $library->{branchcode}, |
| 74 |
biblionumber => $biblio->biblionumber, |
74 |
biblionumber => $biblio->biblionumber, |
| 75 |
location => 'my_loc', |
75 |
location => 'my_loc', |
| 76 |
} |
76 |
} |
| 77 |
)->store |
77 |
)->store->get_from_storage; |
| 78 |
->get_from_storage; |
78 |
|
| 79 |
|
79 |
is( t::lib::Dates::compare( $item->replacementpricedate, $today ), |
| 80 |
is( t::lib::Dates::compare($item->replacementpricedate, $today), 0, 'replacementpricedate must have been set to today if not given'); |
80 |
0, 'replacementpricedate must have been set to today if not given' ); |
| 81 |
is( t::lib::Dates::compare($item->datelastseen, $today), 0, 'datelastseen must have been set to today if not given'); |
81 |
is( t::lib::Dates::compare( $item->datelastseen, $today ), |
| 82 |
is( $item->itype, $biblio->biblioitem->itemtype, 'items.itype must have been set to biblioitem.itemtype is not given'); |
82 |
0, 'datelastseen must have been set to today if not given' ); |
| 83 |
is( $item->permanent_location, $item->location, 'permanent_location must have been set to location if not given' ); |
83 |
is( |
|
|
84 |
$item->itype, |
| 85 |
$biblio->biblioitem->itemtype, |
| 86 |
'items.itype must have been set to biblioitem.itemtype is not given' |
| 87 |
); |
| 88 |
is( $item->permanent_location, $item->location, |
| 89 |
'permanent_location must have been set to location if not given' ); |
| 84 |
$item->delete; |
90 |
$item->delete; |
|
|
91 |
|
| 92 |
subtest '_lost_found_trigger' => sub { |
| 93 |
plan tests => 6; |
| 94 |
|
| 95 |
t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 ); |
| 96 |
t::lib::Mocks::mock_preference( 'WhenLostForgiveFine', 0 ); |
| 97 |
|
| 98 |
my $processfee_amount = 20; |
| 99 |
my $replacement_amount = 99.00; |
| 100 |
my $item_type = $builder->build_object( |
| 101 |
{ |
| 102 |
class => 'Koha::ItemTypes', |
| 103 |
value => { |
| 104 |
notforloan => undef, |
| 105 |
rentalcharge => 0, |
| 106 |
defaultreplacecost => undef, |
| 107 |
processfee => $processfee_amount, |
| 108 |
rentalcharge_daily => 0, |
| 109 |
} |
| 110 |
} |
| 111 |
); |
| 112 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 113 |
|
| 114 |
$biblio = $builder->build_sample_biblio( { author => 'Hall, Daria' } ); |
| 115 |
|
| 116 |
subtest 'Full write-off tests' => sub { |
| 117 |
|
| 118 |
plan tests => 12; |
| 119 |
|
| 120 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 121 |
my $manager = |
| 122 |
$builder->build_object( { class => "Koha::Patrons" } ); |
| 123 |
t::lib::Mocks::mock_userenv( |
| 124 |
{ patron => $manager, branchcode => $manager->branchcode } ); |
| 125 |
|
| 126 |
my $item = $builder->build_sample_item( |
| 127 |
{ |
| 128 |
biblionumber => $biblio->biblionumber, |
| 129 |
library => $library->branchcode, |
| 130 |
replacementprice => $replacement_amount, |
| 131 |
itype => $item_type->itemtype, |
| 132 |
} |
| 133 |
); |
| 134 |
|
| 135 |
C4::Circulation::AddIssue( $patron->unblessed, $item->barcode ); |
| 136 |
|
| 137 |
# Simulate item marked as lost |
| 138 |
$item->itemlost(3)->store; |
| 139 |
C4::Circulation::LostItem( $item->itemnumber, 1 ); |
| 140 |
|
| 141 |
my $processing_fee_lines = Koha::Account::Lines->search( |
| 142 |
{ |
| 143 |
borrowernumber => $patron->id, |
| 144 |
itemnumber => $item->itemnumber, |
| 145 |
debit_type_code => 'PROCESSING' |
| 146 |
} |
| 147 |
); |
| 148 |
is( $processing_fee_lines->count, |
| 149 |
1, 'Only one processing fee produced' ); |
| 150 |
my $processing_fee_line = $processing_fee_lines->next; |
| 151 |
is( $processing_fee_line->amount + 0, |
| 152 |
$processfee_amount, |
| 153 |
'The right PROCESSING amount is generated' ); |
| 154 |
is( $processing_fee_line->amountoutstanding + 0, |
| 155 |
$processfee_amount, |
| 156 |
'The right PROCESSING amountoutstanding is generated' ); |
| 157 |
|
| 158 |
my $lost_fee_lines = Koha::Account::Lines->search( |
| 159 |
{ |
| 160 |
borrowernumber => $patron->id, |
| 161 |
itemnumber => $item->itemnumber, |
| 162 |
debit_type_code => 'LOST' |
| 163 |
} |
| 164 |
); |
| 165 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
| 166 |
my $lost_fee_line = $lost_fee_lines->next; |
| 167 |
is( $lost_fee_line->amount + 0, |
| 168 |
$replacement_amount, 'The right LOST amount is generated' ); |
| 169 |
is( $lost_fee_line->amountoutstanding + 0, |
| 170 |
$replacement_amount, |
| 171 |
'The right LOST amountoutstanding is generated' ); |
| 172 |
is( $lost_fee_line->status, undef, 'The LOST status was not set' ); |
| 173 |
|
| 174 |
my $account = $patron->account; |
| 175 |
my $debts = $account->outstanding_debits; |
| 176 |
|
| 177 |
# Write off the debt |
| 178 |
my $credit = $account->add_credit( |
| 179 |
{ |
| 180 |
amount => $account->balance, |
| 181 |
type => 'WRITEOFF', |
| 182 |
interface => 'test', |
| 183 |
} |
| 184 |
); |
| 185 |
$credit->apply( |
| 186 |
{ debits => [ $debts->as_list ], offset_type => 'Writeoff' } ); |
| 187 |
|
| 188 |
# Simulate item marked as found |
| 189 |
$item->itemlost(0)->store; |
| 190 |
is( $item->{_refunded}, undef, 'No LOST_FOUND account line added' ); |
| 191 |
|
| 192 |
$lost_fee_line->discard_changes; # reload from DB |
| 193 |
is( $lost_fee_line->amountoutstanding + 0, |
| 194 |
0, 'Lost fee has no outstanding amount' ); |
| 195 |
is( $lost_fee_line->debit_type_code, |
| 196 |
'LOST', 'Lost fee now still has account type of LOST' ); |
| 197 |
is( $lost_fee_line->status, 'FOUND', |
| 198 |
"Lost fee now has account status of FOUND - No Refund" ); |
| 199 |
|
| 200 |
is( $patron->account->balance, |
| 201 |
-0, 'The patron balance is 0, everything was written off' ); |
| 202 |
}; |
| 203 |
|
| 204 |
subtest 'Full payment tests' => sub { |
| 205 |
|
| 206 |
plan tests => 14; |
| 207 |
|
| 208 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 209 |
|
| 210 |
my $item = $builder->build_sample_item( |
| 211 |
{ |
| 212 |
biblionumber => $biblio->biblionumber, |
| 213 |
library => $library->branchcode, |
| 214 |
replacementprice => $replacement_amount, |
| 215 |
itype => $item_type->itemtype |
| 216 |
} |
| 217 |
); |
| 218 |
|
| 219 |
my $issue = |
| 220 |
C4::Circulation::AddIssue( $patron->unblessed, $item->barcode ); |
| 221 |
|
| 222 |
# Simulate item marked as lost |
| 223 |
$item->itemlost(1)->store; |
| 224 |
C4::Circulation::LostItem( $item->itemnumber, 1 ); |
| 225 |
|
| 226 |
my $processing_fee_lines = Koha::Account::Lines->search( |
| 227 |
{ |
| 228 |
borrowernumber => $patron->id, |
| 229 |
itemnumber => $item->itemnumber, |
| 230 |
debit_type_code => 'PROCESSING' |
| 231 |
} |
| 232 |
); |
| 233 |
is( $processing_fee_lines->count, |
| 234 |
1, 'Only one processing fee produced' ); |
| 235 |
my $processing_fee_line = $processing_fee_lines->next; |
| 236 |
is( $processing_fee_line->amount + 0, |
| 237 |
$processfee_amount, |
| 238 |
'The right PROCESSING amount is generated' ); |
| 239 |
is( $processing_fee_line->amountoutstanding + 0, |
| 240 |
$processfee_amount, |
| 241 |
'The right PROCESSING amountoutstanding is generated' ); |
| 242 |
|
| 243 |
my $lost_fee_lines = Koha::Account::Lines->search( |
| 244 |
{ |
| 245 |
borrowernumber => $patron->id, |
| 246 |
itemnumber => $item->itemnumber, |
| 247 |
debit_type_code => 'LOST' |
| 248 |
} |
| 249 |
); |
| 250 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
| 251 |
my $lost_fee_line = $lost_fee_lines->next; |
| 252 |
is( $lost_fee_line->amount + 0, |
| 253 |
$replacement_amount, 'The right LOST amount is generated' ); |
| 254 |
is( $lost_fee_line->amountoutstanding + 0, |
| 255 |
$replacement_amount, |
| 256 |
'The right LOST amountountstanding is generated' ); |
| 257 |
|
| 258 |
my $account = $patron->account; |
| 259 |
my $debts = $account->outstanding_debits; |
| 260 |
|
| 261 |
# Pay off the debt |
| 262 |
my $credit = $account->add_credit( |
| 263 |
{ |
| 264 |
amount => $account->balance, |
| 265 |
type => 'PAYMENT', |
| 266 |
interface => 'test', |
| 267 |
} |
| 268 |
); |
| 269 |
$credit->apply( |
| 270 |
{ debits => [ $debts->as_list ], offset_type => 'Payment' } ); |
| 271 |
|
| 272 |
# Simulate item marked as found |
| 273 |
$item->itemlost(0)->store; |
| 274 |
is( $item->{_refunded}, 1, 'Refund triggered' ); |
| 275 |
|
| 276 |
my $credit_return = Koha::Account::Lines->search( |
| 277 |
{ |
| 278 |
itemnumber => $item->itemnumber, |
| 279 |
credit_type_code => 'LOST_FOUND' |
| 280 |
}, |
| 281 |
{ rows => 1 } |
| 282 |
)->single; |
| 283 |
|
| 284 |
ok( $credit_return, 'An account line of type LOST_FOUND is added' ); |
| 285 |
is( $credit_return->amount + 0, |
| 286 |
-99.00, |
| 287 |
'The account line of type LOST_FOUND has an amount of -99' ); |
| 288 |
is( |
| 289 |
$credit_return->amountoutstanding + 0, |
| 290 |
-99.00, |
| 291 |
'The account line of type LOST_FOUND has an amountoutstanding of -99' |
| 292 |
); |
| 293 |
|
| 294 |
$lost_fee_line->discard_changes; |
| 295 |
is( $lost_fee_line->amountoutstanding + 0, |
| 296 |
0, 'Lost fee has no outstanding amount' ); |
| 297 |
is( $lost_fee_line->debit_type_code, |
| 298 |
'LOST', 'Lost fee now still has account type of LOST' ); |
| 299 |
is( $lost_fee_line->status, 'FOUND', |
| 300 |
"Lost fee now has account status of FOUND" ); |
| 301 |
|
| 302 |
is( $patron->account->balance, -99, |
| 303 |
'The patron balance is -99, a credit that equals the lost fee payment' |
| 304 |
); |
| 305 |
}; |
| 306 |
|
| 307 |
subtest 'Test without payment or write off' => sub { |
| 308 |
|
| 309 |
plan tests => 14; |
| 310 |
|
| 311 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 312 |
|
| 313 |
my $item = $builder->build_sample_item( |
| 314 |
{ |
| 315 |
biblionumber => $biblio->biblionumber, |
| 316 |
library => $library->branchcode, |
| 317 |
replacementprice => 23.00, |
| 318 |
replacementprice => $replacement_amount, |
| 319 |
itype => $item_type->itemtype |
| 320 |
} |
| 321 |
); |
| 322 |
|
| 323 |
my $issue = |
| 324 |
C4::Circulation::AddIssue( $patron->unblessed, $item->barcode ); |
| 325 |
|
| 326 |
# Simulate item marked as lost |
| 327 |
$item->itemlost(3)->store; |
| 328 |
C4::Circulation::LostItem( $item->itemnumber, 1 ); |
| 329 |
|
| 330 |
my $processing_fee_lines = Koha::Account::Lines->search( |
| 331 |
{ |
| 332 |
borrowernumber => $patron->id, |
| 333 |
itemnumber => $item->itemnumber, |
| 334 |
debit_type_code => 'PROCESSING' |
| 335 |
} |
| 336 |
); |
| 337 |
is( $processing_fee_lines->count, |
| 338 |
1, 'Only one processing fee produced' ); |
| 339 |
my $processing_fee_line = $processing_fee_lines->next; |
| 340 |
is( $processing_fee_line->amount + 0, |
| 341 |
$processfee_amount, |
| 342 |
'The right PROCESSING amount is generated' ); |
| 343 |
is( $processing_fee_line->amountoutstanding + 0, |
| 344 |
$processfee_amount, |
| 345 |
'The right PROCESSING amountoutstanding is generated' ); |
| 346 |
|
| 347 |
my $lost_fee_lines = Koha::Account::Lines->search( |
| 348 |
{ |
| 349 |
borrowernumber => $patron->id, |
| 350 |
itemnumber => $item->itemnumber, |
| 351 |
debit_type_code => 'LOST' |
| 352 |
} |
| 353 |
); |
| 354 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
| 355 |
my $lost_fee_line = $lost_fee_lines->next; |
| 356 |
is( $lost_fee_line->amount + 0, |
| 357 |
$replacement_amount, 'The right LOST amount is generated' ); |
| 358 |
is( $lost_fee_line->amountoutstanding + 0, |
| 359 |
$replacement_amount, |
| 360 |
'The right LOST amountountstanding is generated' ); |
| 361 |
|
| 362 |
# Simulate item marked as found |
| 363 |
$item->itemlost(0)->store; |
| 364 |
is( $item->{_refunded}, 1, 'Refund triggered' ); |
| 365 |
|
| 366 |
my $credit_return = Koha::Account::Lines->search( |
| 367 |
{ |
| 368 |
itemnumber => $item->itemnumber, |
| 369 |
credit_type_code => 'LOST_FOUND' |
| 370 |
}, |
| 371 |
{ rows => 1 } |
| 372 |
)->single; |
| 373 |
|
| 374 |
ok( $credit_return, 'An account line of type LOST_FOUND is added' ); |
| 375 |
is( $credit_return->amount + 0, |
| 376 |
-99.00, |
| 377 |
'The account line of type LOST_FOUND has an amount of -99' ); |
| 378 |
is( |
| 379 |
$credit_return->amountoutstanding + 0, |
| 380 |
0, |
| 381 |
'The account line of type LOST_FOUND has an amountoutstanding of 0' |
| 382 |
); |
| 383 |
|
| 384 |
$lost_fee_line->discard_changes; |
| 385 |
is( $lost_fee_line->amountoutstanding + 0, |
| 386 |
0, 'Lost fee has no outstanding amount' ); |
| 387 |
is( $lost_fee_line->debit_type_code, |
| 388 |
'LOST', 'Lost fee now still has account type of LOST' ); |
| 389 |
is( $lost_fee_line->status, 'FOUND', |
| 390 |
"Lost fee now has account status of FOUND" ); |
| 391 |
|
| 392 |
is( $patron->account->balance, |
| 393 |
20, 'The patron balance is 20, still owes the processing fee' ); |
| 394 |
}; |
| 395 |
|
| 396 |
subtest |
| 397 |
'Test with partial payement and write off, and remaining debt' => |
| 398 |
sub { |
| 399 |
|
| 400 |
plan tests => 17; |
| 401 |
|
| 402 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 403 |
my $item = $builder->build_sample_item( |
| 404 |
{ |
| 405 |
biblionumber => $biblio->biblionumber, |
| 406 |
library => $library->branchcode, |
| 407 |
replacementprice => $replacement_amount, |
| 408 |
itype => $item_type->itemtype |
| 409 |
} |
| 410 |
); |
| 411 |
|
| 412 |
my $issue = |
| 413 |
C4::Circulation::AddIssue( $patron->unblessed, $item->barcode ); |
| 414 |
|
| 415 |
# Simulate item marked as lost |
| 416 |
$item->itemlost(1)->store; |
| 417 |
C4::Circulation::LostItem( $item->itemnumber, 1 ); |
| 418 |
|
| 419 |
my $processing_fee_lines = Koha::Account::Lines->search( |
| 420 |
{ |
| 421 |
borrowernumber => $patron->id, |
| 422 |
itemnumber => $item->itemnumber, |
| 423 |
debit_type_code => 'PROCESSING' |
| 424 |
} |
| 425 |
); |
| 426 |
is( $processing_fee_lines->count, |
| 427 |
1, 'Only one processing fee produced' ); |
| 428 |
my $processing_fee_line = $processing_fee_lines->next; |
| 429 |
is( $processing_fee_line->amount + 0, |
| 430 |
$processfee_amount, |
| 431 |
'The right PROCESSING amount is generated' ); |
| 432 |
is( $processing_fee_line->amountoutstanding + 0, |
| 433 |
$processfee_amount, |
| 434 |
'The right PROCESSING amountoutstanding is generated' ); |
| 435 |
|
| 436 |
my $lost_fee_lines = Koha::Account::Lines->search( |
| 437 |
{ |
| 438 |
borrowernumber => $patron->id, |
| 439 |
itemnumber => $item->itemnumber, |
| 440 |
debit_type_code => 'LOST' |
| 441 |
} |
| 442 |
); |
| 443 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
| 444 |
my $lost_fee_line = $lost_fee_lines->next; |
| 445 |
is( $lost_fee_line->amount + 0, |
| 446 |
$replacement_amount, 'The right LOST amount is generated' ); |
| 447 |
is( $lost_fee_line->amountoutstanding + 0, |
| 448 |
$replacement_amount, |
| 449 |
'The right LOST amountountstanding is generated' ); |
| 450 |
|
| 451 |
my $account = $patron->account; |
| 452 |
is( |
| 453 |
$account->balance, |
| 454 |
$processfee_amount + $replacement_amount, |
| 455 |
'Balance is PROCESSING + L' |
| 456 |
); |
| 457 |
|
| 458 |
# Partially pay fee |
| 459 |
my $payment_amount = 27; |
| 460 |
my $payment = $account->add_credit( |
| 461 |
{ |
| 462 |
amount => $payment_amount, |
| 463 |
type => 'PAYMENT', |
| 464 |
interface => 'test', |
| 465 |
} |
| 466 |
); |
| 467 |
|
| 468 |
$payment->apply( |
| 469 |
{ debits => [$lost_fee_line], offset_type => 'Payment' } ); |
| 470 |
|
| 471 |
# Partially write off fee |
| 472 |
my $write_off_amount = 25; |
| 473 |
my $write_off = $account->add_credit( |
| 474 |
{ |
| 475 |
amount => $write_off_amount, |
| 476 |
type => 'WRITEOFF', |
| 477 |
interface => 'test', |
| 478 |
} |
| 479 |
); |
| 480 |
$write_off->apply( |
| 481 |
{ debits => [$lost_fee_line], offset_type => 'Writeoff' } ); |
| 482 |
|
| 483 |
is( |
| 484 |
$account->balance, |
| 485 |
$processfee_amount + |
| 486 |
$replacement_amount - |
| 487 |
$payment_amount - |
| 488 |
$write_off_amount, |
| 489 |
'Payment and write off applied' |
| 490 |
); |
| 491 |
|
| 492 |
# Store the amountoutstanding value |
| 493 |
$lost_fee_line->discard_changes; |
| 494 |
my $outstanding = $lost_fee_line->amountoutstanding; |
| 495 |
|
| 496 |
# Simulate item marked as found |
| 497 |
$item->itemlost(0)->store; |
| 498 |
is( $item->{_refunded}, 1, 'Refund triggered' ); |
| 499 |
|
| 500 |
my $credit_return = Koha::Account::Lines->search( |
| 501 |
{ |
| 502 |
itemnumber => $item->itemnumber, |
| 503 |
credit_type_code => 'LOST_FOUND' |
| 504 |
}, |
| 505 |
{ rows => 1 } |
| 506 |
)->single; |
| 507 |
|
| 508 |
ok( $credit_return, 'An account line of type LOST_FOUND is added' ); |
| 509 |
|
| 510 |
is( |
| 511 |
$account->balance, |
| 512 |
$processfee_amount - $payment_amount, |
| 513 |
'Balance is PROCESSING - PAYMENT (LOST_FOUND)' |
| 514 |
); |
| 515 |
|
| 516 |
$lost_fee_line->discard_changes; |
| 517 |
is( $lost_fee_line->amountoutstanding + 0, |
| 518 |
0, 'Lost fee has no outstanding amount' ); |
| 519 |
is( $lost_fee_line->debit_type_code, |
| 520 |
'LOST', 'Lost fee now still has account type of LOST' ); |
| 521 |
is( $lost_fee_line->status, 'FOUND', |
| 522 |
"Lost fee now has account status of FOUND" ); |
| 523 |
|
| 524 |
is( |
| 525 |
$credit_return->amount + 0, |
| 526 |
( $payment_amount + $outstanding ) * -1, |
| 527 |
'The account line of type LOST_FOUND has an amount equal to the payment + outstanding' |
| 528 |
); |
| 529 |
is( |
| 530 |
$credit_return->amountoutstanding + 0, |
| 531 |
$payment_amount * -1, |
| 532 |
'The account line of type LOST_FOUND has an amountoutstanding equal to the payment' |
| 533 |
); |
| 534 |
|
| 535 |
is( |
| 536 |
$account->balance, |
| 537 |
$processfee_amount - $payment_amount, |
| 538 |
'The patron balance is the difference between the PROCESSING and the credit' |
| 539 |
); |
| 540 |
}; |
| 541 |
|
| 542 |
subtest 'Partial payment, existing debits and AccountAutoReconcile' => |
| 543 |
sub { |
| 544 |
|
| 545 |
plan tests => 10; |
| 546 |
|
| 547 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 548 |
my $barcode = 'KD123456793'; |
| 549 |
my $replacement_amount = 100; |
| 550 |
my $processfee_amount = 20; |
| 551 |
|
| 552 |
my $item_type = $builder->build_object( |
| 553 |
{ |
| 554 |
class => 'Koha::ItemTypes', |
| 555 |
value => { |
| 556 |
notforloan => undef, |
| 557 |
rentalcharge => 0, |
| 558 |
defaultreplacecost => undef, |
| 559 |
processfee => 0, |
| 560 |
rentalcharge_daily => 0, |
| 561 |
} |
| 562 |
} |
| 563 |
); |
| 564 |
my $item = Koha::Item->new( |
| 565 |
{ |
| 566 |
biblionumber => $biblio->biblionumber, |
| 567 |
homebranch => $library->branchcode, |
| 568 |
holdingbranch => $library->branchcode, |
| 569 |
barcode => $barcode, |
| 570 |
replacementprice => $replacement_amount, |
| 571 |
itype => $item_type->itemtype |
| 572 |
}, |
| 573 |
)->store; |
| 574 |
|
| 575 |
my $issue = |
| 576 |
C4::Circulation::AddIssue( $patron->unblessed, $barcode ); |
| 577 |
|
| 578 |
# Simulate item marked as lost |
| 579 |
$item->itemlost(1)->store; |
| 580 |
C4::Circulation::LostItem( $item->itemnumber, 1 ); |
| 581 |
|
| 582 |
my $lost_fee_lines = Koha::Account::Lines->search( |
| 583 |
{ |
| 584 |
borrowernumber => $patron->id, |
| 585 |
itemnumber => $item->itemnumber, |
| 586 |
debit_type_code => 'LOST' |
| 587 |
} |
| 588 |
); |
| 589 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
| 590 |
my $lost_fee_line = $lost_fee_lines->next; |
| 591 |
is( $lost_fee_line->amount + 0, |
| 592 |
$replacement_amount, 'The right LOST amount is generated' ); |
| 593 |
is( $lost_fee_line->amountoutstanding + 0, |
| 594 |
$replacement_amount, |
| 595 |
'The right LOST amountountstanding is generated' ); |
| 596 |
|
| 597 |
my $account = $patron->account; |
| 598 |
is( $account->balance, $replacement_amount, 'Balance is L' ); |
| 599 |
|
| 600 |
# Partially pay fee |
| 601 |
my $payment_amount = 27; |
| 602 |
my $payment = $account->add_credit( |
| 603 |
{ |
| 604 |
amount => $payment_amount, |
| 605 |
type => 'PAYMENT', |
| 606 |
interface => 'test', |
| 607 |
} |
| 608 |
); |
| 609 |
$payment->apply( |
| 610 |
{ debits => [$lost_fee_line], offset_type => 'Payment' } ); |
| 611 |
|
| 612 |
is( |
| 613 |
$account->balance, |
| 614 |
$replacement_amount - $payment_amount, |
| 615 |
'Payment applied' |
| 616 |
); |
| 617 |
|
| 618 |
my $manual_debit_amount = 80; |
| 619 |
$account->add_debit( |
| 620 |
{ |
| 621 |
amount => $manual_debit_amount, |
| 622 |
type => 'OVERDUE', |
| 623 |
interface => 'test' |
| 624 |
} |
| 625 |
); |
| 626 |
|
| 627 |
is( |
| 628 |
$account->balance, |
| 629 |
$manual_debit_amount + $replacement_amount - $payment_amount, |
| 630 |
'Manual debit applied' |
| 631 |
); |
| 632 |
|
| 633 |
t::lib::Mocks::mock_preference( 'AccountAutoReconcile', 1 ); |
| 634 |
|
| 635 |
# Simulate item marked as found |
| 636 |
$item->itemlost(0)->store; |
| 637 |
is( $item->{_refunded}, 1, 'Refund triggered' ); |
| 638 |
|
| 639 |
my $credit_return = Koha::Account::Lines->search( |
| 640 |
{ |
| 641 |
itemnumber => $item->itemnumber, |
| 642 |
credit_type_code => 'LOST_FOUND' |
| 643 |
}, |
| 644 |
{ rows => 1 } |
| 645 |
)->single; |
| 646 |
|
| 647 |
ok( $credit_return, 'An account line of type LOST_FOUND is added' ); |
| 648 |
|
| 649 |
is( |
| 650 |
$account->balance, |
| 651 |
$manual_debit_amount - $payment_amount, |
| 652 |
'Balance is PROCESSING - payment (LOST_FOUND)' |
| 653 |
); |
| 654 |
|
| 655 |
my $manual_debit = Koha::Account::Lines->search( |
| 656 |
{ |
| 657 |
borrowernumber => $patron->id, |
| 658 |
debit_type_code => 'OVERDUE', |
| 659 |
status => 'UNRETURNED' |
| 660 |
} |
| 661 |
)->next; |
| 662 |
is( |
| 663 |
$manual_debit->amountoutstanding + 0, |
| 664 |
$manual_debit_amount - $payment_amount, |
| 665 |
'reconcile_balance was called' |
| 666 |
); |
| 667 |
}; |
| 668 |
|
| 669 |
subtest 'Patron deleted' => sub { |
| 670 |
plan tests => 1; |
| 671 |
|
| 672 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 673 |
my $barcode = 'KD123456794'; |
| 674 |
my $replacement_amount = 100; |
| 675 |
my $processfee_amount = 20; |
| 676 |
|
| 677 |
my $item_type = $builder->build_object( |
| 678 |
{ |
| 679 |
class => 'Koha::ItemTypes', |
| 680 |
value => { |
| 681 |
notforloan => undef, |
| 682 |
rentalcharge => 0, |
| 683 |
defaultreplacecost => undef, |
| 684 |
processfee => 0, |
| 685 |
rentalcharge_daily => 0, |
| 686 |
} |
| 687 |
} |
| 688 |
); |
| 689 |
my $item = Koha::Item->new( |
| 690 |
{ |
| 691 |
biblionumber => $biblio->biblionumber, |
| 692 |
homebranch => $library->branchcode, |
| 693 |
holdingbranch => $library->branchcode, |
| 694 |
barcode => $barcode, |
| 695 |
replacementprice => $replacement_amount, |
| 696 |
itype => $item_type->itemtype |
| 697 |
}, |
| 698 |
)->store; |
| 699 |
|
| 700 |
my $issue = |
| 701 |
C4::Circulation::AddIssue( $patron->unblessed, $barcode ); |
| 702 |
|
| 703 |
# Simulate item marked as lost |
| 704 |
$item->itemlost(1)->store; |
| 705 |
C4::Circulation::LostItem( $item->itemnumber, 1 ); |
| 706 |
|
| 707 |
$issue->delete(); |
| 708 |
$patron->delete(); |
| 709 |
|
| 710 |
# Simulate item marked as found |
| 711 |
$item->itemlost(0)->store; |
| 712 |
is( $item->{_refunded}, undef, 'No refund triggered' ); |
| 713 |
|
| 714 |
}; |
| 715 |
}; |
| 85 |
}; |
716 |
}; |
| 86 |
|
717 |
|
| 87 |
subtest 'get_transfer' => sub { |
718 |
subtest 'get_transfer' => sub { |
|
Lines 107-113
subtest 'holds' => sub {
Link Here
|
| 107 |
my $item = $builder->build_sample_item({ |
738 |
my $item = $builder->build_sample_item({ |
| 108 |
biblionumber => $biblio->biblionumber, |
739 |
biblionumber => $biblio->biblionumber, |
| 109 |
}); |
740 |
}); |
| 110 |
$nb_of_items++; |
|
|
| 111 |
is($item->holds->count, 0, "Nothing returned if no holds"); |
741 |
is($item->holds->count, 0, "Nothing returned if no holds"); |
| 112 |
my $hold1 = $builder->build({ source => 'Reserve', value => { itemnumber=>$item->itemnumber, found => 'T' }}); |
742 |
my $hold1 = $builder->build({ source => 'Reserve', value => { itemnumber=>$item->itemnumber, found => 'T' }}); |
| 113 |
my $hold2 = $builder->build({ source => 'Reserve', value => { itemnumber=>$item->itemnumber, found => 'W' }}); |
743 |
my $hold2 = $builder->build({ source => 'Reserve', value => { itemnumber=>$item->itemnumber, found => 'W' }}); |
|
Lines 172-178
subtest 'can_be_transferred' => sub {
Link Here
|
| 172 |
homebranch => $library1->branchcode, |
802 |
homebranch => $library1->branchcode, |
| 173 |
holdingbranch => $library1->branchcode, |
803 |
holdingbranch => $library1->branchcode, |
| 174 |
}); |
804 |
}); |
| 175 |
$nb_of_items++; |
|
|
| 176 |
|
805 |
|
| 177 |
is(Koha::Item::Transfer::Limits->search({ |
806 |
is(Koha::Item::Transfer::Limits->search({ |
| 178 |
fromBranch => $library1->branchcode, |
807 |
fromBranch => $library1->branchcode, |
|
Lines 196-202
subtest 'can_be_transferred' => sub {
Link Here
|
| 196 |
'We get the same result also if we pass the from-library parameter.'); |
825 |
'We get the same result also if we pass the from-library parameter.'); |
| 197 |
}; |
826 |
}; |
| 198 |
|
827 |
|
|
|
828 |
# Reset nb_of_items prior to testing delete |
| 829 |
$nb_of_items = Koha::Items->search->count; |
| 830 |
|
| 831 |
# Test delete |
| 199 |
$retrieved_item_1->delete; |
832 |
$retrieved_item_1->delete; |
| 200 |
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' ); |
833 |
is( Koha::Items->search->count, $nb_of_items - 1, 'Delete should have deleted the item' ); |
| 201 |
|
834 |
|
| 202 |
$schema->storage->txn_rollback; |
835 |
$schema->storage->txn_rollback; |
| 203 |
- |
|
|