Bugzilla – Attachment 122392 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 patrons with owings
Bug-15156-Get-all-patrons-with-owings.patch (text/plain), 4.11 KB, created by
David Nind
on 2021-06-24 14:38:28 UTC
(
hide
)
Description:
Bug 15156: Get all patrons with owings
Filename:
MIME Type:
Creator:
David Nind
Created:
2021-06-24 14:38:28 UTC
Size:
4.11 KB
patch
obsolete
>From b08bc7c411fe7c8b884bb1c1bda3663ff941bc8e Mon Sep 17 00:00:00 2001 >From: Emmi Takkinen <emmi.takkinen@outlook.com> >Date: Mon, 21 Sep 2020 08:46:25 +0300 >Subject: [PATCH] Bug 15156: Get all patrons with owings > >This patch adds method to return set of unique patrons with >accountlines matching filtering params. > >To test: >prove t/db_dependent/Koha/Patrons.t > >Signed-off-by: David Nind <david@davidnind.com> >--- > Koha/Patrons.pm | 23 +++++++++++++++++++ > t/db_dependent/Koha/Patrons.t | 43 +++++++++++++++++++++++++++++++++-- > 2 files changed, 64 insertions(+), 2 deletions(-) > >diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm >index 616fefacba..5104be2f9e 100644 >--- a/Koha/Patrons.pm >+++ b/Koha/Patrons.pm >@@ -483,6 +483,29 @@ sub filter_by_attribute_value { > } > > >+=head3 >+ >+ my $patrons = Koha::Patrons->filter_by_owings({ ... }); >+ >+ Returns a Koha::Patrons set of all unique patrons with accountlines >+ matching filtering params. >+ >+=cut >+ >+sub filter_by_owings { >+ my ( $self, $params ) = @_; >+ my $rs = Koha::Account::Lines->search( >+ { >+ %{$params} >+ }, >+ { >+ distinct => 1, >+ select => 'borrowernumber' >+ } >+ )->_resultset()->search_related('borrowernumber'); >+ return Koha::Patrons->_new_from_dbic($rs); >+} >+ > =head3 _type > > =cut >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index 120e981324..afb6ec4a6d 100755 >--- 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 => 42; >+use Test::More tests => 43; > use Test::Warn; > use Test::Exception; > use Test::MockModule; >@@ -2184,4 +2184,43 @@ subtest 'queue_notice' => sub { > is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter,"Count of queued notices not increased in test mode"); > }; > >-$schema->storage->txn_rollback; >+subtest 'filter_by_owings' => sub { >+ >+ plan tests => 7; >+ >+ my $library = $builder->build({source => 'Branch' }); >+ my $max_owing = 10; >+ >+ my $patrons = Koha::Patrons->filter_by_owings({ branchcode => $library->{branchcode}, amountoutstanding => { '>=' => $max_owing } }); >+ is(ref($patrons), 'Koha::Patrons', 'filter_by_owings returns set of Koha::Patrons'); >+ is($patrons->count, 0, 'Empty set of Koha::Patrons returned'); >+ >+ 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', library_id => $library->{branchcode} }); >+ >+ 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', library_id => $library->{branchcode} }); >+ >+ t::lib::Mocks::mock_userenv({ patron => $patron1 }); >+ >+ $patrons = Koha::Patrons->filter_by_owings({ branchcode => $library->{branchcode}, amountoutstanding => { '>=' => $max_owing } }); >+ is($patrons->count, 2, 'filter_by_debts() should return set of 2 patrons when filtered with amountoutstanding'); >+ >+ my $found_patron1 = $patrons->find($patron1->borrowernumber); >+ my $found_patron2 = $patrons->find($patron2->borrowernumber); >+ >+ is($found_patron1->borrowernumber, $patron1->borrowernumber, 'patron 1 returned'); >+ is($found_patron2->borrowernumber, $patron2->borrowernumber, 'patron 2 returned'); >+ >+ $account1->pay({ amount => 10, interface => 'commandline', library_id => $library->{branchcode}, manager_id => $patron1->borrowernumber }); >+ $patrons = Koha::Patrons->filter_by_owings({ branchcode => $library->{branchcode}, amountoutstanding => { '>=' => $max_owing } }); >+ >+ is( $patrons->count, 1, 'filter_by_debts() should return 1 patron when filtered with amountoutstanding'); >+ my $found_patron = $patrons->next; >+ is( $found_patron->borrowernumber, $patron2->borrowernumber, 'Only patron 2 returned'); >+ >+}; >+ >+$schema->storage->txn_rollback; >\ No newline at end of file >-- >2.20.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