View | Details | Raw Unified | Return to bug 22600
Collapse All | Expand All

(-)a/C4/Accounts.pm (+1 lines)
Lines 166-171 sub manualinvoice { Link Here
166
            itemnumber        => $itemnum || undef,
166
            itemnumber        => $itemnum || undef,
167
            note              => $note,
167
            note              => $note,
168
            manager_id        => $manager_id,
168
            manager_id        => $manager_id,
169
            interface         => C4::Context->interface,
169
            branchcode        => $branchcode,
170
            branchcode        => $branchcode,
170
        }
171
        }
171
    )->store();
172
    )->store();
(-)a/t/db_dependent/Accounts.t (-37 / +38 lines)
Lines 68-73 $context->mock( 'userenv', sub { Link Here
68
        branch => $branchcode,
68
        branch => $branchcode,
69
    };
69
    };
70
});
70
});
71
$context->mock( 'interface', sub { return "commandline" } );
71
my $userenv_branchcode = $branchcode;
72
my $userenv_branchcode = $branchcode;
72
73
73
# Test manualinvoice
74
# Test manualinvoice
Lines 109-117 my $sth = $dbh->prepare( Link Here
109
         borrowernumber,
110
         borrowernumber,
110
         amountoutstanding,
111
         amountoutstanding,
111
         date,
112
         date,
112
         description
113
         description,
114
         interface
113
     )
115
     )
114
     VALUES ( ?, ?, (select date_sub(CURRENT_DATE, INTERVAL ? DAY) ), ? )"
116
     VALUES ( ?, ?, (select date_sub(CURRENT_DATE, INTERVAL ? DAY) ), ?, ? )"
115
);
117
);
116
118
117
my $days = 5;
119
my $days = 5;
Lines 133-139 my $categorycode = $builder->build({ source => 'Category' })->{categorycode}; Link Here
133
my $borrower = Koha::Patron->new( { firstname => 'Test', surname => 'Patron', categorycode => $categorycode, branchcode => $branchcode } )->store();
135
my $borrower = Koha::Patron->new( { firstname => 'Test', surname => 'Patron', categorycode => $categorycode, branchcode => $branchcode } )->store();
134
136
135
for my $data ( @test_data ) {
137
for my $data ( @test_data ) {
136
    $sth->execute($borrower->borrowernumber, $data->{amount}, $data->{days_ago}, $data->{description});
138
    $sth->execute($borrower->borrowernumber, $data->{amount}, $data->{days_ago}, $data->{description}, 'commandline');
137
}
139
}
138
140
139
purge_zero_balance_fees( $days );
141
purge_zero_balance_fees( $days );
Lines 178-185 subtest "Koha::Account::pay tests" => sub { Link Here
178
180
179
    my $account = Koha::Account->new({ patron_id => $borrower->id });
181
    my $account = Koha::Account->new({ patron_id => $borrower->id });
180
182
181
    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 100 })->store();
183
    my $line1 = $account->add_debit({ type => 'account', amount => 100, interface => 'commandline' });
182
    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 200 })->store();
184
    my $line2 = $account->add_debit({ type => 'account', amount => 200, interface => 'commandline' });
183
185
184
    $sth = $dbh->prepare("SELECT count(*) FROM accountlines");
186
    $sth = $dbh->prepare("SELECT count(*) FROM accountlines");
185
    $sth->execute;
187
    $sth->execute;
Lines 278-284 subtest "Koha::Account::pay tests" => sub { Link Here
278
    $note = $sth->fetchrow_array;
280
    $note = $sth->fetchrow_array;
279
    is($note,'$200.00 payment note', '$200.00 payment note is registered');
281
    is($note,'$200.00 payment note', '$200.00 payment note is registered');
280
282
281
    my $line3 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 42, accounttype => 'TEST' })->store();
283
    my $line3 = $account->add_debit({ type => 'account', amount => 42, interface => 'commandline' });
282
    my $payment_id = $account->pay( { lines => [$line3], amount => 42 } );
284
    my $payment_id = $account->pay( { lines => [$line3], amount => 42 } );
283
    my $payment = Koha::Account::Lines->find( $payment_id );
285
    my $payment = Koha::Account::Lines->find( $payment_id );
284
    is( $payment->amount(), '-42.000000', "Payment paid the specified fine" );
286
    is( $payment->amount(), '-42.000000', "Payment paid the specified fine" );
Lines 306-315 subtest "Koha::Account::pay particular line tests" => sub { Link Here
306
308
307
    my $account = Koha::Account->new({ patron_id => $borrower->id });
309
    my $account = Koha::Account->new({ patron_id => $borrower->id });
308
310
309
    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 1 })->store();
311
    my $line1 = $account->add_debit({ type => 'account', amount => 1, interface => 'commandline' });
310
    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 2 })->store();
312
    my $line2 = $account->add_debit({ type => 'account', amount => 2, interface => 'commandline' });
311
    my $line3 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 3 })->store();
313
    my $line3 = $account->add_debit({ type => 'account', amount => 3, interface => 'commandline' });
312
    my $line4 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 4 })->store();
314
    my $line4 = $account->add_debit({ type => 'account', amount => 4, interface => 'commandline' });
313
315
314
    is( $account->balance(), 10, "Account balance is 10" );
316
    is( $account->balance(), 10, "Account balance is 10" );
315
317
Lines 351-357 subtest "Koha::Account::pay writeoff tests" => sub { Link Here
351
353
352
    my $account = Koha::Account->new({ patron_id => $borrower->id });
354
    my $account = Koha::Account->new({ patron_id => $borrower->id });
353
355
354
    my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 42 })->store();
356
    my $line = $account->add_debit({ type => 'account', amount => 42, interface => 'commandline' });
355
357
356
    is( $account->balance(), 42, "Account balance is 42" );
358
    is( $account->balance(), 42, "Account balance is 42" );
