Lines 232-238
subtest 'apply() tests' => sub {
Link Here
|
232 |
is( $offsets->count, 1, 'Only one offset is generated' ); |
232 |
is( $offsets->count, 1, 'Only one offset is generated' ); |
233 |
$THE_offset = $offsets->next; |
233 |
$THE_offset = $offsets->next; |
234 |
is( $THE_offset->amount * 1, -90, 'Amount was calculated correctly (less than the available credit)' ); |
234 |
is( $THE_offset->amount * 1, -90, 'Amount was calculated correctly (less than the available credit)' ); |
235 |
is( $THE_offset->type, 'Credit Applied', 'Defaults to \'Credit Applied\' offset type' ); |
235 |
is( $THE_offset->type, 'APPLY', 'Defaults to \'APPLY\' offset type' ); |
236 |
|
236 |
|
237 |
$debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); |
237 |
$debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); |
238 |
throws_ok |
238 |
throws_ok |
Lines 944-950
subtest "payout() tests" => sub {
Link Here
|
944 |
|
944 |
|
945 |
subtest "reduce() tests" => sub { |
945 |
subtest "reduce() tests" => sub { |
946 |
|
946 |
|
947 |
plan tests => 29; |
947 |
plan tests => 34; |
948 |
|
948 |
|
949 |
$schema->storage->txn_begin; |
949 |
$schema->storage->txn_begin; |
950 |
|
950 |
|
Lines 1067-1078
subtest "reduce() tests" => sub {
Link Here
|
1067 |
is( $reduction->status(), 'APPLIED', "Reduction status is 'APPLIED'" ); |
1067 |
is( $reduction->status(), 'APPLIED', "Reduction status is 'APPLIED'" ); |
1068 |
|
1068 |
|
1069 |
my $offsets = Koha::Account::Offsets->search( |
1069 |
my $offsets = Koha::Account::Offsets->search( |
1070 |
{ credit_id => $reduction->id, debit_id => $debit1->id } ); |
1070 |
{ credit_id => $reduction->id } ); |
1071 |
is( $offsets->count, 1, 'Only one offset is generated' ); |
1071 |
is( $offsets->count, 2, 'Two offsets generated' ); |
1072 |
my $THE_offset = $offsets->next; |
1072 |
my $THE_offset = $offsets->next; |
|
|
1073 |
is( $THE_offset->type, 'CREATE', 'CREATE offset added for discount line'); |
1073 |
is( $THE_offset->amount * 1, |
1074 |
is( $THE_offset->amount * 1, |
1074 |
-5, 'Correct amount was applied against debit' ); |
1075 |
-5, 'Correct offset amount recorded'); |
1075 |
is( $THE_offset->type, 'DISCOUNT', "Offset type set to 'DISCOUNT'" ); |
1076 |
$THE_offset = $offsets->next; |
|
|
1077 |
is( $THE_offset->type, 'APPLY', "APPLY offset added for 'DISCOUNT'" ); |
1078 |
is( $THE_offset->amount * 1, -5, 'Correct amount offset against debt'); |
1079 |
is( $THE_offset->debit_id, $debit1->accountlines_id, 'APPLY offset recorded the correct debit_id'); |
1076 |
|
1080 |
|
1077 |
# Zero offset created when zero outstanding |
1081 |
# Zero offset created when zero outstanding |
1078 |
# (Refund another 5 on paid debt of 20) |
1082 |
# (Refund another 5 on paid debt of 20) |
Lines 1087-1098
subtest "reduce() tests" => sub {
Link Here
|
1087 |
is( $debit1->status(), 'REFUNDED', "Debit status updated to REFUNDED"); |
1091 |
is( $debit1->status(), 'REFUNDED', "Debit status updated to REFUNDED"); |
1088 |
|
1092 |
|
1089 |
$offsets = Koha::Account::Offsets->search( |
1093 |
$offsets = Koha::Account::Offsets->search( |
1090 |
{ credit_id => $reduction->id, debit_id => $debit1->id } ); |
1094 |
{ credit_id => $reduction->id } ); |
1091 |
is( $offsets->count, 1, 'Only one new offset is generated' ); |
1095 |
is( $offsets->count, 2, 'Two offsets generated' ); |
|
|
1096 |
$THE_offset = $offsets->next; |
1097 |
is( $THE_offset->type, 'CREATE', 'CREATE offset added for refund line'); |
1098 |
is( $THE_offset->amount * 1, |
1099 |
-5, 'Correct offset amount recorded'); |
1092 |
$THE_offset = $offsets->next; |
1100 |
$THE_offset = $offsets->next; |
|
|
1101 |
is( $THE_offset->type, 'APPLY', "APPLY offset added for 'REFUND'" ); |
1093 |
is( $THE_offset->amount * 1, |
1102 |
is( $THE_offset->amount * 1, |
1094 |
0, 'Zero offset created for already paid off debit' ); |
1103 |
0, 'Zero offset created for already paid off debit' ); |
1095 |
is( $THE_offset->type, 'REFUND', "Offset type set to 'REFUND'" ); |
|
|
1096 |
|
1104 |
|
1097 |
# Compound reduction should not allow more than original amount |
1105 |
# Compound reduction should not allow more than original amount |
1098 |
# (Reduction of 5 + 5 + 20 > 20) |
1106 |
# (Reduction of 5 + 5 + 20 > 20) |
Lines 1123-1129
subtest "reduce() tests" => sub {
Link Here
|
1123 |
}; |
1131 |
}; |
1124 |
|
1132 |
|
1125 |
subtest "cancel() tests" => sub { |
1133 |
subtest "cancel() tests" => sub { |
1126 |
plan tests => 16; |
1134 |
plan tests => 18; |
1127 |
|
1135 |
|
1128 |
$schema->storage->txn_begin; |
1136 |
$schema->storage->txn_begin; |
1129 |
|
1137 |
|
Lines 1209-1221
subtest "cancel() tests" => sub {
Link Here
|
1209 |
is( $account->balance() * 1, 15, "Account balance is 15" ); |
1217 |
is( $account->balance() * 1, 15, "Account balance is 15" ); |
1210 |
|
1218 |
|
1211 |
my $offsets = Koha::Account::Offsets->search( |
1219 |
my $offsets = Koha::Account::Offsets->search( |
1212 |
{ credit_id => $cancellation->id, debit_id => $debit1->id } ); |
1220 |
{ credit_id => $cancellation->id } ); |
1213 |
is( $offsets->count, 1, 'Only one offset is generated' ); |
1221 |
is( $offsets->count, 2, 'Two offsets are generated' ); |
1214 |
my $THE_offset = $offsets->next; |
1222 |
my $THE_offset = $offsets->next; |
|
|
1223 |
is( $THE_offset->type, 'CREATE', 'CREATE offset added for cancel line'); |
1224 |
is( $THE_offset->amount * 1, -10, 'Correct offset amount recorded' ); |
1225 |
$THE_offset = $offsets->next; |
1226 |
is( $THE_offset->type, 'APPLY', "APPLY offset added" ); |
1215 |
is( $THE_offset->amount * 1, |
1227 |
is( $THE_offset->amount * 1, |
1216 |
-10, 'Correct amount was applied against debit' ); |
1228 |
-10, 'Correct amount was applied against debit' ); |
1217 |
is( $THE_offset->type, 'CANCELLATION', |
|
|
1218 |
"Offset type set to 'CANCELLATION'" ); |
1219 |
|
1229 |
|
1220 |
$schema->storage->txn_rollback; |
1230 |
$schema->storage->txn_rollback; |
1221 |
}; |
1231 |
}; |
1222 |
- |
|
|