Bugzilla – Attachment 102555 Details for
Bug 24159
Allow daysMode for calculating due and renewal dates to be set at the circulation rules level
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24159: Move useDaysMode pref to circulation rules
Bug-24159-Move-useDaysMode-pref-to-circulation-rul.patch (text/plain), 6.12 KB, created by
PTFS Europe Sandboxes
on 2020-04-08 11:47:43 UTC
(
hide
)
Description:
Bug 24159: Move useDaysMode pref to circulation rules
Filename:
MIME Type:
Creator:
PTFS Europe Sandboxes
Created:
2020-04-08 11:47:43 UTC
Size:
6.12 KB
patch
obsolete
>From 5077628e39ecf1889eab8109d41557183fbd654f Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 28 Feb 2020 13:29:09 +0100 >Subject: [PATCH] Bug 24159: Move useDaysMode pref to circulation rules > >Moving the useDaysMode system preference to a circulation rule will add >much more flexibility in the calculation of the due date. > >The initial request was to make hourly loan returned on closed when >(when checked out on the same close day). >To do so we do not want to take into account the calendar. >However the calendar need to be taken into account for other loan item types. > >Other scenarios are possible, for instance depending on the branch. > >This patchset will add a new "Days mode" column (next to "Loan period") >to the circulation rules page, with the different values of the >"useDaysMode" system preference + a "default" value, to default to the >system preference value. > >Test plan: >- Define a long loan item type (like 10 days) that will use the calendar >(or default to the pref value, if the pref is not set to "ignore the >calendar") >- and a hourly loan (like 2 hours) that will ignore the calendar >- Create items with those item types >- Mark today as a closed day >- Check the items out >=> The hourly loan is due the same day >=> The other loan is due on an open day > >QA note: >There is the need to force the "days_mode" option when Koha::Calendar is >initiated for the due date calculation. To make sure devs will not >forget it, the methods that need have it defined will throw an >exception. > >Sponsored-by: Institute of Technology Carlow > >Signed-off-by: Simon Perry <simon.perry@itcarlow.ie> >--- > C4/Circulation.pm | 18 +++++++++++++----- > C4/UsageStats.pm | 1 - > Koha/CirculationRules.pm | 30 ++++++++++++++++++++++++++++++ > t/db_dependent/UsageStats.t | 1 - > 4 files changed, 43 insertions(+), 7 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 3374ebef79..80651eb863 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -3565,7 +3565,7 @@ sub updateWrongTransfer { > $newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower); > > this function calculates the due date given the start date and configured circulation rules, >-checking against the holidays calendar as per the 'useDaysMode' syspref. >+checking against the holidays calendar as per the useDaysMode circulation rule. > C<$startdate> = DateTime object representing start date of loan period (assumed to be today) > C<$itemtype> = itemtype code of item in question > C<$branch> = location whose calendar to use >@@ -3601,8 +3601,16 @@ sub CalcDateDue { > } > > >+ my $useDaysMode_value = Koha::CirculationRules->get_useDaysMode_effective_value( >+ { >+ categorycode => $borrower->{categorycode}, >+ itemtype => $itemtype, >+ branchcode => $branch, >+ } >+ ); >+ > # calculate the datedue as normal >- if ( C4::Context->preference('useDaysMode') eq 'Days' ) >+ if ( $useDaysMode_value eq 'Days' ) > { # ignoring calendar > if ( $loanlength->{lengthunit} eq 'hours' ) { > $datedue->add( hours => $loanlength->{$length_key} ); >@@ -3619,7 +3627,7 @@ sub CalcDateDue { > else { # days > $dur = DateTime::Duration->new( days => $loanlength->{$length_key}); > } >- my $calendar = Koha::Calendar->new( branchcode => $branch ); >+ my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $useDaysMode_value ); > $datedue = $calendar->addDate( $datedue, $dur, $loanlength->{lengthunit} ); > if ($loanlength->{lengthunit} eq 'days') { > $datedue->set_hour(23); >@@ -3657,8 +3665,8 @@ sub CalcDateDue { > $datedue = $expiry_dt->clone->set_time_zone( C4::Context->tz ); > } > } >- if ( C4::Context->preference('useDaysMode') ne 'Days' ) { >- my $calendar = Koha::Calendar->new( branchcode => $branch ); >+ if ( $useDaysMode_value ne 'Days' ) { >+ my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $useDaysMode_value ); > if ( $calendar->is_holiday($datedue) ) { > # Don't return on a closed day > $datedue = $calendar->prev_open_days( $datedue, 1 ); >diff --git a/C4/UsageStats.pm b/C4/UsageStats.pm >index d608eb9ea9..5cc871d703 100644 >--- a/C4/UsageStats.pm >+++ b/C4/UsageStats.pm >@@ -155,7 +155,6 @@ sub BuildReport { > ReturnBeforeExpiry > TransfersMaxDaysWarning > UseBranchTransferLimits >- useDaysMode > UseTransportCostMatrix > UseCourseReserves > finesCalendar >diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm >index 5042e6f55d..df68310aee 100644 >--- a/Koha/CirculationRules.pm >+++ b/Koha/CirculationRules.pm >@@ -487,6 +487,36 @@ sub guess_article_requestable_itemtypes { > return $res; > } > >+=head3 get_useDaysMode_effective_value >+ >+Return the value for useDaysMode defined in the circulation rules. >+If not defined (or empty string), the value of the system preference useDaysMode is returned >+ >+=cut >+ >+sub get_useDaysMode_effective_value { >+ my ( $class, $params ) = @_; >+ >+ my $categorycode = $params->{categorycode}; >+ my $itemtype = $params->{itemtype}; >+ my $branchcode = $params->{branchcode}; >+ >+ my $useDaysMode_rule = $class->get_effective_rule( >+ { >+ categorycode => $categorycode, >+ itemtype => $itemtype, >+ branchcode => $branchcode, >+ rule_name => 'useDaysMode', >+ } >+ ); >+ >+ return ( defined($useDaysMode_rule) >+ and $useDaysMode_rule->rule_value ne '' ) >+ ? $useDaysMode_rule->rule_value >+ : C4::Context->preference('useDaysMode'); >+ >+} >+ > > =head3 type > >diff --git a/t/db_dependent/UsageStats.t b/t/db_dependent/UsageStats.t >index 1aabf76138..b874c2e08b 100644 >--- a/t/db_dependent/UsageStats.t >+++ b/t/db_dependent/UsageStats.t >@@ -416,7 +416,6 @@ sub mocking_systempreferences_to_a_set_value { > ReturnBeforeExpiry > TransfersMaxDaysWarning > UseBranchTransferLimits >- useDaysMode > UseTransportCostMatrix > UseCourseReserves > finesCalendar >-- >2.11.0
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 24159
:
99758
|
99759
|
99760
|
99761
|
99762
|
100608
|
100609
|
100610
|
100611
|
100612
|
100613
|
100614
|
100615
|
101053
|
101054
|
101556
|
101649
|
101698
|
102009
|
102148
|
102303
|
102554
|
102555
|
102556
|
102557
|
102558
|
102559
|
102560
|
102561
|
102562
|
102563
|
104197
|
104198
|
104199
|
104200
|
104201
|
104202
|
104203
|
104204
|
106007
|
106008
|
106013
|
106014
|
106015
|
106016
|
106017
|
106018
|
106019
|
106020
|
106021
|
106022