357
359
Lines 747-775 subtest "Koha::Account::non_issues_charges tests" => sub { Link Here
747
    plan tests => 21;
749
    plan tests => 21;
748
750
749
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
751
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
752
    my $account = $patron->account;
750
753
751
    my $today  = dt_from_string;
754
    my $today  = dt_from_string;
752
    my $res    = 3;
755
    my $res    = 3;
753
    my $rent   = 5;
756
    my $rent   = 5;
754
    my $manual = 7;
757
    my $manual = 7;
755
    Koha::Account::Line->new(
758
    $account->add_debit(
756
        {
759
        {
757
            borrowernumber    => $patron->borrowernumber,
760
            description => 'a Res fee',
758
            date              => $today,
761
            type        => 'reserve',
759
            description       => 'a Res fee',
762
            amount      => $res,
760
            accounttype       => 'Res',
763
            interface   => 'commandline'
761
            amountoutstanding => $res,
762
        }
764
        }
763
    )->store;
765
    );
764
    Koha::Account::Line->new(
766
    $account->add_debit(
765
        {
767
        {
766
            borrowernumber    => $patron->borrowernumber,
768
            description => 'a Rental fee',
767
            date              => $today,
769
            type        => 'rent',
768
            description       => 'a Rental fee',
770
            amount      => $rent,
769
            accounttype       => 'Rent',
771
            interface   => 'commandline'
770
            amountoutstanding => $rent,
771
        }
772
        }
772
    )->store;
773
    );
773
    Koha::Account::Line->new(
774
    Koha::Account::Line->new(
774
        {
775
        {
775
            borrowernumber    => $patron->borrowernumber,
776
            borrowernumber    => $patron->borrowernumber,
Lines 777-782 subtest "Koha::Account::non_issues_charges tests" => sub { Link Here
777
            description       => 'a Manual invoice fee',
778
            description       => 'a Manual invoice fee',
778
            accounttype       => 'Copie',
779
            accounttype       => 'Copie',
779
            amountoutstanding => $manual,
780
            amountoutstanding => $manual,
781
            interface         => 'commandline'
780
        }
782
        }
781
    )->store;
783
    )->store;
782
    Koha::AuthorisedValue->new(
784
    Koha::AuthorisedValue->new(
Lines 787-793 subtest "Koha::Account::non_issues_charges tests" => sub { Link Here
787
        }
789
        }
788
    )->store;
790
    )->store;
789
791
790
    my $account = $patron->account;
791
792
792
    t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge',   0 );
793
    t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge',   0 );
793
    t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 );
794
    t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 );
Lines 925-932 subtest "Koha::Account::non_issues_charges tests" => sub { Link Here
925
        }
926
        }
926
    );
927
    );
927
928
928
    my $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0 })->store();
929
    my $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0, interface => 'commandline' })->store();
929
    my $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => -5 })->store();
930
    my $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => -5, interface => 'commandline' })->store();
930
    my $offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment', amount => 0 })->store();
931
    my $offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment', amount => 0 })->store();
931
    purge_zero_balance_fees( 1 );
932
    purge_zero_balance_fees( 1 );
932
    my $debit_2 = Koha::Account::Lines->find( $debit->id );
933
    my $debit_2 = Koha::Account::Lines->find( $debit->id );
Lines 935-942 subtest "Koha::Account::non_issues_charges tests" => sub { Link Here
935
    ok( $credit_2, 'Credit was correctly not deleted when credit has balance' );
936
    ok( $credit_2, 'Credit was correctly not deleted when credit has balance' );
936
    is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2, "The 2 account lines still exists" );
937
    is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2, "The 2 account lines still exists" );
937
938
938
    $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 5 })->store();
939
    $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 5, interface => 'commanline' })->store();
939
    $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0 })->store();
940
    $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0, interface => 'commandline' })->store();
940
    $offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment', amount => 0 })->store();
941
    $offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment', amount => 0 })->store();
941
    purge_zero_balance_fees( 1 );
942
    purge_zero_balance_fees( 1 );
942
    $debit_2 = $credit_2 = undef;
943
    $debit_2 = $credit_2 = undef;
Lines 946-953 subtest "Koha::Account::non_issues_charges tests" => sub { Link Here
946
    ok( $credit_2, 'Credit was correctly not deleted when debit has balance' );
947
    ok( $credit_2, 'Credit was correctly not deleted when debit has balance' );
947
    is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists" );
948
    is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists" );
948
949
949
    $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0 })->store();
950
    $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0, interface => 'commandline' })->store();
950
    $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0 })->store();
951
    $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0, interface => 'commandline' })->store();
951
    $offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment', amount => 0 })->store();
952
    $offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment', amount => 0 })->store();
952
    purge_zero_balance_fees( 1 );
953
    purge_zero_balance_fees( 1 );
953
    $debit_2 = Koha::Account::Lines->find( $debit->id );
954
    $debit_2 = Koha::Account::Lines->find( $debit->id );
Lines 976-983 subtest "Koha::Account::Line::void tests" => sub { Link Here
976
977
977
    my $account = Koha::Account->new({ patron_id => $borrower->id });
978
    my $account = Koha::Account->new({ patron_id => $borrower->id });
978
979
979
    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10 })->store();
980
    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10, interface => 'commandline'  })->store();
980
    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20 })->store();
981
    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20, interface => 'commandline'  })->store();
981
982
982
    is( $account->balance(), 30, "Account balance is 30" );
983
    is( $account->balance(), 30, "Account balance is 30" );
983
    is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' );
984
    is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' );
Lines 1043-1050 subtest "Koha::Account::Offset credit & debit tests" => sub { Link Here
1043
1044
1044
    my $account = Koha::Account->new({ patron_id => $borrower->id });
1045
    my $account = Koha::Account->new({ patron_id => $borrower->id });
1045
1046
1046
    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10 })->store();
1047
    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10, interface => 'commandline' })->store();
1047
    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20 })->store();
1048
    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20, interface => 'commandline' })->store();
1048
1049
1049
    my $id = $account->pay(
1050
    my $id = $account->pay(
1050
        {
1051
        {
Lines 1103-1109 subtest "Payment notice tests" => sub { Link Here
1103
    });
1104
    });
1104
    my $account = Koha::Account->new({ patron_id => $borrower->id });
1105
    my $account = Koha::Account->new({ patron_id => $borrower->id });
1105
1106
1106
    my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 27 })->store();
1107
    my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 27, interface => 'commandline' })->store();
1107
1108
1108
    my $letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_PAYMENT' } );
1109
    my $letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_PAYMENT' } );
1109
    $letter->content('[%- USE Price -%]A payment of [% credit.amount * -1 | $Price %] has been applied to your account.');
1110
    $letter->content('[%- USE Price -%]A payment of [% credit.amount * -1 | $Price %] has been applied to your account.');
