Bugzilla – Attachment 129145 Details for
Bug 27946
Add a charge per article request to patron categories
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27946: Make Koha::ArticleRequest->request add a fee if required
Bug-27946-Make-KohaArticleRequest-request-add-a-fe.patch (text/plain), 3.97 KB, created by
Kyle M Hall (khall)
on 2022-01-07 12:14:42 UTC
(
hide
)
Description:
Bug 27946: Make Koha::ArticleRequest->request add a fee if required
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2022-01-07 12:14:42 UTC
Size:
3.97 KB
patch
obsolete
>From d3c7201caf521249993ad22ac14e43d844fbe3f9 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 17 Dec 2021 10:29:53 -0300 >Subject: [PATCH] Bug 27946: Make Koha::ArticleRequest->request add a fee if > required > >This patch makes the ->request method add a fee for the patron if >required. It relies on methods defined in Koha::Patron for the task. The >debit line is linked to the AR if applies. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/ArticleRequest.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/ArticleRequest.pm | 25 +++++++++++++++++++- > t/db_dependent/Koha/ArticleRequest.t | 34 +++++++++++++++++++++++++--- > 2 files changed, 55 insertions(+), 4 deletions(-) > >diff --git a/Koha/ArticleRequest.pm b/Koha/ArticleRequest.pm >index be4a895e2ef..09b19455ae8 100644 >--- a/Koha/ArticleRequest.pm >+++ b/Koha/ArticleRequest.pm >@@ -19,7 +19,7 @@ package Koha::ArticleRequest; > > use Modern::Perl; > >- >+use Koha::Account::Lines; > use Koha::Database; > use Koha::Patrons; > use Koha::Biblios; >@@ -57,6 +57,12 @@ sub request { > ) unless $self->borrower->can_request_article; > > $self->status(Koha::ArticleRequest::Status::Requested); >+ >+ # Handle possible fees >+ my $debit = $self->borrower->add_article_request_fee_if_needed({ item_id => $self->itemnumber }); >+ $self->debit_id( $debit->id ) >+ if $debit; >+ > $self->store(); > $self->notify(); > return $self; >@@ -149,6 +155,23 @@ sub biblio { > return $self->{_biblio}; > } > >+=head3 debit >+ >+ my $debit = $article_request->debit; >+ >+Returns the related Koha::Account::Line object for this article request >+ >+=cut >+ >+sub debit { >+ my ($self) = @_; >+ >+ my $debit_rs = $self->_result->debit; >+ return unless $debit_rs; >+ >+ return Koha::Account::Line->_new_from_dbic( $debit_rs ); >+} >+ > =head3 item > > Returns the Koha::Item object for this article request >diff --git a/t/db_dependent/Koha/ArticleRequest.t b/t/db_dependent/Koha/ArticleRequest.t >index 4339f2a0b2a..dfa5ec3f6ca 100755 >--- a/t/db_dependent/Koha/ArticleRequest.t >+++ b/t/db_dependent/Koha/ArticleRequest.t >@@ -30,12 +30,17 @@ my $builder = t::lib::TestBuilder->new; > > subtest 'request() tests' => sub { > >- plan tests => 3; >+ plan tests => 11; > > $schema->storage->txn_begin; > >+ my $amount = 0; >+ >+ my $patron_mock = Test::MockModule->new('Koha::Patron'); >+ $patron_mock->mock( 'article_request_fee', sub { return $amount; } ); >+ > my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >- my $biblio = $builder->build_sample_biblio; >+ my $item = $builder->build_sample_item; > > my $ar_mock = Test::MockModule->new('Koha::ArticleRequest'); > $ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } ); >@@ -43,15 +48,38 @@ subtest 'request() tests' => sub { > my $ar = Koha::ArticleRequest->new( > { > borrowernumber => $patron->id, >- biblionumber => $biblio->id, >+ biblionumber => $item->biblionumber, >+ } >+ ); >+ >+ $ar->request()->discard_changes; >+ >+ is( $ar->status, Koha::ArticleRequest::Status::Requested ); >+ ok( defined $ar->created_on, 'created_on is set' ); >+ >+ is( $ar->debit_id, undef, 'No fee linked' ); >+ is( $patron->account->balance, 0, 'No outstanding fees' ); >+ >+ # set a fee amount >+ $amount = 10; >+ >+ $ar = Koha::ArticleRequest->new( >+ { >+ borrowernumber => $patron->id, >+ biblionumber => $item->biblionumber, >+ itemnumber => $item->id, > } > ); > > $ar->request()->discard_changes; > > is( $ar->status, Koha::ArticleRequest::Status::Requested ); >+ is( $ar->itemnumber, $item->id, 'itemnumber set' ); > ok( defined $ar->created_on, 'created_on is set' ); > >+ ok( defined $ar->debit_id, 'Fee linked' ); >+ is( $patron->account->balance, $amount, 'Outstanding fees with the right value' ); >+ > $schema->storage->txn_rollback; > }; > >-- >2.30.2
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 27946
:
120144
|
120145
|
120146
|
120147
|
122522
|
122529
|
122530
|
122531
|
122532
|
122552
|
123503
|
123504
|
123505
|
123506
|
123507
|
128660
|
128661
|
128662
|
128663
|
128664
|
128665
|
128868
|
128869
|
128870
|
128871
|
128872
|
128873
|
129141
|
129142
|
129143
|
129144
|
129145
|
129146
|
129147
|
129171
|
129172
|
129173
|
129174
|
129175
|
129176
|
129177