Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 3; |
22 |
use Test::More tests => 4; |
23 |
|
23 |
|
24 |
use Koha::Account; |
24 |
use Koha::Account; |
25 |
use Koha::Account::Lines; |
25 |
use Koha::Account::Lines; |
Lines 191-193
subtest 'add_credit() tests' => sub {
Link Here
|
191 |
|
191 |
|
192 |
$schema->storage->txn_rollback; |
192 |
$schema->storage->txn_rollback; |
193 |
}; |
193 |
}; |
194 |
- |
194 |
|
|
|
195 |
subtest 'normalize_balance' => sub { |
196 |
|
197 |
plan tests => 3; |
198 |
|
199 |
subtest 'more credit than debit' => sub { |
200 |
|
201 |
plan tests => 6; |
202 |
|
203 |
$schema->storage->txn_begin; |
204 |
|
205 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
206 |
my $account = $patron->account; |
207 |
|
208 |
# Add Credits |
209 |
$account->add_credit({ amount => 1 }); |
210 |
$account->add_credit({ amount => 2 }); |
211 |
$account->add_credit({ amount => 3 }); |
212 |
$account->add_credit({ amount => 4 }); |
213 |
$account->add_credit({ amount => 5 }); |
214 |
|
215 |
# Add Debits TODO: replace for calls to add_debit when time comes |
216 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store; |
217 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store; |
218 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store; |
219 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store; |
220 |
|
221 |
# Paid Off |
222 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; |
223 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; |
224 |
|
225 |
is( $account->balance(), -5, "Account balance is -5" ); |
226 |
is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' ); |
227 |
is( $account->outstanding_credits->total_outstanding, -15, 'Outstanding credits sum -15' ); |
228 |
|
229 |
$account->normalize_balance(); |
230 |
|
231 |
is( $account->balance(), -5, "Account balance is -5" ); |
232 |
is( $account->outstanding_debits->total_outstanding, 0, 'No outstanding debits' ); |
233 |
is( $account->outstanding_credits->total_outstanding, -5, 'Outstanding credits sum -5' ); |
234 |
|
235 |
$schema->storage->txn_rollback; |
236 |
}; |
237 |
|
238 |
subtest 'same debit than credit' => sub { |
239 |
|
240 |
plan tests => 6; |
241 |
|
242 |
$schema->storage->txn_begin; |
243 |
|
244 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
245 |
my $account = $patron->account; |
246 |
|
247 |
# Add Credits |
248 |
$account->add_credit({ amount => 1 }); |
249 |
$account->add_credit({ amount => 2 }); |
250 |
$account->add_credit({ amount => 3 }); |
251 |
$account->add_credit({ amount => 4 }); |
252 |
|
253 |
# Add Debits TODO: replace for calls to add_debit when time comes |
254 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store; |
255 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store; |
256 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store; |
257 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store; |
258 |
|
259 |
# Paid Off |
260 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; |
261 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; |
262 |
|
263 |
is( $account->balance(), 0, "Account balance is 0" ); |
264 |
is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' ); |
265 |
is( $account->outstanding_credits->total_outstanding, -10, 'Outstanding credits sum -10' ); |
266 |
|
267 |
$account->normalize_balance(); |
268 |
|
269 |
is( $account->balance(), 0, "Account balance is 0" ); |
270 |
is( $account->outstanding_debits->total_outstanding, 0, 'No outstanding debits' ); |
271 |
is( $account->outstanding_credits->total_outstanding, 0, 'Outstanding credits sum 0' ); |
272 |
|
273 |
$schema->storage->txn_rollback; |
274 |
}; |
275 |
|
276 |
subtest 'more debit than credit' => sub { |
277 |
|
278 |
plan tests => 6; |
279 |
|
280 |
$schema->storage->txn_begin; |
281 |
|
282 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
283 |
my $account = $patron->account; |
284 |
|
285 |
# Add Credits |
286 |
$account->add_credit({ amount => 1 }); |
287 |
$account->add_credit({ amount => 2 }); |
288 |
$account->add_credit({ amount => 3 }); |
289 |
$account->add_credit({ amount => 4 }); |
290 |
|
291 |
# Add Debits TODO: replace for calls to add_debit when time comes |
292 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store; |
293 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store; |
294 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store; |
295 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store; |
296 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 5, amountoutstanding => 5 })->store; |
297 |
|
298 |
# Paid Off |
299 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; |
300 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; |
301 |
|
302 |
is( $account->balance(), 5, "Account balance is 5" ); |
303 |
is( $account->outstanding_debits->total_outstanding, 15, 'Outstanding debits sum 15' ); |
304 |
is( $account->outstanding_credits->total_outstanding, -10, 'Outstanding credits sum -10' ); |
305 |
|
306 |
$account->normalize_balance(); |
307 |
|
308 |
is( $account->balance(), 5, "Account balance is 5" ); |
309 |
is( $account->outstanding_debits->total_outstanding, 5, 'Outstanding debits sum 5' ); |
310 |
is( $account->outstanding_credits->total_outstanding, 0, 'Outstanding credits sum 0' ); |
311 |
|
312 |
$schema->storage->txn_rollback; |
313 |
}; |
314 |
}; |