use Modern::Perl;
use utf8;
-use Test::More tests => 47;
+use Test::More tests => 51;
use Test::MockModule;
use Test::Deep qw( cmp_deeply );
is( Koha::Item::Transfers->search({ itemnumber => $item->itemnumber, datearrived => undef })->count, 0, "No outstanding transfers when hold is waiting");
};
+subtest 'Tests for NoRefundOnLostReturnedItemsAge = undef' => sub {
+ plan tests => 3;
+
+ t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 );
+ t::lib::Mocks::mock_preference( 'NoRefundOnLostReturnedItemsAge', undef );
+
+ my $lost_on = dt_from_string->subtract( days => 7 )->date;
+
+ my $library = $builder->build( { source => 'Branch' } );
+ my $patron = $builder->build(
+ {
+ source => 'Borrower',
+ value => { categorycode => $patron_category->{categorycode} }
+ }
+ );
+
+ my $biblionumber = $builder->build_sample_biblio(
+ {
+ branchcode => $library->{branchcode},
+ }
+ )->biblionumber;
+ my $item = $builder->build_sample_item(
+ {
+ biblionumber => $biblionumber,
+ library => $library->{branchcode},
+ replacementprice => '42.00',
+ }
+ );
+
+ # And the circulation rule
+ Koha::CirculationRules->search->delete;
+ Koha::CirculationRules->set_rules(
+ {
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
+ rules => {
+ issuelength => 14,
+ lengthunit => 'days',
+ }
+ }
+ );
+ $builder->build(
+ {
+ source => 'CirculationRule',
+ value => {
+ branchcode => undef,
+ categorycode => undef,
+ itemtype => undef,
+ rule_name => 'refund',
+ rule_value => 1
+ }
+ }
+ );
+
+ # Test with NoRefundOnLostReturnedItemsAge disabled
+ my $issue = AddIssue( $patron, $item->barcode );
+ LostItem( $item->itemnumber, 'cli', 0 );
+ $item->_result->itemlost(1);
+ $item->_result->itemlost_on( $lost_on );
+ $item->_result->update();
+
+ my $a = Koha::Account::Lines->find(
+ {
+ itemnumber => $item->id,
+ borrowernumber => $patron->{borrowernumber}
+ }
+ );
+ ok( $a, "Found accountline for lost fee" );
+ is( $a->amountoutstanding, '42.000000', "Lost fee charged correctly" );
+ my ( $doreturn, $messages ) = AddReturn( $item->barcode, $library->{branchcode}, undef, dt_from_string );
+ $a = Koha::Account::Lines->find( $a->id );
+ is( $a->amountoutstanding, '0.000000', "Lost fee was refunded" );
+};
+
+subtest 'Tests for NoRefundOnLostReturnedItemsAge > length of days item has been lost' => sub {
+ plan tests => 3;
+
+ t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 );
+ t::lib::Mocks::mock_preference( 'NoRefundOnLostReturnedItemsAge', 7 );
+
+ my $lost_on = dt_from_string->subtract( days => 6 )->date;
+
+ my $library = $builder->build( { source => 'Branch' } );
+ my $patron = $builder->build(
+ {
+ source => 'Borrower',
+ value => { categorycode => $patron_category->{categorycode} }
+ }
+ );
+
+ my $biblionumber = $builder->build_sample_biblio(
+ {
+ branchcode => $library->{branchcode},
+ }
+ )->biblionumber;
+ my $item = $builder->build_sample_item(
+ {
+ biblionumber => $biblionumber,
+ library => $library->{branchcode},
+ replacementprice => '42.00',
+ }
+ );
+
+ # And the circulation rule
+ Koha::CirculationRules->search->delete;
+ Koha::CirculationRules->set_rules(
+ {
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
+ rules => {
+ issuelength => 14,
+ lengthunit => 'days',
+ }
+ }
+ );
+ $builder->build(
+ {
+ source => 'CirculationRule',
+ value => {
+ branchcode => undef,
+ categorycode => undef,
+ itemtype => undef,
+ rule_name => 'refund',
+ rule_value => 1
+ }
+ }
+ );
+
+ # Test with NoRefundOnLostReturnedItemsAge disabled
+ my $issue = AddIssue( $patron, $item->barcode );
+ LostItem( $item->itemnumber, 'cli', 0 );
+ $item->_result->itemlost(1);
+ $item->_result->itemlost_on( $lost_on );
+ $item->_result->update();
+
+ my $a = Koha::Account::Lines->find(
+ {
+ itemnumber => $item->id,
+ borrowernumber => $patron->{borrowernumber}
+ }
+ );
+ ok( $a, "Found accountline for lost fee" );
+ is( $a->amountoutstanding, '42.000000', "Lost fee charged correctly" );
+ my ( $doreturn, $messages ) = AddReturn( $item->barcode, $library->{branchcode}, undef, dt_from_string );
+ $a = Koha::Account::Lines->find( $a->id );
+ is( $a->amountoutstanding, '0.000000', "Lost fee was refunded" );
+};
+
+subtest 'Tests for NoRefundOnLostReturnedItemsAge = length of days item has been lost' => sub {
+ plan tests => 3;
+
+ t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 );
+ t::lib::Mocks::mock_preference( 'NoRefundOnLostReturnedItemsAge', 7 );
+
+ my $lost_on = dt_from_string->subtract( days => 7 )->date;
+
+ my $library = $builder->build( { source => 'Branch' } );
+ my $patron = $builder->build(
+ {
+ source => 'Borrower',
+ value => { categorycode => $patron_category->{categorycode} }
+ }
+ );
+
+ my $biblionumber = $builder->build_sample_biblio(
+ {
+ branchcode => $library->{branchcode},
+ }
+ )->biblionumber;
+ my $item = $builder->build_sample_item(
+ {
+ biblionumber => $biblionumber,
+ library => $library->{branchcode},
+ replacementprice => '42.00',
+ }
+ );
+
+ # And the circulation rule
+ Koha::CirculationRules->search->delete;
+ Koha::CirculationRules->set_rules(
+ {
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
+ rules => {
+ issuelength => 14,
+ lengthunit => 'days',
+ }
+ }
+ );
+ $builder->build(
+ {
+ source => 'CirculationRule',
+ value => {
+ branchcode => undef,
+ categorycode => undef,
+ itemtype => undef,
+ rule_name => 'refund',
+ rule_value => 1
+ }
+ }
+ );
+
+ # Test with NoRefundOnLostReturnedItemsAge disabled
+ my $issue = AddIssue( $patron, $item->barcode );
+ LostItem( $item->itemnumber, 'cli', 0 );
+ $item->_result->itemlost(1);
+ $item->_result->itemlost_on( $lost_on );
+ $item->_result->update();
+
+ my $a = Koha::Account::Lines->find(
+ {
+ itemnumber => $item->id,
+ borrowernumber => $patron->{borrowernumber}
+ }
+ );
+ ok( $a, "Found accountline for lost fee" );
+ is( $a->amountoutstanding, '42.000000', "Lost fee charged correctly" );
+ my ( $doreturn, $messages ) = AddReturn( $item->barcode, $library->{branchcode}, undef, dt_from_string );
+ $a = Koha::Account::Lines->find( $a->id );
+ is( $a->amountoutstanding, '42.000000', "Lost fee was not refunded" );
+};
+
+subtest 'Tests for NoRefundOnLostReturnedItemsAge < length of days item has been lost' => sub {
+ plan tests => 3;
+
+ t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 );
+ t::lib::Mocks::mock_preference( 'NoRefundOnLostReturnedItemsAge', 7 );
+
+ my $lost_on = dt_from_string->subtract( days => 8 )->date;
+
+ my $library = $builder->build( { source => 'Branch' } );
+ my $patron = $builder->build(
+ {
+ source => 'Borrower',
+ value => { categorycode => $patron_category->{categorycode} }
+ }
+ );
+
+ my $biblionumber = $builder->build_sample_biblio(
+ {
+ branchcode => $library->{branchcode},
+ }
+ )->biblionumber;
+ my $item = $builder->build_sample_item(
+ {
+ biblionumber => $biblionumber,
+ library => $library->{branchcode},
+ replacementprice => '42.00',
+ }
+ );
+
+ # And the circulation rule
+ Koha::CirculationRules->search->delete;
+ Koha::CirculationRules->set_rules(
+ {
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => undef,
+ rules => {
+ issuelength => 14,
+ lengthunit => 'days',
+ }
+ }
+ );
+ $builder->build(
+ {
+ source => 'CirculationRule',
+ value => {
+ branchcode => undef,
+ categorycode => undef,
+ itemtype => undef,
+ rule_name => 'refund',
+ rule_value => 1
+ }
+ }
+ );
+
+ # Test with NoRefundOnLostReturnedItemsAge disabled
+ my $issue = AddIssue( $patron, $item->barcode );
+ LostItem( $item->itemnumber, 'cli', 0 );
+ $item->_result->itemlost(1);
+ $item->_result->itemlost_on( $lost_on );
+ $item->_result->update();
+
+ my $a = Koha::Account::Lines->find(
+ {
+ itemnumber => $item->id,
+ borrowernumber => $patron->{borrowernumber}
+ }
+ );
+ ok( $a, "Found accountline for lost fee" );
+ is( $a->amountoutstanding, '42.000000', "Lost fee charged correctly" );
+ my ( $doreturn, $messages ) = AddReturn( $item->barcode, $library->{branchcode}, undef, dt_from_string );
+ $a = Koha::Account::Lines->find( $a->id );
+ is( $a->amountoutstanding, '42.000000', "Lost fee was not refunded" );
+};
+
$schema->storage->txn_rollback;
C4::Context->clear_syspref_cache();
$branches = Koha::Libraries->search();