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 978-984
subtest "payout() tests" => sub {
Link Here
|
978 |
|
978 |
|
979 |
subtest "reduce() tests" => sub { |
979 |
subtest "reduce() tests" => sub { |
980 |
|
980 |
|
981 |
plan tests => 29; |
981 |
plan tests => 34; |
982 |
|
982 |
|
983 |
$schema->storage->txn_begin; |
983 |
$schema->storage->txn_begin; |
984 |
|
984 |
|
Lines 1101-1112
subtest "reduce() tests" => sub {
Link Here
|
1101 |
is( $reduction->status(), 'APPLIED', "Reduction status is 'APPLIED'" ); |
1101 |
is( $reduction->status(), 'APPLIED', "Reduction status is 'APPLIED'" ); |
1102 |
|
1102 |
|
1103 |
my $offsets = Koha::Account::Offsets->search( |
1103 |
my $offsets = Koha::Account::Offsets->search( |
1104 |
{ credit_id => $reduction->id, debit_id => $debit1->id } ); |
1104 |
{ credit_id => $reduction->id } ); |
1105 |
is( $offsets->count, 1, 'Only one offset is generated' ); |
1105 |
is( $offsets->count, 2, 'Two offsets generated' ); |
1106 |
my $THE_offset = $offsets->next; |
1106 |
my $THE_offset = $offsets->next; |
|
|
1107 |
is( $THE_offset->type, 'CREATE', 'CREATE offset added for discount line'); |
1107 |
is( $THE_offset->amount * 1, |
1108 |
is( $THE_offset->amount * 1, |
1108 |
-5, 'Correct amount was applied against debit' ); |
1109 |
-5, 'Correct offset amount recorded'); |
1109 |
is( $THE_offset->type, 'DISCOUNT', "Offset type set to 'DISCOUNT'" ); |
1110 |
$THE_offset = $offsets->next; |
|
|
1111 |
is( $THE_offset->type, 'APPLY', "APPLY offset added for 'DISCOUNT'" ); |
1112 |
is( $THE_offset->amount * 1, -5, 'Correct amount offset against debt'); |
1113 |
is( $THE_offset->debit_id, $debit1->accountlines_id, 'APPLY offset recorded the correct debit_id'); |
1110 |
|
1114 |
|
1111 |
# Zero offset created when zero outstanding |
1115 |
# Zero offset created when zero outstanding |
1112 |
# (Refund another 5 on paid debt of 20) |
1116 |
# (Refund another 5 on paid debt of 20) |
Lines 1121-1132
subtest "reduce() tests" => sub {
Link Here
|
1121 |
is( $debit1->status(), 'REFUNDED', "Debit status updated to REFUNDED"); |
1125 |
is( $debit1->status(), 'REFUNDED', "Debit status updated to REFUNDED"); |
1122 |
|
1126 |
|
1123 |
$offsets = Koha::Account::Offsets->search( |
1127 |
$offsets = Koha::Account::Offsets->search( |
1124 |
{ credit_id => $reduction->id, debit_id => $debit1->id } ); |
1128 |
{ credit_id => $reduction->id } ); |
1125 |
is( $offsets->count, 1, 'Only one new offset is generated' ); |
1129 |
is( $offsets->count, 2, 'Two offsets generated' ); |
|
|
1130 |
$THE_offset = $offsets->next; |
1131 |
is( $THE_offset->type, 'CREATE', 'CREATE offset added for refund line'); |
1132 |
is( $THE_offset->amount * 1, |
1133 |
-5, 'Correct offset amount recorded'); |
1126 |
$THE_offset = $offsets->next; |
1134 |
$THE_offset = $offsets->next; |
|
|
1135 |
is( $THE_offset->type, 'APPLY', "APPLY offset added for 'REFUND'" ); |
1127 |
is( $THE_offset->amount * 1, |
1136 |
is( $THE_offset->amount * 1, |
1128 |
0, 'Zero offset created for already paid off debit' ); |
1137 |
0, 'Zero offset created for already paid off debit' ); |
1129 |
is( $THE_offset->type, 'REFUND', "Offset type set to 'REFUND'" ); |
|
|
1130 |
|
1138 |
|
1131 |
# Compound reduction should not allow more than original amount |
1139 |
# Compound reduction should not allow more than original amount |
1132 |
# (Reduction of 5 + 5 + 20 > 20) |
1140 |
# (Reduction of 5 + 5 + 20 > 20) |
Lines 1157-1163
subtest "reduce() tests" => sub {
Link Here
|
1157 |
}; |
1165 |
}; |
1158 |
|
1166 |
|
1159 |
subtest "cancel() tests" => sub { |
1167 |
subtest "cancel() tests" => sub { |
1160 |
plan tests => 16; |
1168 |
plan tests => 18; |
1161 |
|
1169 |
|
1162 |
$schema->storage->txn_begin; |
1170 |
$schema->storage->txn_begin; |
1163 |
|
1171 |
|
Lines 1243-1255
subtest "cancel() tests" => sub {
Link Here
|
1243 |
is( $account->balance() * 1, 15, "Account balance is 15" ); |
1251 |
is( $account->balance() * 1, 15, "Account balance is 15" ); |
1244 |
|
1252 |
|
1245 |
my $offsets = Koha::Account::Offsets->search( |
1253 |
my $offsets = Koha::Account::Offsets->search( |
1246 |
{ credit_id => $cancellation->id, debit_id => $debit1->id } ); |
1254 |
{ credit_id => $cancellation->id } ); |
1247 |
is( $offsets->count, 1, 'Only one offset is generated' ); |
1255 |
is( $offsets->count, 2, 'Two offsets are generated' ); |
1248 |
my $THE_offset = $offsets->next; |
1256 |
my $THE_offset = $offsets->next; |
|
|
1257 |
is( $THE_offset->type, 'CREATE', 'CREATE offset added for cancel line'); |
1258 |
is( $THE_offset->amount * 1, -10, 'Correct offset amount recorded' ); |
1259 |
$THE_offset = $offsets->next; |
1260 |
is( $THE_offset->type, 'APPLY', "APPLY offset added" ); |
1249 |
is( $THE_offset->amount * 1, |
1261 |
is( $THE_offset->amount * 1, |
1250 |
-10, 'Correct amount was applied against debit' ); |
1262 |
-10, 'Correct amount was applied against debit' ); |
1251 |
is( $THE_offset->type, 'CANCELLATION', |
|
|
1252 |
"Offset type set to 'CANCELLATION'" ); |
1253 |
|
1263 |
|
1254 |
$schema->storage->txn_rollback; |
1264 |
$schema->storage->txn_rollback; |
1255 |
}; |
1265 |
}; |
1256 |
- |
|
|