(-)a/t/db_dependent/Circulation.t (-6 / +15 lines)
Lines 684-689 my ( $reused_itemnumber_1, $reused_itemnumber_2 ); Link Here
684
        $account->add_debit(
684
        $account->add_debit(
685
            {
685
            {
686
                amount      => $fines_amount,
686
                amount      => $fines_amount,
687
                interface   => 'test',
687
                type        => 'fine',
688
                type        => 'fine',
688
                item_id     => $item_to_auto_renew->{itemnumber},
689
                item_id     => $item_to_auto_renew->{itemnumber},
689
                description => "Some fines"
690
                description => "Some fines"
Lines 697-702 my ( $reused_itemnumber_1, $reused_itemnumber_2 ); Link Here
697
        $account->add_debit(
698
        $account->add_debit(
698
            {
699
            {
699
                amount      => $fines_amount,
700
                amount      => $fines_amount,
701
                interface   => 'test',
700
                type        => 'fine',
702
                type        => 'fine',
701
                item_id     => $item_to_auto_renew->{itemnumber},
703
                item_id     => $item_to_auto_renew->{itemnumber},
702
                description => "Some fines"
704
                description => "Some fines"
Lines 710-715 my ( $reused_itemnumber_1, $reused_itemnumber_2 ); Link Here
710
        $account->add_debit(
712
        $account->add_debit(
711
            {
713
            {
712
                amount      => $fines_amount,
714
                amount      => $fines_amount,
715
                interface   => 'test',
713
                type        => 'fine',
716
                type        => 'fine',
714
                item_id     => $item_to_auto_renew->{itemnumber},
717
                item_id     => $item_to_auto_renew->{itemnumber},
715
                description => "Some fines"
718
                description => "Some fines"
Lines 2046-2052 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2046
        # Write off the debt
2049
        # Write off the debt
2047
        my $credit = $account->add_credit(
2050
        my $credit = $account->add_credit(
2048
            {   amount => $account->balance,
2051
            {   amount => $account->balance,
2049
                type   => 'writeoff'
2052
                type   => 'writeoff',
2053
                interface => 'test',
2050
            }
2054
            }
2051
        );
2055
        );
2052
        $credit->apply( { debits => $debts, offset_type => 'Writeoff' } );
2056
        $credit->apply( { debits => $debts, offset_type => 'Writeoff' } );
Lines 2106-2112 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2106
        # Write off the debt
2110
        # Write off the debt
2107
        my $credit = $account->add_credit(
2111
        my $credit = $account->add_credit(
2108
            {   amount => $account->balance,
2112
            {   amount => $account->balance,
2109
                type   => 'payment'
2113
                type   => 'payment',
2114
                interface => 'test',
2110
            }
2115
            }
2111
        );
2116
        );
2112
        $credit->apply( { debits => $debts, offset_type => 'Payment' } );
2117
        $credit->apply( { debits => $debts, offset_type => 'Payment' } );
Lines 2226-2232 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2226
        my $payment_amount = 27;
2231
        my $payment_amount = 27;
2227
        my $payment        = $account->add_credit(
2232
        my $payment        = $account->add_credit(
2228
            {   amount => $payment_amount,
2233
            {   amount => $payment_amount,
2229
                type   => 'payment'
2234
                type   => 'payment',
2235
                interface => 'test',
2230
            }
2236
            }
2231
        );
2237
        );
2232
2238
Lines 2236-2242 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2236
        my $write_off_amount = 25;
2242
        my $write_off_amount = 25;
2237
        my $write_off        = $account->add_credit(
2243
        my $write_off        = $account->add_credit(
2238
            {   amount => $write_off_amount,
2244
            {   amount => $write_off_amount,
2239
                type   => 'writeoff'
2245
                type   => 'writeoff',
2246
                interface => 'test',
2240
            }
2247
            }
2241
        );
2248
        );
2242
        $write_off->apply( { debits => $lost_fee_lines->reset, offset_type => 'Writeoff' } );
2249
        $write_off->apply( { debits => $lost_fee_lines->reset, offset_type => 'Writeoff' } );
Lines 2327-2333 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2327
        my $payment_amount = 27;
2334
        my $payment_amount = 27;
2328
        my $payment        = $account->add_credit(
2335
        my $payment        = $account->add_credit(
2329
            {   amount => $payment_amount,
2336
            {   amount => $payment_amount,
2330
                type   => 'payment'
2337
                type   => 'payment',
2338
                interface => 'test',
2331
            }
2339
            }
2332
        );
2340
        );
2333
        $payment->apply({ debits => $lost_fee_lines->reset, offset_type => 'Payment' });
2341
        $payment->apply({ debits => $lost_fee_lines->reset, offset_type => 'Payment' });
Lines 2338-2344 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2338
        );
2346
        );
2339
2347
2340
        my $manual_debit_amount = 80;
2348
        my $manual_debit_amount = 80;
2341
        $account->add_debit( { amount => $manual_debit_amount, type => 'fine' } );
2349
        $account->add_debit( { amount => $manual_debit_amount, type => 'fine', interface =>'test' } );
2342
2350
2343
        is( $account->balance, $manual_debit_amount + $replacement_amount - $payment_amount, 'Manual debit applied' );
2351
        is( $account->balance, $manual_debit_amount + $replacement_amount - $payment_amount, 'Manual debit applied' );
2344
2352
Lines 2380-2385 subtest '_FixOverduesOnReturn' => sub { Link Here
2380
            itemnumber     => $item->itemnumber,
2388
            itemnumber     => $item->itemnumber,
2381
            amount => 99.00,
2389
            amount => 99.00,
2382
            amountoutstanding => 99.00,
2390
            amountoutstanding => 99.00,
2391
            interface => 'test',
2383
        }
2392
        }
2384
    )->store();
2393
    )->store();
2385
2394
(-)a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t (-1 / +1 lines)
Lines 69-75 my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item- Link Here
69
is( $issuingimpossible->{DEBT_GUARANTEES}, undef, "Patron can check out item" );
69
is( $issuingimpossible->{DEBT_GUARANTEES}, undef, "Patron can check out item" );
70
70
71
my $account = Koha::Account->new( { patron_id => $guarantee->{borrowernumber} } );
71
my $account = Koha::Account->new( { patron_id => $guarantee->{borrowernumber} } );
72
$account->add_debit({ amount => 10.00, type => 'lost_item' });
72
$account->add_debit({ amount => 10.00, type => 'lost_item', interface => 'test' });
73
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
73
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
74
is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
74
is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
75
75
(-)a/t/db_dependent/Koha/Account.t (-69 / +77 lines)
Lines 33-38 use t::lib::TestBuilder; Link Here
33
33
34
my $schema  = Koha::Database->new->schema;
34
my $schema  = Koha::Database->new->schema;
35
my $builder = t::lib::TestBuilder->new;
35
my $builder = t::lib::TestBuilder->new;
36
C4::Context->interface('commandline');
36
37
37
subtest 'new' => sub {
38
subtest 'new' => sub {
38
39
Lines 59-68 subtest 'outstanding_debits() tests' => sub { Link Here
59
    my $account = $patron->account;
60
    my $account = $patron->account;
60
61
61
    my @generated_lines;
62
    my @generated_lines;
62
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store;
63
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store;
63
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store;
64
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store;
64
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store;
65
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store;
65
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store;
66
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4, interface => 'commandline' })->store;
66
67
67
    my $lines     = $account->outstanding_debits();
68
    my $lines     = $account->outstanding_debits();
68
    my @lines_arr = $account->outstanding_debits();
69
    my @lines_arr = $account->outstanding_debits();
Lines 79-87 subtest 'outstanding_debits() tests' => sub { Link Here
79
        $i++;
80
        $i++;
80
    }
81
    }
81
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
82
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
82
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -2 })->store;
83
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -2, interface => 'commandline' })->store;
83
    my $just_one = Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => 3, amountoutstanding =>  3 })->store;
84
    my $just_one = Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => 3, amountoutstanding =>  3, interface => 'commandline' })->store;
