Lines 1076-1079
subtest "reduce() tests" => sub {
Link Here
|
1076 |
$schema->storage->txn_rollback; |
1076 |
$schema->storage->txn_rollback; |
1077 |
}; |
1077 |
}; |
1078 |
|
1078 |
|
|
|
1079 |
subtest "cancel() tests" => sub { |
1080 |
plan tests => 9; |
1081 |
|
1082 |
$schema->storage->txn_begin; |
1083 |
|
1084 |
# Create a borrower |
1085 |
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; |
1086 |
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; |
1087 |
|
1088 |
my $borrower = Koha::Patron->new( { |
1089 |
cardnumber => 'dariahall', |
1090 |
surname => 'Hall', |
1091 |
firstname => 'Daria', |
1092 |
} ); |
1093 |
$borrower->categorycode( $categorycode ); |
1094 |
$borrower->branchcode( $branchcode ); |
1095 |
$borrower->store; |
1096 |
|
1097 |
t::lib::Mocks::mock_userenv({ branchcode => $branchcode, borrowernumber => $borrower->borrowernumber }); |
1098 |
|
1099 |
my $account = Koha::Account->new({ patron_id => $borrower->id }); |
1100 |
|
1101 |
my $line1 = Koha::Account::Line->new( |
1102 |
{ |
1103 |
borrowernumber => $borrower->borrowernumber, |
1104 |
amount => 10, |
1105 |
amountoutstanding => 10, |
1106 |
interface => 'commandline', |
1107 |
debit_type_code => 'OVERDUE', |
1108 |
} |
1109 |
)->store(); |
1110 |
my $line2 = Koha::Account::Line->new( |
1111 |
{ |
1112 |
borrowernumber => $borrower->borrowernumber, |
1113 |
amount => 20, |
1114 |
amountoutstanding => 20, |
1115 |
interface => 'commandline', |
1116 |
debit_type_code => 'OVERDUE', |
1117 |
} |
1118 |
)->store(); |
1119 |
|
1120 |
my $id = $account->pay({ |
1121 |
lines => [$line2], |
1122 |
amount => 5, |
1123 |
}); |
1124 |
|
1125 |
is( $account->balance(), 25, "Account balance is 25" ); |
1126 |
is( $line1->amountoutstanding+0, 10, 'First fee has amount outstanding of 10' ); |
1127 |
is( $line2->amountoutstanding+0, 15, 'Second fee has amount outstanding of 15' ); |
1128 |
|
1129 |
my $ret = $line1->cancel(); |
1130 |
is( ref($ret), 'Koha::Account::Line', 'Cancel returns the account line' ); |
1131 |
is( $account->balance(), 15, "Account balance is 15" ); |
1132 |
is( $line1->amount+0, 0, 'First fee has amount of 0' ); |
1133 |
is( $line1->amountoutstanding+0, 0, 'First fee has amount outstanding of 0' ); |
1134 |
|
1135 |
$ret = $line2->cancel(); |
1136 |
is ($ret, undef, 'cancel returns undef when line cannot be cancelled'); |
1137 |
|
1138 |
my $account_payment = Koha::Account::Lines->find($id); |
1139 |
$ret = $account_payment->cancel(); |
1140 |
is ($ret, undef, 'payment cannot be cancelled'); |
1141 |
|
1142 |
$schema->storage->txn_rollback; |
1143 |
}; |
1144 |
|
1079 |
1; |
1145 |
1; |
1080 |
- |
|
|