Bugzilla – Attachment 102661 Details for
Bug 25037
Add checkout_type to checkouts
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25037: Add Koha::Checkouts checkout_type constants and TT plugin
Bug-25037-Add-KohaCheckouts-checkouttype-constants.patch (text/plain), 6.02 KB, created by
Lari Taskula
on 2020-04-09 20:00:54 UTC
(
hide
)
Description:
Bug 25037: Add Koha::Checkouts checkout_type constants and TT plugin
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2020-04-09 20:00:54 UTC
Size:
6.02 KB
patch
obsolete
>From d6ea8ecfdd655990ccbaf4ddea451f7d66bf73ad Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@hypernova.fi> >Date: Wed, 1 Apr 2020 16:01:37 +0000 >Subject: [PATCH] Bug 25037: Add Koha::Checkouts checkout_type constants and TT > plugin > >Also make it available for templates. > >To test: >1. prove t/db_dependent/Koha/Checkouts.t >2. prove t/db_dependent/Template/Plugin/Checkouts.t > >Sponsored-by: The National Library of Finland >--- > Koha/Checkout.pm | 13 +++++ > Koha/Checkouts.pm | 13 +++++ > Koha/Template/Plugin/Checkouts.pm | 61 ++++++++++++++++++++++ > t/db_dependent/Koha/Checkouts.t | 21 +++++++- > t/db_dependent/Template/Plugin/Checkouts.t | 31 +++++++++++ > 5 files changed, 138 insertions(+), 1 deletion(-) > create mode 100644 Koha/Template/Plugin/Checkouts.pm > create mode 100644 t/db_dependent/Template/Plugin/Checkouts.t > >diff --git a/Koha/Checkout.pm b/Koha/Checkout.pm >index 9180bf4df7..a5797b3bca 100644 >--- a/Koha/Checkout.pm >+++ b/Koha/Checkout.pm >@@ -41,6 +41,19 @@ Koha::Checkout - Koha Checkout object class > > =cut > >+=head3 is_onsite_checkout >+ >+my is_onsite_checkout = $checkout->is_onsite_checkout(); >+ >+Return 1 if the checkout is an on-site checkout. >+ >+=cut >+ >+sub is_onsite_checkout { >+ my ( $self ) = @_; >+ return $self->checkout_type eq $Koha::Checkouts::type->{onsite_checkout}; >+} >+ > =head3 is_overdue > > my $is_overdue = $checkout->is_overdue( [ $reference_dt ] ); >diff --git a/Koha/Checkouts.pm b/Koha/Checkouts.pm >index 84d4253e72..8f61fdce87 100644 >--- a/Koha/Checkouts.pm >+++ b/Koha/Checkouts.pm >@@ -55,6 +55,19 @@ sub calculate_dropbox_date { > return $dropbox_date; > } > >+=cut >+ >+=head2 Name to code mappings >+ >+=head3 $type >+ >+=cut >+ >+our $type = { >+ 'checkout' => 'C', >+ 'onsite_checkout' => 'OS', >+}; >+ > =head3 type > > =cut >diff --git a/Koha/Template/Plugin/Checkouts.pm b/Koha/Template/Plugin/Checkouts.pm >new file mode 100644 >index 0000000000..c0a20745c3 >--- /dev/null >+++ b/Koha/Template/Plugin/Checkouts.pm >@@ -0,0 +1,61 @@ >+package Koha::Template::Plugin::Checkouts; >+ >+# Copyright 2020 Hypernova Oy >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+=head1 NAME >+ >+Koha::Template::Plugin::Checkouts >+ >+=head1 DESCRIPTION >+ >+The Checkouts plugin is a helper for using Koha::Checkouts in templates. >+ >+=head1 SYNOPSYS >+ >+ [% USE Checkouts %] >+ >+=cut >+ >+use Modern::Perl; >+ >+use Template::Plugin; >+use base qw( Template::Plugin ); >+ >+use C4::Koha; >+use C4::Context; >+use Koha::Checkouts; >+ >+=head1 FUNCTIONS >+ >+=head2 type >+ >+Returns $Koha::Checkouts::type HASHref. >+ >+Usage: >+ >+ [% IF (checkout_type == Checkouts.type.onsite_checkout %] >+ ... >+ [% END %] >+ >+=cut >+ >+sub type { >+ return $Koha::Checkouts::type; >+} >+ >+1; >diff --git a/t/db_dependent/Koha/Checkouts.t b/t/db_dependent/Koha/Checkouts.t >index dfb90e42a8..e584dae1e6 100644 >--- a/t/db_dependent/Koha/Checkouts.t >+++ b/t/db_dependent/Koha/Checkouts.t >@@ -19,7 +19,8 @@ > > use Modern::Perl; > >-use Test::More tests => 7; >+use Test::More tests => 9; >+use Test::Exception; > > use C4::Circulation; > use Koha::Checkouts; >@@ -56,6 +57,24 @@ is( Koha::Checkouts->search->count, $nb_of_checkouts + 2, 'The 2 checkouts shoul > my $retrieved_checkout_1 = Koha::Checkouts->find( $new_checkout_1->issue_id ); > is( $retrieved_checkout_1->itemnumber, $new_checkout_1->itemnumber, 'Find a checkout by id should return the correct checkout' ); > >+subtest 'Koha::Checkouts checkout_codes' => sub { >+ plan tests => 2; >+ is( $Koha::Checkouts::type->{checkout}, 'C' ); >+ is( $Koha::Checkouts::type->{onsite_checkout}, 'OS' ); >+}; >+ >+subtest 'is_onsite_checkout' => sub { >+ plan tests => 2; >+ >+ my $old_checkout_type = $retrieved_checkout_1->checkout_type; >+ $new_checkout_1->checkout_type($Koha::Checkouts::type->{checkout})->store; >+ ok( !$new_checkout_1->is_onsite_checkout, 'It is not on-site checkout' ); >+ $new_checkout_1->checkout_type($Koha::Checkouts::type->{onsite_checkout})->store; >+ is( $new_checkout_1->is_onsite_checkout, >+ 1, 'It is an on-site checkout' ); >+ $new_checkout_1->checkout_type($old_checkout_type)->store; >+}; >+ > subtest 'is_overdue' => sub { > plan tests => 6; > my $ten_days_ago = dt_from_string->add( days => -10 ); >diff --git a/t/db_dependent/Template/Plugin/Checkouts.t b/t/db_dependent/Template/Plugin/Checkouts.t >new file mode 100644 >index 0000000000..890b856da2 >--- /dev/null >+++ b/t/db_dependent/Template/Plugin/Checkouts.t >@@ -0,0 +1,31 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+use Koha::Template::Plugin::Checkouts; >+ >+subtest 'type() tests' => sub { >+ plan tests => 2; >+ >+ is( Koha::Template::Plugin::Checkouts->new->type->{checkout}, 'C' ); >+ is( Koha::Template::Plugin::Checkouts->new->type->{onsite_checkout}, 'OS' ); >+}; >-- >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 25037
:
102259
|
102260
|
102261
|
102262
|
102263
|
102264
|
102265
|
102266
|
102267
|
102268
|
102269
|
102272
|
102413
|
102414
|
102415
|
102416
|
102417
|
102418
|
102419
|
102420
|
102421
|
102422
|
102423
|
102424
|
102586
|
102587
|
102588
|
102589
|
102590
|
102591
|
102592
|
102593
|
102594
|
102595
|
102596
|
102597
|
102598
|
102599
|
102655
|
102656
|
102657
|
102658
|
102659
|
102660
|
102661
|
102662
|
102663
|
102664
|
102665
|
102666
|
102675
|
102676
|
104267
|
104268
|
105638
|
105780
|
105781
|
105782
|
105783
|
105784