84
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -6, amountoutstanding => -6 })->store;
85
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -6, amountoutstanding => -6, interface => 'commandline' })->store;
85
    $lines = $patron_2->account->outstanding_debits();
86
    $lines = $patron_2->account->outstanding_debits();
86
    is( $lines->total_outstanding, 3, "Total if some outstanding debits and some credits is only debits" );
87
    is( $lines->total_outstanding, 3, "Total if some outstanding debits and some credits is only debits" );
87
    is( $lines->count, 1, "With 1 outstanding debits, we get back a Lines object with 1 lines" );
88
    is( $lines->count, 1, "With 1 outstanding debits, we get back a Lines object with 1 lines" );
Lines 89-97 subtest 'outstanding_debits() tests' => sub { Link Here
89
    is_deeply( $the_line->unblessed, $lines->next->unblessed, "We get back the one correct line");
90
    is_deeply( $the_line->unblessed, $lines->next->unblessed, "We get back the one correct line");
90
91
91
    my $patron_3 = $builder->build_object({ class => 'Koha::Patrons' });
92
    my $patron_3 = $builder->build_object({ class => 'Koha::Patrons' });
92
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -2,   amountoutstanding => -2 })->store;
93
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -2,   amountoutstanding => -2, interface => 'commandline' })->store;
93
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -20,  amountoutstanding => -20 })->store;
94
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -20,  amountoutstanding => -20, interface => 'commandline' })->store;
94
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -200, amountoutstanding => -200 })->store;
95
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -200, amountoutstanding => -200, interface => 'commandline' })->store;
95
    $lines = $patron_3->account->outstanding_debits();
96
    $lines = $patron_3->account->outstanding_debits();
96
    is( $lines->total_outstanding, 0, "Total if no outstanding debits total is 0" );
97
    is( $lines->total_outstanding, 0, "Total if no outstanding debits total is 0" );
97
    is( $lines->count, 0, "With 0 outstanding debits, we get back a Lines object with 0 lines" );
98
    is( $lines->count, 0, "With 0 outstanding debits, we get back a Lines object with 0 lines" );
Lines 103-109 subtest 'outstanding_debits() tests' => sub { Link Here
103
    is( $lines->count, 0, "With no outstanding debits, we get back a Lines object with 0 lines" );
104
    is( $lines->count, 0, "With no outstanding debits, we get back a Lines object with 0 lines" );
104
105
105
    # create a pathological credit with amountoutstanding > 0 (BZ 14591)
106
    # create a pathological credit with amountoutstanding > 0 (BZ 14591)
106
    Koha::Account::Line->new({ borrowernumber => $patron_4->id, amount => -3, amountoutstanding => 3 })->store();
107
    Koha::Account::Line->new({ borrowernumber => $patron_4->id, amount => -3, amountoutstanding => 3, interface => 'commandline' })->store();
107
    $lines = $account_4->outstanding_debits();
108
    $lines = $account_4->outstanding_debits();
108
    is( $lines->count, 0, 'No credits are confused with debits because of the amountoutstanding value' );
109
    is( $lines->count, 0, 'No credits are confused with debits because of the amountoutstanding value' );
109
110
Lines 120-129 subtest 'outstanding_credits() tests' => sub { Link Here
120
    my $account = $patron->account;
121
    my $account = $patron->account;
121
122
122
    my @generated_lines;
123
    my @generated_lines;
123
    push @generated_lines, $account->add_credit({ amount => 1 });
124
    push @generated_lines, $account->add_credit({ amount => 1, interface => 'commandline' });
124
    push @generated_lines, $account->add_credit({ amount => 2 });
125
    push @generated_lines, $account->add_credit({ amount => 2, interface => 'commandline' });
125
    push @generated_lines, $account->add_credit({ amount => 3 });
126
    push @generated_lines, $account->add_credit({ amount => 3, interface => 'commandline' });
126
    push @generated_lines, $account->add_credit({ amount => 4 });
127
    push @generated_lines, $account->add_credit({ amount => 4, interface => 'commandline' });
127
128
128
    my $lines     = $account->outstanding_credits();
129
    my $lines     = $account->outstanding_credits();
129
    my @lines_arr = $account->outstanding_credits();
130
    my @lines_arr = $account->outstanding_credits();
Lines 147-153 subtest 'outstanding_credits() tests' => sub { Link Here
147
    is( $lines->count, 0, "With no outstanding credits, we get back a Lines object with 0 lines" );
148
    is( $lines->count, 0, "With no outstanding credits, we get back a Lines object with 0 lines" );
148
149
149
    # create a pathological debit with amountoutstanding < 0 (BZ 14591)
150
    # create a pathological debit with amountoutstanding < 0 (BZ 14591)
150
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => 2, amountoutstanding => -3 })->store();
151
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => 2, amountoutstanding => -3, interface => 'commandline' })->store();
151
    $lines = $account->outstanding_credits();
152
    $lines = $account->outstanding_credits();
152
    is( $lines->count, 0, 'No debits are confused with credits because of the amountoutstanding value' );
153
    is( $lines->count, 0, 'No debits are confused with credits because of the amountoutstanding value' );
153
154
Lines 178-184 subtest 'add_credit() tests' => sub { Link Here
178
            library_id  => $patron->branchcode,
179
            library_id  => $patron->branchcode,
179
            note        => 'not really important',
180
            note        => 'not really important',
180
            type        => 'payment',
181
            type        => 'payment',
181
            user_id     => $patron->id
182
            user_id     => $patron->id,
183
            interface   => 'commandline'
182
        }
