|
Lines 18-24
Link Here
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
use utf8; |
19 |
use utf8; |
| 20 |
|
20 |
|
| 21 |
use Test::More tests => 70; |
21 |
use Test::More tests => 73; |
| 22 |
use Test::Exception; |
22 |
use Test::Exception; |
| 23 |
use Test::MockModule; |
23 |
use Test::MockModule; |
| 24 |
use Test::Deep qw( cmp_deeply ); |
24 |
use Test::Deep qw( cmp_deeply ); |
|
Lines 5429-5434
subtest 'Do not return on renewal (LOST charge)' => sub {
Link Here
|
| 5429 |
); |
5429 |
); |
| 5430 |
}; |
5430 |
}; |
| 5431 |
|
5431 |
|
|
|
5432 |
subtest 'Lost status does not change when preferences are set to 0' => sub { |
| 5433 |
plan tests => 2; |
| 5434 |
|
| 5435 |
my $library = $builder->build_object( { class => "Koha::Libraries" } ); |
| 5436 |
my $manager = $builder->build_object( { class => "Koha::Patrons" } ); |
| 5437 |
t::lib::Mocks::mock_userenv( { patron => $manager, branchcode => $manager->branchcode } ); |
| 5438 |
|
| 5439 |
my $biblio = $builder->build_sample_biblio; |
| 5440 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 5441 |
|
| 5442 |
my $item = $builder->build_sample_item( |
| 5443 |
{ |
| 5444 |
biblionumber => $biblio->biblionumber, |
| 5445 |
library => $library->branchcode, |
| 5446 |
replacementprice => 99, |
| 5447 |
itype => $itemtype, |
| 5448 |
itemlost => 1, |
| 5449 |
} |
| 5450 |
); |
| 5451 |
|
| 5452 |
my $debitCharge = Koha::Account::Line->new( |
| 5453 |
{ |
| 5454 |
borrowernumber => $patron->borrowernumber, |
| 5455 |
debit_type_code => 'LOST', |
| 5456 |
status => undef, |
| 5457 |
itemnumber => $item->itemnumber, |
| 5458 |
amount => 12, |
| 5459 |
amountoutstanding => 12, |
| 5460 |
interface => 'something', |
| 5461 |
} |
| 5462 |
)->store(); |
| 5463 |
|
| 5464 |
# Test for UpdateItemLostStatusWhenPaid |
| 5465 |
t::lib::Mocks::mock_preference( 'UpdateItemLostStatusWhenPaid', 0 ); |
| 5466 |
|
| 5467 |
my $paymentLine = Koha::Account::Line->new( |
| 5468 |
{ |
| 5469 |
borrowernumber => $patron->borrowernumber, |
| 5470 |
credit_type_code => 'CREDIT', |
| 5471 |
status => undef, |
| 5472 |
itemnumber => $item->itemnumber, |
| 5473 |
amountoutstanding => 0 - 12, |
| 5474 |
amount => 0 - 12, |
| 5475 |
interface => 'something', |
| 5476 |
} |
| 5477 |
)->store(); |
| 5478 |
|
| 5479 |
my $offset = Koha::Account::Offset->new( |
| 5480 |
{ |
| 5481 |
credit_id => $paymentLine->id, |
| 5482 |
debit_id => $debitCharge->id, |
| 5483 |
type => 'APPLY', |
| 5484 |
amount => 0 |
| 5485 |
} |
| 5486 |
)->store(); |
| 5487 |
|
| 5488 |
$paymentLine->apply( { debits => [$debitCharge] } ); |
| 5489 |
|
| 5490 |
is( |
| 5491 |
Koha::Items->find( $item->itemnumber )->itemlost, 1, |
| 5492 |
"Payment should not change itemlost status when UpdateItemLostStatusWhenPaid is 0" |
| 5493 |
); |
| 5494 |
|
| 5495 |
# Test for UpdateItemLostStatusWhenWriteOff |
| 5496 |
t::lib::Mocks::mock_preference( 'UpdateItemLostStatusWhenWriteOff', 0 ); |
| 5497 |
|
| 5498 |
my $writeOffLine = Koha::Account::Line->new( |
| 5499 |
{ |
| 5500 |
borrowernumber => $patron->borrowernumber, |
| 5501 |
credit_type_code => 'WRITEOFF', |
| 5502 |
status => undef, |
| 5503 |
itemnumber => $item->itemnumber, |
| 5504 |
amountoutstanding => 0 - 12, |
| 5505 |
amount => 0 - 12, |
| 5506 |
interface => 'something', |
| 5507 |
} |
| 5508 |
)->store(); |
| 5509 |
|
| 5510 |
$offset = Koha::Account::Offset->new( |
| 5511 |
{ |
| 5512 |
credit_id => $writeOffLine->id, |
| 5513 |
debit_id => $debitCharge->id, |
| 5514 |
type => 'APPLY', |
| 5515 |
amount => 0 |
| 5516 |
} |
| 5517 |
)->store(); |
| 5518 |
|
| 5519 |
$writeOffLine->apply( { debits => [$debitCharge] } ); |
| 5520 |
|
| 5521 |
is( |
| 5522 |
Koha::Items->find( $item->itemnumber )->itemlost, 1, |
| 5523 |
"Write-off should not change itemlost status when UpdateItemLostStatusWhenWriteOff is 0" |
| 5524 |
); |
| 5525 |
}; |
| 5526 |
|
| 5527 |
# Test for UpdateItemLostStatusWhenPaid |
| 5528 |
subtest 'Update lost item to authorized value on payment of balance' => sub { |
| 5529 |
plan tests => 5; |
| 5530 |
|
| 5531 |
my $library = $builder->build_object( { class => "Koha::Libraries" } ); |
| 5532 |
my $manager = $builder->build_object( { class => "Koha::Patrons" } ); |
| 5533 |
t::lib::Mocks::mock_userenv( { patron => $manager, branchcode => $manager->branchcode } ); |
| 5534 |
|
| 5535 |
my $biblio = $builder->build_sample_biblio; |
| 5536 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 5537 |
|
| 5538 |
for my $status ( 2 .. 6 ) { |
| 5539 |
t::lib::Mocks::mock_preference( 'UpdateItemLostStatusWhenPaid', $status ); |
| 5540 |
|
| 5541 |
my $item = $builder->build_sample_item( |
| 5542 |
{ |
| 5543 |
biblionumber => $biblio->biblionumber, |
| 5544 |
library => $library->branchcode, |
| 5545 |
replacementprice => 99, |
| 5546 |
itype => $itemtype, |
| 5547 |
itemlost => 1, |
| 5548 |
} |
| 5549 |
); |
| 5550 |
|
| 5551 |
my $debitCharge = Koha::Account::Line->new( |
| 5552 |
{ |
| 5553 |
borrowernumber => $patron->borrowernumber, |
| 5554 |
debit_type_code => 'LOST', |
| 5555 |
status => undef, |
| 5556 |
itemnumber => $item->itemnumber, |
| 5557 |
amount => 12, |
| 5558 |
amountoutstanding => 12, |
| 5559 |
interface => 'something', |
| 5560 |
} |
| 5561 |
)->store(); |
| 5562 |
|
| 5563 |
my $paymentLine = Koha::Account::Line->new( |
| 5564 |
{ |
| 5565 |
borrowernumber => $patron->borrowernumber, |
| 5566 |
credit_type_code => 'CREDIT', |
| 5567 |
status => undef, |
| 5568 |
itemnumber => $item->itemnumber, |
| 5569 |
amountoutstanding => 0 - 12, |
| 5570 |
amount => 0 - 12, |
| 5571 |
interface => 'something', |
| 5572 |
} |
| 5573 |
)->store(); |
| 5574 |
|
| 5575 |
my $offset = Koha::Account::Offset->new( |
| 5576 |
{ |
| 5577 |
credit_id => $paymentLine->id, |
| 5578 |
debit_id => $debitCharge->id, |
| 5579 |
type => 'APPLY', |
| 5580 |
amount => 0 |
| 5581 |
} |
| 5582 |
)->store(); |
| 5583 |
|
| 5584 |
$paymentLine->apply( { debits => [$debitCharge] } ); |
| 5585 |
|
| 5586 |
is( |
| 5587 |
Koha::Items->find( $item->itemnumber )->itemlost, $status, |
| 5588 |
"Payment should set itemlost to status $status" |
| 5589 |
); |
| 5590 |
} |
| 5591 |
}; |
| 5592 |
|
| 5593 |
# Test for UpdateItemLostStatusWhenWriteOff |
| 5594 |
subtest 'Update lost item to authorized value on write-off of balance' => sub { |
| 5595 |
plan tests => 5; |
| 5596 |
|
| 5597 |
my $library = $builder->build_object( { class => "Koha::Libraries" } ); |
| 5598 |
my $manager = $builder->build_object( { class => "Koha::Patrons" } ); |
| 5599 |
t::lib::Mocks::mock_userenv( { patron => $manager, branchcode => $manager->branchcode } ); |
| 5600 |
|
| 5601 |
my $biblio = $builder->build_sample_biblio; |
| 5602 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 5603 |
|
| 5604 |
for my $status ( 2 .. 6 ) { |
| 5605 |
t::lib::Mocks::mock_preference( 'UpdateItemLostStatusWhenWriteOff', $status ); |
| 5606 |
|
| 5607 |
my $item = $builder->build_sample_item( |
| 5608 |
{ |
| 5609 |
biblionumber => $biblio->biblionumber, |
| 5610 |
library => $library->branchcode, |
| 5611 |
replacementprice => 99, |
| 5612 |
itype => $itemtype, |
| 5613 |
itemlost => 1, |
| 5614 |
} |
| 5615 |
); |
| 5616 |
|
| 5617 |
my $debitCharge = Koha::Account::Line->new( |
| 5618 |
{ |
| 5619 |
borrowernumber => $patron->borrowernumber, |
| 5620 |
debit_type_code => 'LOST', |
| 5621 |
status => undef, |
| 5622 |
itemnumber => $item->itemnumber, |
| 5623 |
amount => 12, |
| 5624 |
amountoutstanding => 12, |
| 5625 |
interface => 'something', |
| 5626 |
} |
| 5627 |
)->store(); |
| 5628 |
|
| 5629 |
my $writeOffLine = Koha::Account::Line->new( |
| 5630 |
{ |
| 5631 |
borrowernumber => $patron->borrowernumber, |
| 5632 |
credit_type_code => 'WRITEOFF', |
| 5633 |
status => undef, |
| 5634 |
itemnumber => $item->itemnumber, |
| 5635 |
amountoutstanding => 0 - 12, |
| 5636 |
amount => 0 - 12, |
| 5637 |
interface => 'something', |
| 5638 |
} |
| 5639 |
)->store(); |
| 5640 |
|
| 5641 |
my $offset = Koha::Account::Offset->new( |
| 5642 |
{ |
| 5643 |
credit_id => $writeOffLine->id, |
| 5644 |
debit_id => $debitCharge->id, |
| 5645 |
type => 'APPLY', |
| 5646 |
amount => 0 |
| 5647 |
} |
| 5648 |
)->store(); |
| 5649 |
|
| 5650 |
$writeOffLine->apply( { debits => [$debitCharge] } ); |
| 5651 |
|
| 5652 |
is( |
| 5653 |
Koha::Items->find( $item->itemnumber )->itemlost, $status, |
| 5654 |
"Write-off should set itemlost to status $status" |
| 5655 |
); |
| 5656 |
} |
| 5657 |
}; |
| 5658 |
|
| 5432 |
subtest 'Filling a hold should cancel existing transfer' => sub { |
5659 |
subtest 'Filling a hold should cancel existing transfer' => sub { |
| 5433 |
plan tests => 4; |
5660 |
plan tests => 4; |
| 5434 |
|
5661 |
|
| 5435 |
- |
|
|