Lines 138-144
subtest 'store' => sub {
Link Here
|
138 |
}; |
138 |
}; |
139 |
|
139 |
|
140 |
subtest '_lost_found_trigger' => sub { |
140 |
subtest '_lost_found_trigger' => sub { |
141 |
plan tests => 7; |
141 |
plan tests => 10; |
142 |
|
142 |
|
143 |
t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 ); |
143 |
t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 ); |
144 |
t::lib::Mocks::mock_preference( 'WhenLostForgiveFine', 0 ); |
144 |
t::lib::Mocks::mock_preference( 'WhenLostForgiveFine', 0 ); |
Lines 761-766
subtest 'store' => sub {
Link Here
|
761 |
|
761 |
|
762 |
}; |
762 |
}; |
763 |
|
763 |
|
|
|
764 |
subtest 'restore fine | no overdue' => sub { |
765 |
|
766 |
plan tests => 8; |
767 |
|
768 |
my $manager = |
769 |
$builder->build_object( { class => "Koha::Patrons" } ); |
770 |
t::lib::Mocks::mock_userenv( |
771 |
{ patron => $manager, branchcode => $manager->branchcode } ); |
772 |
|
773 |
# Set lostreturn_policy to 'restore' for tests |
774 |
my $specific_rule_restore = $builder->build( |
775 |
{ |
776 |
source => 'CirculationRule', |
777 |
value => { |
778 |
branchcode => $manager->branchcode, |
779 |
categorycode => undef, |
780 |
itemtype => undef, |
781 |
rule_name => 'lostreturn', |
782 |
rule_value => 'restore' |
783 |
} |
784 |
} |
785 |
); |
786 |
|
787 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
788 |
|
789 |
my $item = $builder->build_sample_item( |
790 |
{ |
791 |
biblionumber => $biblio->biblionumber, |
792 |
library => $library->branchcode, |
793 |
replacementprice => $replacement_amount, |
794 |
itype => $item_type->itemtype |
795 |
} |
796 |
); |
797 |
|
798 |
my $issue = |
799 |
C4::Circulation::AddIssue( $patron->unblessed, $item->barcode ); |
800 |
|
801 |
# Simulate item marked as lost |
802 |
$item->itemlost(1)->store; |
803 |
C4::Circulation::LostItem( $item->itemnumber, 1 ); |
804 |
|
805 |
my $processing_fee_lines = Koha::Account::Lines->search( |
806 |
{ |
807 |
borrowernumber => $patron->id, |
808 |
itemnumber => $item->itemnumber, |
809 |
debit_type_code => 'PROCESSING' |
810 |
} |
811 |
); |
812 |
is( $processing_fee_lines->count, |
813 |
1, 'Only one processing fee produced' ); |
814 |
my $processing_fee_line = $processing_fee_lines->next; |
815 |
is( $processing_fee_line->amount + 0, |
816 |
$processfee_amount, |
817 |
'The right PROCESSING amount is generated' ); |
818 |
is( $processing_fee_line->amountoutstanding + 0, |
819 |
$processfee_amount, |
820 |
'The right PROCESSING amountoutstanding is generated' ); |
821 |
|
822 |
my $lost_fee_lines = Koha::Account::Lines->search( |
823 |
{ |
824 |
borrowernumber => $patron->id, |
825 |
itemnumber => $item->itemnumber, |
826 |
debit_type_code => 'LOST' |
827 |
} |
828 |
); |
829 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
830 |
my $lost_fee_line = $lost_fee_lines->next; |
831 |
is( $lost_fee_line->amount + 0, |
832 |
$replacement_amount, 'The right LOST amount is generated' ); |
833 |
is( $lost_fee_line->amountoutstanding + 0, |
834 |
$replacement_amount, |
835 |
'The right LOST amountountstanding is generated' ); |
836 |
|
837 |
my $account = $patron->account; |
838 |
my $debts = $account->outstanding_debits; |
839 |
|
840 |
# Pay off the debt |
841 |
my $credit = $account->add_credit( |
842 |
{ |
843 |
amount => $account->balance, |
844 |
type => 'PAYMENT', |
845 |
interface => 'test', |
846 |
} |
847 |
); |
848 |
$credit->apply( |
849 |
{ debits => [ $debts->as_list ], offset_type => 'Payment' } ); |
850 |
|
851 |
# Simulate item marked as found |
852 |
$item->itemlost(0)->store; |
853 |
is( $item->{_refunded}, 1, 'Refund triggered' ); |
854 |
is( $item->{_restored}, undef, 'Restore not triggered when there is no overdue fine found' ); |
855 |
}; |
856 |
|
857 |
subtest 'restore fine | unforgiven overdue' => sub { |
858 |
|
859 |
plan tests => 10; |
860 |
|
861 |
# Set lostreturn_policy to 'restore' for tests |
862 |
my $manager = |
863 |
$builder->build_object( { class => "Koha::Patrons" } ); |
864 |
t::lib::Mocks::mock_userenv( |
865 |
{ patron => $manager, branchcode => $manager->branchcode } ); |
866 |
my $specific_rule_restore = $builder->build( |
867 |
{ |
868 |
source => 'CirculationRule', |
869 |
value => { |
870 |
branchcode => $manager->branchcode, |
871 |
categorycode => undef, |
872 |
itemtype => undef, |
873 |
rule_name => 'lostreturn', |
874 |
rule_value => 'restore' |
875 |
} |
876 |
} |
877 |
); |
878 |
|
879 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
880 |
|
881 |
my $item = $builder->build_sample_item( |
882 |
{ |
883 |
biblionumber => $biblio->biblionumber, |
884 |
library => $library->branchcode, |
885 |
replacementprice => $replacement_amount, |
886 |
itype => $item_type->itemtype |
887 |
} |
888 |
); |
889 |
|
890 |
my $issue = |
891 |
C4::Circulation::AddIssue( $patron->unblessed, $item->barcode ); |
892 |
|
893 |
# Simulate item marked as lost |
894 |
$item->itemlost(1)->store; |
895 |
C4::Circulation::LostItem( $item->itemnumber, 1 ); |
896 |
|
897 |
my $processing_fee_lines = Koha::Account::Lines->search( |
898 |
{ |
899 |
borrowernumber => $patron->id, |
900 |
itemnumber => $item->itemnumber, |
901 |
debit_type_code => 'PROCESSING' |
902 |
} |
903 |
); |
904 |
is( $processing_fee_lines->count, |
905 |
1, 'Only one processing fee produced' ); |
906 |
my $processing_fee_line = $processing_fee_lines->next; |
907 |
is( $processing_fee_line->amount + 0, |
908 |
$processfee_amount, |
909 |
'The right PROCESSING amount is generated' ); |
910 |
is( $processing_fee_line->amountoutstanding + 0, |
911 |
$processfee_amount, |
912 |
'The right PROCESSING amountoutstanding is generated' ); |
913 |
|
914 |
my $lost_fee_lines = Koha::Account::Lines->search( |
915 |
{ |
916 |
borrowernumber => $patron->id, |
917 |
itemnumber => $item->itemnumber, |
918 |
debit_type_code => 'LOST' |
919 |
} |
920 |
); |
921 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
922 |
my $lost_fee_line = $lost_fee_lines->next; |
923 |
is( $lost_fee_line->amount + 0, |
924 |
$replacement_amount, 'The right LOST amount is generated' ); |
925 |
is( $lost_fee_line->amountoutstanding + 0, |
926 |
$replacement_amount, |
927 |
'The right LOST amountountstanding is generated' ); |
928 |
|
929 |
my $account = $patron->account; |
930 |
my $debts = $account->outstanding_debits; |
931 |
|
932 |
# Pay off the debt |
933 |
my $credit = $account->add_credit( |
934 |
{ |
935 |
amount => $account->balance, |
936 |
type => 'PAYMENT', |
937 |
interface => 'test', |
938 |
} |
939 |
); |
940 |
$credit->apply( |
941 |
{ debits => [ $debts->as_list ], offset_type => 'Payment' } ); |
942 |
|
943 |
# Fine not forgiven |
944 |
my $overdue = $account->add_debit( |
945 |
{ |
946 |
amount => 30.00, |
947 |
user_id => $manager->borrowernumber, |
948 |
library_id => $library->branchcode, |
949 |
interface => 'test', |
950 |
item_id => $item->itemnumber, |
951 |
type => 'OVERDUE', |
952 |
} |
953 |
)->store(); |
954 |
$overdue->status('LOST')->store(); |
955 |
$overdue->discard_changes; |
956 |
is( $overdue->status, 'LOST', |
957 |
'Overdue status set to LOST' ); |
958 |
|
959 |
# Simulate item marked as found |
960 |
$item->itemlost(0)->store; |
961 |
is( $item->{_refunded}, 1, 'Refund triggered' ); |
962 |
is( $item->{_restored}, undef, 'Restore not triggered when overdue was not forgiven' ); |
963 |
$overdue->discard_changes; |
964 |
is( $overdue->status, 'FOUND', |
965 |
'Overdue status updated to FOUND' ); |
966 |
}; |
967 |
|
968 |
subtest 'restore fine | forgiven overdue' => sub { |
969 |
|
970 |
plan tests => 12; |
971 |
|
972 |
# Set lostreturn_policy to 'restore' for tests |
973 |
my $manager = |
974 |
$builder->build_object( { class => "Koha::Patrons" } ); |
975 |
t::lib::Mocks::mock_userenv( |
976 |
{ patron => $manager, branchcode => $manager->branchcode } ); |
977 |
my $specific_rule_restore = $builder->build( |
978 |
{ |
979 |
source => 'CirculationRule', |
980 |
value => { |
981 |
branchcode => $manager->branchcode, |
982 |
categorycode => undef, |
983 |
itemtype => undef, |
984 |
rule_name => 'lostreturn', |
985 |
rule_value => 'restore' |
986 |
} |
987 |
} |
988 |
); |
989 |
|
990 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
991 |
|
992 |
my $item = $builder->build_sample_item( |
993 |
{ |
994 |
biblionumber => $biblio->biblionumber, |
995 |
library => $library->branchcode, |
996 |
replacementprice => $replacement_amount, |
997 |
itype => $item_type->itemtype |
998 |
} |
999 |
); |
1000 |
|
1001 |
my $issue = |
1002 |
C4::Circulation::AddIssue( $patron->unblessed, $item->barcode ); |
1003 |
|
1004 |
# Simulate item marked as lost |
1005 |
$item->itemlost(1)->store; |
1006 |
C4::Circulation::LostItem( $item->itemnumber, 1 ); |
1007 |
|
1008 |
my $processing_fee_lines = Koha::Account::Lines->search( |
1009 |
{ |
1010 |
borrowernumber => $patron->id, |
1011 |
itemnumber => $item->itemnumber, |
1012 |
debit_type_code => 'PROCESSING' |
1013 |
} |
1014 |
); |
1015 |
is( $processing_fee_lines->count, |
1016 |
1, 'Only one processing fee produced' ); |
1017 |
my $processing_fee_line = $processing_fee_lines->next; |
1018 |
is( $processing_fee_line->amount + 0, |
1019 |
$processfee_amount, |
1020 |
'The right PROCESSING amount is generated' ); |
1021 |
is( $processing_fee_line->amountoutstanding + 0, |
1022 |
$processfee_amount, |
1023 |
'The right PROCESSING amountoutstanding is generated' ); |
1024 |
|
1025 |
my $lost_fee_lines = Koha::Account::Lines->search( |
1026 |
{ |
1027 |
borrowernumber => $patron->id, |
1028 |
itemnumber => $item->itemnumber, |
1029 |
debit_type_code => 'LOST' |
1030 |
} |
1031 |
); |
1032 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
1033 |
my $lost_fee_line = $lost_fee_lines->next; |
1034 |
is( $lost_fee_line->amount + 0, |
1035 |
$replacement_amount, 'The right LOST amount is generated' ); |
1036 |
is( $lost_fee_line->amountoutstanding + 0, |
1037 |
$replacement_amount, |
1038 |
'The right LOST amountountstanding is generated' ); |
1039 |
|
1040 |
my $account = $patron->account; |
1041 |
my $debts = $account->outstanding_debits; |
1042 |
|
1043 |
# Pay off the debt |
1044 |
my $credit = $account->add_credit( |
1045 |
{ |
1046 |
amount => $account->balance, |
1047 |
type => 'PAYMENT', |
1048 |
interface => 'test', |
1049 |
} |
1050 |
); |
1051 |
$credit->apply( |
1052 |
{ debits => [ $debts->as_list ], offset_type => 'Payment' } ); |
1053 |
|
1054 |
# Add overdue |
1055 |
my $overdue = $account->add_debit( |
1056 |
{ |
1057 |
amount => 30.00, |
1058 |
user_id => $manager->borrowernumber, |
1059 |
library_id => $library->branchcode, |
1060 |
interface => 'test', |
1061 |
item_id => $item->itemnumber, |
1062 |
type => 'OVERDUE', |
1063 |
} |
1064 |
)->store(); |
1065 |
$overdue->status('LOST')->store(); |
1066 |
is( $overdue->status, 'LOST', |
1067 |
'Overdue status set to LOST' ); |
1068 |
|
1069 |
# Forgive fine |
1070 |
$credit = $account->add_credit( |
1071 |
{ |
1072 |
amount => 30.00, |
1073 |
user_id => $manager->borrowernumber, |
1074 |
library_id => $library->branchcode, |
1075 |
interface => 'test', |
1076 |
type => 'FORGIVEN', |
1077 |
item_id => $item->itemnumber |
1078 |
} |
1079 |
); |
1080 |
$credit->apply( |
1081 |
{ debits => [$overdue], offset_type => 'Forgiven' } ); |
1082 |
|
1083 |
# Simulate item marked as found |
1084 |
$item->itemlost(0)->store; |
1085 |
is( $item->{_refunded}, 1, 'Refund triggered' ); |
1086 |
is( $item->{_restored}, 1, 'Restore triggered when overdue was forgiven' ); |
1087 |
$overdue->discard_changes; |
1088 |
is( $overdue->status, 'FOUND', 'Overdue status updated to FOUND' ); |
1089 |
is( $overdue->amountoutstanding, $overdue->amount, 'Overdue outstanding has been restored' ); |
1090 |
$credit->discard_changes; |
1091 |
is( $credit->status, 'VOID', 'Overdue Forgival has been marked as VOID'); |
1092 |
}; |
1093 |
|
764 |
subtest 'Continue when userenv is not set' => sub { |
1094 |
subtest 'Continue when userenv is not set' => sub { |
765 |
plan tests => 1; |
1095 |
plan tests => 1; |
766 |
|
1096 |
|
767 |
- |
|
|