184
        }
183
    );
185
    );
184
186
Lines 197-203 subtest 'add_credit() tests' => sub { Link Here
197
            library_id  => $patron->branchcode,
199
            library_id  => $patron->branchcode,
198
            note        => 'not really important',
200
            note        => 'not really important',
199
            user_id     => $patron->id,
201
            user_id     => $patron->id,
200
            sip         => $sip_code
202
            sip         => $sip_code,
203
            interface   => 'commandline'
201
        }
204
        }
202
    );
205
    );
203
206
Lines 220-226 subtest 'add_credit() tests' => sub { Link Here
220
            description => 'Manual credit applied',
223
            description => 'Manual credit applied',
221
            library_id  => $patron->branchcode,
224
            library_id  => $patron->branchcode,
222
            user_id     => $patron->id,
225
            user_id     => $patron->id,
223
            type        => 'forgiven'
226
            type        => 'forgiven',
227
            interface   => 'commandline'
224
        }
228
        }
225
    );
229
    );
226
230
Lines 254-260 subtest 'add_debit() tests' => sub { Link Here
254
            library_id  => $patron->branchcode,
258
            library_id  => $patron->branchcode,
255
            note        => 'this should fail anyway',
259
            note        => 'this should fail anyway',
256
            type        => 'rent',
260
            type        => 'rent',
257
            user_id     => $patron->id
261
            user_id     => $patron->id,
262
            interface   => 'commandline'
258
        }
263
        }
259
    ); } 'Koha::Exceptions::Account::AmountNotPositive', 'Expected validation exception thrown (amount)';
264
    ); } 'Koha::Exceptions::Account::AmountNotPositive', 'Expected validation exception thrown (amount)';
260
265
Lines 266-272 subtest 'add_debit() tests' => sub { Link Here
266
            library_id  => $patron->branchcode,
271
            library_id  => $patron->branchcode,
267
            note        => 'this should fail anyway',
272
            note        => 'this should fail anyway',
268
            type        => 'failure',
273
            type        => 'failure',
269
            user_id     => $patron->id
274
            user_id     => $patron->id,
275
            interface   => 'commandline'
270
        }
276
        }
271
    ); } 'Koha::Exceptions::Account::UnrecognisedType', 'Expected validation exception thrown (type)';
277
    ); } 'Koha::Exceptions::Account::UnrecognisedType', 'Expected validation exception thrown (type)';
272
278
Lines 280-286 subtest 'add_debit() tests' => sub { Link Here
280
            library_id  => $patron->branchcode,
286
            library_id  => $patron->branchcode,
281
            note        => 'not really important',
287
            note        => 'not really important',
282
            type        => 'rent',
288
            type        => 'rent',
283
            user_id     => $patron->id
289
            user_id     => $patron->id,
290
            interface   => 'commandline'
284
        }
291
        }
285
    );
292
    );
286
293
Lines 308-313 subtest 'add_debit() tests' => sub { Link Here
308
            note        => 'not really important',
315
            note        => 'not really important',
309
            type        => 'rent',
316
            type        => 'rent',
310
            user_id     => $patron->id,
317
            user_id     => $patron->id,
318
            interface   => 'commandline'
311
        }
319
        }
312
    );
320
    );
313
321
Lines 349-368 subtest 'lines() tests' => sub { Link Here
349
    my @generated_lines;
357
    my @generated_lines;
350
358
351
    # Add Credits
359
    # Add Credits
352
    push @generated_lines, $account->add_credit({ amount => 1 });
360
    push @generated_lines, $account->add_credit({ amount => 1, interface => 'commandline' });
353
    push @generated_lines, $account->add_credit({ amount => 2 });
361
    push @generated_lines, $account->add_credit({ amount => 2, interface => 'commandline' });
354
    push @generated_lines, $account->add_credit({ amount => 3 });
362
    push @generated_lines, $account->add_credit({ amount => 3, interface => 'commandline' });
355
    push @generated_lines, $account->add_credit({ amount => 4 });
363
    push @generated_lines, $account->add_credit({ amount => 4, interface => 'commandline' });
356
364
357
    # Add Debits
365
    # Add Debits
358
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 1 })->store;
366
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 1, interface => 'commandline' })->store;
359
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 2 })->store;
367
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 2, interface => 'commandline' })->store;
360
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 3 })->store;
368
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 3, interface => 'commandline' })->store;
361
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 4 })->store;
369
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 4, interface => 'commandline' })->store;
362
370
363
    # Paid Off
371
    # Paid Off
364
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 0 })->store;
372
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 0, interface => 'commandline' })->store;
365
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 0 })->store;
373
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 0, interface => 'commandline' })->store;
366
374
367
    my $lines = $account->lines;
375
    my $lines = $account->lines;
368
    is( $lines->_resultset->count, 10, "All accountlines (debits, credits and paid off) were fetched");
376
    is( $lines->_resultset->count, 10, "All accountlines (debits, credits and paid off) were fetched");
Lines 384-404 subtest 'reconcile_balance' => sub { Link Here
384
        my $account = $patron->account;
392
        my $account = $patron->account;
385
393
386
        # Add Credits
394
        # Add Credits
387
        $account->add_credit({ amount => 1 });
395
        $account->add_credit({ amount => 1, interface => 'commandline' });
388
        $account->add_credit({ amount => 2 });
396
        $account->add_credit({ amount => 2, interface => 'commandline' });
389
        $account->add_credit({ amount => 3 });
397
        $account->add_credit({ amount => 3, interface => 'commandline' });
390
        $account->add_credit({ amount => 4 });
398
        $account->add_credit({ amount => 4, interface => 'commandline' });
391
        $account->add_credit({ amount => 5 });
399
        $account->add_credit({ amount => 5, interface => 'commandline' });
392
400
393
        # Add Debits TODO: replace for calls to add_debit when time comes
401
        # Add Debits TODO: replace for calls to add_debit when time comes
394
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store;
402
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store;
395
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store;
403
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store;
396
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store;
404
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store;
397
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store;
405
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4, interface => 'commandline' })->store;
398
406
399
        # Paid Off
407
        # Paid Off
400
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store;
408
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store;
401
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store;
409
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store;
402
410
403
        is( $account->balance(), -5, "Account balance is -5" );
411
        is( $account->balance(), -5, "Account balance is -5" );
404
        is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' );
412
        is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' );
