Bugzilla – Attachment 105656 Details for
Bug 15156
Get all Borrowers with pending/unpaid fines/accountlines
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15156: Get all Borrowers with pending/unpaid fines/accountlines
0001-Bug-15156-Get-all-Borrowers-with-pending-unpaid.patch (text/plain), 4.01 KB, created by
Emmi Takkinen
on 2020-06-09 07:56:42 UTC
(
hide
)
Description:
Bug 15156: Get all Borrowers with pending/unpaid fines/accountlines
Filename:
MIME Type:
Creator:
Emmi Takkinen
Created:
2020-06-09 07:56:42 UTC
Size:
4.01 KB
patch
obsolete
>From 4a3aa0f40d45c6f807c2b99cc0f0642fdbcb1a50 Mon Sep 17 00:00:00 2001 >From: Emmi Takkinen <emmi.takkinen@outlook.com> >Date: Tue, 25 Feb 2020 09:24:18 +0200 >Subject: [PATCH] Bug 15156: Get all Borrowers with pending/unpaid > fines/accountlines > >This patch adds method to fetch all borrowers with unpaid >fines. > >To test: >prove t/db_dependent/Koha/Patrons.t > >Sponsored-by: Koha-Suomi Oy >--- > Koha/Patrons.pm | 23 ++++++++++++++++++++++ > t/db_dependent/Koha/Patrons.t | 36 ++++++++++++++++++++++++++++++++++- > 2 files changed, 58 insertions(+), 1 deletion(-) > >diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm >index 6943018e88..2c6a1b95fe 100644 >--- a/Koha/Patrons.pm >+++ b/Koha/Patrons.pm >@@ -463,6 +463,29 @@ sub filter_by_attribute_value { > } > > >+=head3 >+ >+ my $patrons_with_fines = Koha::Patrons->search({ ... })->search_patrons_with_unpaid_fines(); >+ >+Returns unique borrowernumbers of all patrons with unpaid fines. >+ >+=cut >+ >+sub search_patrons_with_unpaid_fines { >+ my ( $self ) = @_; >+ my @patrons_with_fines; >+ while ( my $patron = $self->next ) { >+ my $account_balance = $patron->account()->balance; >+ if($account_balance > 0){ >+ push @patrons_with_fines, { >+ borrowernumber => $patron->borrowernumber, >+ accountbalance => $account_balance >+ } >+ } >+ } >+ return \@patrons_with_fines; >+} >+ > =head3 _type > > =cut >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index 4f434adc3c..224d26db70 100644 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 41; >+use Test::More tests => 42; > use Test::Warn; > use Test::Exception; > use Test::MockModule; >@@ -2030,6 +2030,7 @@ subtest 'anonymize' => sub { > $patron2->discard_changes; # refresh > is( $patron2->firstname, undef, 'First name patron2 cleared' ); > }; >+ > $schema->storage->txn_rollback; > > subtest 'extended_attributes' => sub { >@@ -2204,3 +2205,36 @@ subtest 'extended_attributes' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'search_patrons_with_unpaid_fines() tests' => sub { >+ >+ plan tests => 7; >+ >+ $schema->storage->txn_begin; >+ >+ my $patrons_with_fines = Koha::Patrons->search({ branchcode => $library->{branchcode} })->search_patrons_with_unpaid_fines(); >+ is( scalar( @$patrons_with_fines ), 0, 'search_patrons_with_unpaid_fines() should return empty array' ); >+ >+ my $library = $builder->build({source => 'Branch' }); >+ >+ my $patron1 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->{branchcode} }}); >+ my $account1 = $patron1->account; >+ $account1->add_debit({ amount => 10, interface => 'commandline', type => 'OVERDUE' }); >+ >+ my $patron2 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->{branchcode} }}); >+ my $account2 = $patron2->account; >+ $account2->add_debit({ amount => 10, interface => 'commandline', type => 'OVERDUE' }); >+ >+ $patrons_with_fines = Koha::Patrons->search({ branchcode => $library->{branchcode} })->search_patrons_with_unpaid_fines(); >+ is( scalar( @$patrons_with_fines ), 2, 'search_patrons_with_unpaid_fines() should return array with 2 values' ); >+ is( $patrons_with_fines->[0]->{ borrowernumber }, $patron1->borrowernumber, 'patron1 should be in array'); >+ is( $patrons_with_fines->[1]->{ borrowernumber }, $patron2->borrowernumber, 'patron2 should be in array'); >+ is( $patrons_with_fines->[0]->{ accountbalance }, $account1->balance, 'patron1 fines are correct'); >+ is( $patrons_with_fines->[1]->{ accountbalance }, $account2->balance, 'patron2 fines are correct'); >+ >+ $account2->add_credit({ amount => 10, interface => 'commandline' }); >+ $patrons_with_fines = Koha::Patrons->search({ branchcode => $library->{branchcode} })->search_patrons_with_unpaid_fines(); >+ is( scalar( @$patrons_with_fines ), 1, 'Patron without fines is not in array'); >+ >+ $schema->storage->txn_rollback; >+} >\ No newline at end of file >-- >2.17.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15156
:
44640
|
44642
|
46232
|
99981
|
105656
|
109593
|
110886
|
122355
|
122392
|
122528
|
122534
|
124497
|
124508
|
124876
|
124978