Bugzilla – Attachment 57786 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::Issue->is_overdue method
Bug-17689-Add-the-KohaIssue-isoverdue-method.patch (text/plain), 3.71 KB, created by
Jonathan Druart
on 2016-11-28 09:37:15 UTC
(
hide
)
Description:
Bug 17689: Add the Koha::Issue->is_overdue method
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-11-28 09:37:15 UTC
Size:
3.71 KB
patch
obsolete
>From 36f57eaad730ff4619b6430443a75b5f42f0a144 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::Issue->is_overdue method > >This patch adds a new method Koha::Issue->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/Issues.t >should return green >--- > Koha/Issue.pm | 33 +++++++++++++++++++++++++++++++++ > t/db_dependent/Koha/Issues.t | 34 +++++++++++++++++++++++++++++++++- > 2 files changed, 66 insertions(+), 1 deletion(-) > >diff --git a/Koha/Issue.pm b/Koha/Issue.pm >index 8b67235..394439b 100644 >--- a/Koha/Issue.pm >+++ b/Koha/Issue.pm >@@ -18,9 +18,42 @@ package Koha::Issue; > use Modern::Perl; > > use Koha::Database; >+use DateTime; >+use Koha::DateUtils; > > use base qw(Koha::Object); > >+=head1 NAME >+ >+Koha::Issue - Koha Issue Object class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 is_overdue >+ >+my $is_overdue = $issue->is_overdue( [ $reference_dt ] ); >+ >+Return 1 if the issue 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; >+} >+ > sub _type { > return 'Issue'; > } >diff --git a/t/db_dependent/Koha/Issues.t b/t/db_dependent/Koha/Issues.t >index 38023c8..60a5117 100644 >--- a/t/db_dependent/Koha/Issues.t >+++ b/t/db_dependent/Koha/Issues.t >@@ -19,11 +19,12 @@ > > use Modern::Perl; > >-use Test::More tests => 4; >+use Test::More tests => 5; > > use Koha::Issue; > use Koha::Issues; > use Koha::Database; >+use Koha::DateUtils; > > use t::lib::TestBuilder; > >@@ -52,6 +53,37 @@ is( Koha::Issues->search->count, $nb_of_issues + 2, 'The 2 issues should have be > my $retrieved_issue_1 = Koha::Issues->find( $new_issue_1->issue_id ); > is( $retrieved_issue_1->itemnumber, $new_issue_1->itemnumber, 'Find a issue by id should return the correct issue' ); > >+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_issue_1->date_due($ten_days_ago)->store; >+ is( $retrieved_issue_1->is_overdue, >+ 1, 'The item should have been returned 10 days ago' ); >+ >+ $retrieved_issue_1->date_due($ten_days_later)->store; >+ is( $retrieved_issue_1->is_overdue, 0, 'The item is due in 10 days' ); >+ >+ $retrieved_issue_1->date_due($tomorrow)->store; >+ is( $retrieved_issue_1->is_overdue($ten_days_later), >+ 1, 'The item should have been returned yesterday' ); >+ >+ $retrieved_issue_1->date_due($yesterday)->store; >+ is( $retrieved_issue_1->is_overdue($ten_days_ago), >+ 0, 'Ten days ago the item due yesterday was not late' ); >+ >+ $retrieved_issue_1->date_due($tomorrow)->store; >+ is( $retrieved_issue_1->is_overdue($ten_days_later), >+ 1, 'In Ten days, the item due tomorrow will be late' ); >+ >+ $retrieved_issue_1->date_due($yesterday)->store; >+ is( $retrieved_issue_1->is_overdue($ten_days_ago), >+ 0, 'In Ten days, the item due yesterday will still be late' ); >+}; >+ > $retrieved_issue_1->delete; > is( Koha::Issues->search->count, $nb_of_issues + 1, 'Delete should delete the issue' ); > >-- >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