Lines 423-442 subtest 'reconcile_balance' => sub { Link Here
423
        my $account = $patron->account;
431
        my $account = $patron->account;
424
432
425
        # Add Credits
433
        # Add Credits
426
        $account->add_credit({ amount => 1 });
434
        $account->add_credit({ amount => 1, interface => 'commandline' });
427
        $account->add_credit({ amount => 2 });
435
        $account->add_credit({ amount => 2, interface => 'commandline' });
428
        $account->add_credit({ amount => 3 });
436
        $account->add_credit({ amount => 3, interface => 'commandline' });
429
        $account->add_credit({ amount => 4 });
437
        $account->add_credit({ amount => 4, interface => 'commandline' });
430
438
431
        # Add Debits TODO: replace for calls to add_debit when time comes
439
        # Add Debits TODO: replace for calls to add_debit when time comes
432
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store;
440
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store;
433
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store;
441
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store;
434
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store;
442
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store;
435
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store;
443
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4, interface => 'commandline' })->store;
436
444
437
        # Paid Off
445
        # Paid Off
438
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store;
446
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store;
439
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store;
447
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store;
440
448
441
        is( $account->balance(), 0, "Account balance is 0" );
449
        is( $account->balance(), 0, "Account balance is 0" );
442
        is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' );
450
        is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' );
Lines 461-481 subtest 'reconcile_balance' => sub { Link Here
461
        my $account = $patron->account;
469
        my $account = $patron->account;
462
470
463
        # Add Credits
471
        # Add Credits
464
        $account->add_credit({ amount => 1 });
472
        $account->add_credit({ amount => 1, interface => 'commandline' });
465
        $account->add_credit({ amount => 2 });
473
        $account->add_credit({ amount => 2, interface => 'commandline' });
466
        $account->add_credit({ amount => 3 });
474
        $account->add_credit({ amount => 3, interface => 'commandline' });
467
        $account->add_credit({ amount => 4 });
475
        $account->add_credit({ amount => 4, interface => 'commandline' });
468
476
469
        # Add Debits TODO: replace for calls to add_debit when time comes
477
        # Add Debits TODO: replace for calls to add_debit when time comes
470
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store;
478
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store;
471
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store;
479
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store;
472
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store;
480
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store;
473
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store;
481
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4, interface => 'commandline' })->store;
474
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 5, amountoutstanding => 5 })->store;
482
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 5, amountoutstanding => 5, interface => 'commandline' })->store;
475
483
476
        # Paid Off
484
        # Paid Off
477
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store;
485
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store;
478
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store;
486
        Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store;
479
487
480
        is( $account->balance(), 5, "Account balance is 5" );
488
        is( $account->balance(), 5, "Account balance is 5" );
481
        is( $account->outstanding_debits->total_outstanding, 15, 'Outstanding debits sum 15' );
489
        is( $account->outstanding_debits->total_outstanding, 15, 'Outstanding debits sum 15' );
Lines 500-512 subtest 'reconcile_balance' => sub { Link Here
500
        my $account = $patron->account;
508
        my $account = $patron->account;
501
509
502
        # Add Credits
510
        # Add Credits
503
        $account->add_credit({ amount => 1 });
511
        $account->add_credit({ amount => 1, interface => 'commandline' });
504
        $account->add_credit({ amount => 3 });
512
        $account->add_credit({ amount => 3, interface => 'commandline' });
505
513
506
        # Add Debits TODO: replace for calls to add_debit when time comes
514
        # Add Debits TODO: replace for calls to add_debit when time comes
507
        my $debit_1 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store;
515
        my $debit_1 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store;
508
        my $debit_2 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store;
516
        my $debit_2 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store;
509
        my $debit_3 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store;
517
        my $debit_3 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store;
510
518
511
        is( $account->balance(), 2, "Account balance is 2" );
519
        is( $account->balance(), 2, "Account balance is 2" );
512
        is( $account->outstanding_debits->total_outstanding, 6, 'Outstanding debits sum 6' );
520
        is( $account->outstanding_debits->total_outstanding, 6, 'Outstanding debits sum 6' );
(-)a/t/db_dependent/Koha/Account/Lines.t (-25 / +39 lines)
Lines 59-64 subtest 'item() tests' => sub { Link Here
59
        itemnumber     => $item->itemnumber,
59
        itemnumber     => $item->itemnumber,
60
        accounttype    => "F",
60
        accounttype    => "F",
61
        amount         => 10,
61
        amount         => 10,
62
        interface      => 'commandline',
62
    })->store;
63
    })->store;
63
64
64
    my $account_line_item = $line->item;
65
    my $account_line_item = $line->item;
Lines 86-92 subtest 'total_outstanding() tests' => sub { Link Here
86
        {   borrowernumber    => $patron->id,
87
        {   borrowernumber    => $patron->id,
87
            accounttype       => "F",
88
            accounttype       => "F",
88
            amount            => 10,
89
            amount            => 10,
89
            amountoutstanding => 10
90
            amountoutstanding => 10,
91
            interface         => 'commandline',
90
        }
92
        }
91
    )->store;
93
    )->store;
92
94
Lines 94-100 subtest 'total_outstanding() tests' => sub { Link Here
94
        {   borrowernumber    => $patron->id,
96
        {   borrowernumber    => $patron->id,
95
            accounttype       => "F",
97
            accounttype       => "F",
96
            amount            => 10,
98
            amount            => 10,
97
            amountoutstanding => 10
99
            amountoutstanding => 10,
100
            interface         => 'commandline',
98
        }
101
        }
99
    )->store;
102
    )->store;
100
103
Lines 105-111 subtest 'total_outstanding() tests' => sub { Link Here
105
        {   borrowernumber    => $patron->id,
108
        {   borrowernumber    => $patron->id,
106
            accounttype       => "F",
109
            accounttype       => "F",
107
            amount            => -10,
110
            amount            => -10,
108
            amountoutstanding => -10
111
            amountoutstanding => -10,
112
            interface         => 'commandline',
109
        }
113
        }
110
    )->store;
114
    )->store;
111
115
Lines 116-122 subtest 'total_outstanding() tests' => sub { Link Here
116
        {   borrowernumber    => $patron->id,
120
        {   borrowernumber    => $patron->id,
117
            accounttype       => "F",
121
            accounttype       => "F",
118
            amount            => -10,
122
            amount            => -10,
119
            amountoutstanding => -10
123
            amountoutstanding => -10,
124
            interface         => 'commandline',
120
        }
125
        }
121
    )->store;
126
    )->store;
