Bugzilla – Attachment 58293 Details for
Bug 17689
Add the Koha::Issue->is_overdue method
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17689: Add the Koha::Checkout->is_overdue method
Bug-17689-Add-the-KohaCheckout-isoverdue-method.patch (text/plain), 4.20 KB, created by
Jonathan Druart
on 2016-12-20 13:40:12 UTC
(
hide
)
Description:
Bug 17689: Add the Koha::Checkout->is_overdue method
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-12-20 13:40:12 UTC
Size:
4.20 KB
patch
obsolete
>From 01dfc766741406d5ec79766d5203dbef10153326 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 25 Nov 2016 14:16:26 +0100 >Subject: [PATCH] Bug 17689: Add the Koha::Checkout->is_overdue method > >This patch adds a new method Koha::Checkout->is_overdue and provide tests >to cover it. >The goal is to behave like GetItemIssues set the 'overdue' flag to >issues. >I don't understand why the existing GetItemIssues truncate dates to >minutes, so I did not recreate this behavior. > >Test plan: > prove t/db_dependent/Koha/Checkouts.t >should return green > >Signed-off-by: Mika Smith <mikasmith@catalyst.net.nz> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/Checkout.pm | 26 ++++++++++++++++++++++++++ > t/db_dependent/Koha/Checkouts.t | 35 +++++++++++++++++++++++++++++++++-- > 2 files changed, 59 insertions(+), 2 deletions(-) > >diff --git a/Koha/Checkout.pm b/Koha/Checkout.pm >index 358f41c..a1a67d6 100644 >--- a/Koha/Checkout.pm >+++ b/Koha/Checkout.pm >@@ -1,6 +1,7 @@ > package Koha::Checkout; > > # Copyright ByWater Solutions 2015 >+# Copyright 2016 Koha Development Team > # > # This file is part of Koha. > # >@@ -22,6 +23,8 @@ use Modern::Perl; > use Carp; > > use Koha::Database; >+use DateTime; >+use Koha::DateUtils; > > use base qw(Koha::Object); > >@@ -35,6 +38,27 @@ Koha::Checkout - Koha Checkout object class > > =cut > >+=head3 is_overdue >+ >+my $is_overdue = $checkout->is_overdue( [ $reference_dt ] ); >+ >+Return 1 if the checkout is overdue. >+ >+A reference date can be passed, in this case it will be used, otherwise today >+will be the reference date. >+ >+=cut >+ >+sub is_overdue { >+ my ( $self, $dt ) = @_; >+ $dt ||= DateTime->now( time_zone => C4::Context->tz ); >+ my $is_overdue = >+ DateTime->compare( dt_from_string( $self->date_due, 'sql' ), $dt ) == -1 >+ ? 1 >+ : 0; >+ return $is_overdue; >+} >+ > =head3 type > > =cut >@@ -47,6 +71,8 @@ sub _type { > > Kyle M Hall <kyle@bywatersolutions.com> > >+Jonathan Druart <jonathan.druart@bugs.koha-community.org> >+ > =cut > > 1; >diff --git a/t/db_dependent/Koha/Checkouts.t b/t/db_dependent/Koha/Checkouts.t >index e8b1341..ba85bb2 100644 >--- a/t/db_dependent/Koha/Checkouts.t >+++ b/t/db_dependent/Koha/Checkouts.t >@@ -19,11 +19,11 @@ > > use Modern::Perl; > >-use Test::More tests => 4; >+use Test::More tests => 5; > >-use Koha::Checkout; > use Koha::Checkouts; > use Koha::Database; >+use Koha::DateUtils qw( dt_from_string ); > > use t::lib::TestBuilder; > >@@ -55,6 +55,37 @@ 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 'is_overdue' => sub { >+ plan tests => 6; >+ my $ten_days_ago = dt_from_string->add( days => -10 ); >+ my $ten_days_later = dt_from_string->add( days => 10 ); >+ my $yesterday = dt_from_string->add( days => -1 ); >+ my $tomorrow = dt_from_string->add( days => 1 ); >+ >+ $retrieved_checkout_1->date_due($ten_days_ago)->store; >+ is( $retrieved_checkout_1->is_overdue, >+ 1, 'The item should have been returned 10 days ago' ); >+ >+ $retrieved_checkout_1->date_due($ten_days_later)->store; >+ is( $retrieved_checkout_1->is_overdue, 0, 'The item is due in 10 days' ); >+ >+ $retrieved_checkout_1->date_due($tomorrow)->store; >+ is( $retrieved_checkout_1->is_overdue($ten_days_later), >+ 1, 'The item should have been returned yesterday' ); >+ >+ $retrieved_checkout_1->date_due($yesterday)->store; >+ is( $retrieved_checkout_1->is_overdue($ten_days_ago), >+ 0, 'Ten days ago the item due yesterday was not late' ); >+ >+ $retrieved_checkout_1->date_due($tomorrow)->store; >+ is( $retrieved_checkout_1->is_overdue($ten_days_later), >+ 1, 'In Ten days, the item due tomorrow will be late' ); >+ >+ $retrieved_checkout_1->date_due($yesterday)->store; >+ is( $retrieved_checkout_1->is_overdue($ten_days_ago), >+ 0, 'In Ten days, the item due yesterday will still be late' ); >+}; >+ > $retrieved_checkout_1->delete; > is( Koha::Checkouts->search->count, $nb_of_checkouts + 1, 'Delete should have deleted the checkout' ); > >-- >2.9.3
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 17689
:
57786
|
57810
|
57864
| 58293