122
127
Lines 127-133 subtest 'total_outstanding() tests' => sub { Link Here
127
        {   borrowernumber    => $patron->id,
132
        {   borrowernumber    => $patron->id,
128
            accounttype       => "F",
133
            accounttype       => "F",
129
            amount            => -100,
134
            amount            => -100,
130
            amountoutstanding => -100
135
            amountoutstanding => -100,
136
            interface         => 'commandline',
131
        }
137
        }
132
    )->store;
138
    )->store;
133
139
Lines 146-152 subtest 'is_credit() and is_debit() tests' => sub { Link Here
146
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
152
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
147
    my $account = $patron->account;
153
    my $account = $patron->account;
148
154
149
    my $credit = $account->add_credit({ amount => 100, user_id => $patron->id });
155
    my $credit = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' });
150
156
151
    ok( $credit->is_credit, 'is_credit detects credits' );
157
    ok( $credit->is_credit, 'is_credit detects credits' );
152
    ok( !$credit->is_debit, 'is_debit detects credits' );
158
    ok( !$credit->is_debit, 'is_debit detects credits' );
Lines 156-161 subtest 'is_credit() and is_debit() tests' => sub { Link Here
156
        borrowernumber => $patron->id,
162
        borrowernumber => $patron->id,
157
        accounttype    => "F",
163
        accounttype    => "F",
158
        amount         => 10,
164
        amount         => 10,
165
        interface      => 'commandline',
159
    })->store;
166
    })->store;
160
167
161
    ok( !$debit->is_credit, 'is_credit detects debits' );
168
    ok( !$debit->is_credit, 'is_credit detects debits' );
Lines 173-185 subtest 'apply() tests' => sub { Link Here
173
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
180
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
174
    my $account = $patron->account;
181
    my $account = $patron->account;
175
182
176
    my $credit = $account->add_credit( { amount => 100, user_id => $patron->id } );
183
    my $credit = $account->add_credit( { amount => 100, user_id => $patron->id, interface => 'commandline' } );
177
184
178
    my $debit_1 = Koha::Account::Line->new(
185
    my $debit_1 = Koha::Account::Line->new(
179
        {   borrowernumber    => $patron->id,
186
        {   borrowernumber    => $patron->id,
180
            accounttype       => "F",
187
            accounttype       => "F",
181
            amount            => 10,
188
            amount            => 10,
182
            amountoutstanding => 10
189
            amountoutstanding => 10,
190
            interface         => 'commandline',
183
        }
191
        }
184
    )->store;
192
    )->store;
185
193
Lines 187-193 subtest 'apply() tests' => sub { Link Here
187
        {   borrowernumber    => $patron->id,
195
        {   borrowernumber    => $patron->id,
188
            accounttype       => "F",
196
            accounttype       => "F",
189
            amount            => 100,
197
            amount            => 100,
190
            amountoutstanding => 100
198
            amountoutstanding => 100,
199
            interface         => 'commandline',
191
        }
200
        }
192
    )->store;
201
    )->store;
193
202
Lines 237-254 subtest 'apply() tests' => sub { Link Here
237
        '->apply() can only be used with credits';
246
        '->apply() can only be used with credits';
238
247
239
    $debits = Koha::Account::Lines->search({ accountlines_id => $credit->id });
248
    $debits = Koha::Account::Lines->search({ accountlines_id => $credit->id });
240
    my $credit_3 = $account->add_credit({ amount => 1 });
249
    my $credit_3 = $account->add_credit({ amount => 1, interface => 'commandline' });
241
    throws_ok
250
    throws_ok
242
        { $credit_3->apply({ debits => $debits }); }
251
        { $credit_3->apply({ debits => $debits }); }
243
        'Koha::Exceptions::Account::IsNotDebit',
252
        'Koha::Exceptions::Account::IsNotDebit',
244
        '->apply() can only be applied to credits';
253
        '->apply() can only be applied to credits';
245
254
246
    my $credit_2 = $account->add_credit({ amount => 20 });
255
    my $credit_2 = $account->add_credit({ amount => 20, interface => 'commandline' });
247
    my $debit_3  = Koha::Account::Line->new(
256
    my $debit_3  = Koha::Account::Line->new(
248
        {   borrowernumber    => $patron->id,
257
        {   borrowernumber    => $patron->id,
249
            accounttype       => "F",
258
            accounttype       => "F",
250
            amount            => 100,
259
            amount            => 100,
251
            amountoutstanding => 100
260
            amountoutstanding => 100,
261
            interface         => 'commandline',
252
        }
262
        }
253
    )->store;
263
    )->store;
254
264
Lines 296-301 subtest 'Keep account info when related patron, staff or item is deleted' => sub Link Here
296
        itemnumber     => $item->itemnumber,
306
        itemnumber     => $item->itemnumber,
297
        accounttype    => "F",
307
        accounttype    => "F",
298
        amount         => 10,
308
        amount         => 10,
309
        interface      => 'commandline',
299
    })->store;
310
    })->store;
300
311
301
    $issue->delete;
312
    $issue->delete;
Lines 333-339 subtest 'adjust() tests' => sub { Link Here
333
        {   borrowernumber    => $patron->id,
344
        {   borrowernumber    => $patron->id,
334
            accounttype       => "F",
345
            accounttype       => "F",
335
            amount            => 10,
346
            amount            => 10,
336
            amountoutstanding => 10
347
            amountoutstanding => 10,
348
            interface         => 'commandline',
337
        }
349
        }
338
    )->store;
350
    )->store;
339
351
Lines 341-361 subtest 'adjust() tests' => sub { Link Here
341
        {   borrowernumber    => $patron->id,
353
        {   borrowernumber    => $patron->id,
342
            accounttype       => "FU",
354
            accounttype       => "FU",
343
            amount            => 100,
355
            amount            => 100,
344
            amountoutstanding => 100
356
            amountoutstanding => 100,
357
            interface         => 'commandline'
345
        }
358
        }
346
    )->store;
359
    )->store;
347
360
348
    my $credit = $account->add_credit( { amount => 40, user_id => $patron->id } );
361
    my $credit = $account->add_credit( { amount => 40, user_id => $patron->id, interface => 'commandline' } );
349
362
350
    throws_ok { $debit_1->adjust( { amount => 50, type => 'bad' } ) }
363
    throws_ok { $debit_1->adjust( { amount => 50, type => 'bad', interface => 'commandline' } ) }
351
    qr/Update type not recognised/, 'Exception thrown for unrecognised type';
364
    qr/Update type not recognised/, 'Exception thrown for unrecognised type';
352
365
353
    throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_update' } ) }
366
    throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_update', interface => 'commandline' } ) }
354
    qr/Update type not allowed on this accounttype/,
367
    qr/Update type not allowed on this accounttype/,
355
      'Exception thrown for type conflict';
368
      'Exception thrown for type conflict';
356
369
357
    # Increment an unpaid fine
370
    # Increment an unpaid fine
358
    $debit_2->adjust( { amount => 150, type => 'fine_update' } )->discard_changes;
371
    $debit_2->adjust( { amount => 150, type => 'fine_update', interface => 'commandline' } )->discard_changes;
359
372
360
    is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' );
373
    is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' );
361
    is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' );
374
    is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' );
Lines 381-387 subtest 'adjust() tests' => sub { Link Here
381
    t::lib::Mocks::mock_preference( 'FinesLog', 1 );
394
    t::lib::Mocks::mock_preference( 'FinesLog', 1 );
382
395
383
    # Increment the partially paid fine
396
    # Increment the partially paid fine
384
    $debit_2->adjust( { amount => 160, type => 'fine_update' } )->discard_changes;
397
    $debit_2->adjust( { amount => 160, type => 'fine_update', interface => 'commandline' } )->discard_changes;
385
398
386
    is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' );
399
    is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' );
387
    is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' );
400
    is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' );
Lines 395-401 subtest 'adjust() tests' => sub { Link Here
395
    is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' );
408
    is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' );
396
409
397
    # Decrement the partially paid fine, less than what was paid
410
    # Decrement the partially paid fine, less than what was paid
398
    $debit_2->adjust( { amount => 50, type => 'fine_update' } )->discard_changes;
411
    $debit_2->adjust( { amount => 50, type => 'fine_update', interface => 'commandline' } )->discard_changes;
399
412
400
    is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' );
413
    is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' );
401
    is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' );
414
    is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' );
Lines 407-413 subtest 'adjust() tests' => sub { Link Here
407
    is( $THIS_offset->type, 'fine_decrease', 'Adjust type stored correctly' );
420
    is( $THIS_offset->type, 'fine_decrease', 'Adjust type stored correctly' );
408
421
409
    # Decrement the partially paid fine, more than what was paid
422
    # Decrement the partially paid fine, more than what was paid
410
    $debit_2->adjust( { amount => 30, type => 'fine_update' } )->discard_changes;
423
    $debit_2->adjust( { amount => 30, type => 'fine_update', interface => 'commandline' } )->discard_changes;
411
    is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' );
424
    is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' );
412
    is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' );
425
    is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' );
413
426
Lines 438-447 subtest 'checkout() tests' => sub { Link Here
438
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
451
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
439
452
440
    my $line = $account->add_debit({
453
    my $line = $account->add_debit({
441
        amount   => 10,
454
        amount    => 10,
442
        item_id  => $item->itemnumber,
455
        interface => 'commandline',
443
        issue_id => $checkout->issue_id,
456
        item_id   => $item->itemnumber,
444
        type     => 'fine',
457
        issue_id  => $checkout->issue_id,
458
        type      => 'fine',
445
    });
459
    });
446
460
447
    my $line_checkout = $line->checkout;
461
    my $line_checkout = $line->checkout;
(-)a/t/db_dependent/api/v1/patrons_accounts.t (-4 / +8 lines)
Lines 68-74 subtest 'get_balance() tests' => sub { Link Here
68
            accounttype       => "N", # New card
68
            accounttype       => "N", # New card
69
            amountoutstanding => 50,
69
            amountoutstanding => 50,
70
            manager_id        => $patron->borrowernumber,
70
            manager_id        => $patron->borrowernumber,
71
            branchcode        => $library->id
71
            branchcode        => $library->id,
72
            interface         => 'test',
72
        }
73
        }
73
    )->store();
74
    )->store();
74
    $account_line_1->discard_changes;
75
    $account_line_1->discard_changes;
Lines 82-88 subtest 'get_balance() tests' => sub { Link Here
82
            accounttype       => "N", # New card
83
            accounttype       => "N", # New card
83
            amountoutstanding => 50.01,
84
            amountoutstanding => 50.01,
84
            manager_id        => $patron->borrowernumber,
85
            manager_id        => $patron->borrowernumber,
85
            branchcode        => $library->id
86
            branchcode        => $library->id,
87
            interface         => 'test',
86
        }
88
        }
87
    )->store();
89
    )->store();
88
    $account_line_2->discard_changes;
90
    $account_line_2->discard_changes;
Lines 128-134 subtest 'get_balance() tests' => sub { Link Here
128
130
129
    # add a credit
131
    # add a credit
130
    my $credit_line = $account->add_credit(
132
    my $credit_line = $account->add_credit(
131
        { amount => 10, user_id => $patron->id, library_id => $library->id } );
133
        { amount => 10, user_id => $patron->id, library_id => $library->id, interface => 'test' } );
132
    # re-read from the DB
134
    # re-read from the DB
133
    $credit_line->discard_changes;
135
    $credit_line->discard_changes;
134
    $tx = $t->ua->build_tx( GET => "/api/v1/patrons/$patron_id/account" );
136
    $tx = $t->ua->build_tx( GET => "/api/v1/patrons/$patron_id/account" );
Lines 184-189 subtest 'add_credit() tests' => sub { Link Here
184
            accounttype       => "N",                       # New card
186
            accounttype       => "N",                       # New card
185
            amountoutstanding => 10,
187
            amountoutstanding => 10,
186
            manager_id        => $patron->borrowernumber,
188
            manager_id        => $patron->borrowernumber,
189
            interface         => 'test',
187
        }
190
        }
188
    )->store();
191
    )->store();
189
    my $debit_2 = Koha::Account::Line->new(
192
    my $debit_2 = Koha::Account::Line->new(
Lines 194-199 subtest 'add_credit() tests' => sub { Link Here
194
            accounttype       => "N",                       # New card
197
            accounttype       => "N",                       # New card
195
            amountoutstanding => 15,
198
            amountoutstanding => 15,
196
            manager_id        => $patron->borrowernumber,
199
            manager_id        => $patron->borrowernumber,
200
            interface         => 'test',
197
        }
201
        }
198
    )->store();
202
    )->store();
199
203
Lines 220-225 subtest 'add_credit() tests' => sub { Link Here
220
            accounttype       => "N",                       # New card
224
            accounttype       => "N",                       # New card
221
            amountoutstanding => 100,
225
            amountoutstanding => 100,
222
            manager_id        => $patron->borrowernumber,
226
            manager_id        => $patron->borrowernumber,
227
            interface         => 'test',
223
        }
228
        }
224
    )->store();
229
    )->store();
225
230
226
- 

Return to bug 22600