Bugzilla – Attachment 102965 Details for
Bug 17656
Irregularities in serial prediction pattern are planned only for current subscription
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17656: Move GuessEnddate in Koha::Subscription::guess_enddate
Bug-17656-Move-GuessEnddate-in-KohaSubscriptiongue.patch (text/plain), 12.17 KB, created by
Alex Arnaud
on 2020-04-15 07:45:35 UTC
(
hide
)
Description:
Bug 17656: Move GuessEnddate in Koha::Subscription::guess_enddate
Filename:
MIME Type:
Creator:
Alex Arnaud
Created:
2020-04-15 07:45:35 UTC
Size:
12.17 KB
patch
obsolete
>From 7f1cfe8b8d4b5312843da7495bdc9dcecf065f08 Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Fri, 18 May 2018 07:58:52 +0000 >Subject: [PATCH] Bug 17656: Move GuessEnddate in > Koha::Subscription::guess_enddate > >--- > C4/Serials.pm | 35 ------ > Koha/Subscription.pm | 47 +++++++- > serials/subscription-add.pl | 26 ++++- > serials/subscription-renew.pl | 13 ++- > t/db_dependent/Koha/Subscription/GuessEnddate.t | 148 ++++++++++++++++++++++++ > 5 files changed, 220 insertions(+), 49 deletions(-) > create mode 100644 t/db_dependent/Koha/Subscription/GuessEnddate.t > >diff --git a/C4/Serials.pm b/C4/Serials.pm >index de39b5e..8aee9a2 100644 >--- a/C4/Serials.pm >+++ b/C4/Serials.pm >@@ -87,7 +87,6 @@ BEGIN { > &CountIssues > HasItems > &subscriptionCurrentlyOnOrder >- &GuessEnddate > > ); > } >@@ -2666,40 +2665,6 @@ sub findSerialsByStatus { > return @$serials; > } > >-=head2 GuessEnddate >- >-my $enddate = GuessEnddate($startdate_iso $frequencyid, $numberlength, $weeklength, $monthlength); >- >-=cut >- >-sub GuessEnddate { >- my ($startdate_iso, $frequencyid, $numberlength, $weeklength, $monthlength) = @_; >- my ($year, $month, $day); >- my $enddate; >- if($numberlength != 0) { >- my $frequency = GetSubscriptionFrequency($frequencyid); >- if($frequency->{'unit'} eq 'day') { >- ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}); >- } elsif($frequency->{'unit'} eq 'week') { >- ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}); >- } elsif($frequency->{'unit'} eq 'month') { >- ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}); >- } elsif($frequency->{'unit'} eq 'year') { >- ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0); >- } >- } elsif($weeklength != 0) { >- ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $weeklength * 7); >- } elsif($monthlength != 0) { >- ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $monthlength); >- } >- if(defined $year) { >- $enddate = sprintf("%04d-%02d-%02d", $year, $month, $day); >- } else { >- undef $enddate; >- } >- return $enddate; >-} >- > 1; > __END__ > >diff --git a/Koha/Subscription.pm b/Koha/Subscription.pm >index c395517..b9366a4 100644 >--- a/Koha/Subscription.pm >+++ b/Koha/Subscription.pm >@@ -21,6 +21,8 @@ use Modern::Perl; > > use Carp; > >+use C4::Serials::Frequency; >+ > use Koha::Database; > use Koha::Biblios; > use Koha::Acquisition::Booksellers; >@@ -30,7 +32,7 @@ use Koha::Subscription::Frequencies; > use Koha::Subscription::Numberpatterns; > use Koha::DateUtils; > use JSON; >-use Date::Calc qw( Delta_Days ); >+use Date::Calc qw( Delta_Days Add_Delta_Days Add_Delta_YM ); > > use base qw(Koha::Object Koha::Object::Mixin::AdditionalFields); > >@@ -245,9 +247,9 @@ sub lengthtype { > } > } > >-=head3 update_irregularities >+=head3 guess_irregularities > >-$subscription->update_irregularities >+my @irregularities = $subscription->guess_irregularities > > =cut > >@@ -284,6 +286,45 @@ sub guess_irregularities { > return @irregularities; > } > >+=head2 guess_enddate >+ >+my $enddate = $subscription->guess_enddate; >+ >+=cut >+ >+sub guess_enddate { >+ my ($self) = @_; >+ >+ my ($year, $month, $day, $enddate); >+ my $startdate = $self->startdate; >+ my $numberlength = $self->numberlength; >+ my $weeklength = $self->weeklength; >+ my $monthlength = $self->monthlength; >+ >+ if($numberlength != 0) { >+ my $frequency = GetSubscriptionFrequency($self->periodicity); >+ if($frequency->{'unit'} eq 'day') { >+ ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}); >+ } elsif($frequency->{'unit'} eq 'week') { >+ ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate), $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}); >+ } elsif($frequency->{'unit'} eq 'month') { >+ ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate), 0, $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}); >+ } elsif($frequency->{'unit'} eq 'year') { >+ ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0); >+ } >+ } elsif($weeklength != 0) { >+ ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate), $weeklength * 7); >+ } elsif($monthlength != 0) { >+ ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate), 0, $monthlength); >+ } >+ if(defined $year) { >+ $enddate = sprintf("%04d-%02d-%02d", $year, $month, $day); >+ } else { >+ undef $enddate; >+ } >+ return $enddate; >+} >+ > =head3 type > > =cut >diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl >index 8d7e25c..f4b33fd 100755 >--- a/serials/subscription-add.pl >+++ b/serials/subscription-add.pl >@@ -337,11 +337,18 @@ sub redirect_add_subscription { > my $firstacquidate = output_pref( { str => scalar $query->param('firstacquidate'), dateonly => 1, dateformat => 'iso' } ); > > if(!defined $enddate || $enddate eq '') { >+ my $subscription = Koha::Subscriptions->new({ >+ startdate => $startdate, >+ periodicity => $periodicity, >+ weeklength => $weeklength, >+ monthlength =>$monthlength, >+ numberlength => $numberlength >+ }); >+ > if($subtype eq "issues") { >- $enddate = GuessEnddate($firstacquidate, $periodicity, $numberlength, $weeklength, $monthlength) >- } else { >- $enddate = GuessEnddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength) >+ $subscription->startdate($firstacquidate); > } >+ $enddate = $subscription->guess_enddate; > } > my $subscriptionid = NewSubscription( > $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, >@@ -451,11 +458,18 @@ sub redirect_mod_subscription { > > # Guess end date > if(!defined $enddate || $enddate eq '') { >+ my $subscription = Koha::Subscriptions->new({ >+ startdate => $startdate, >+ periodicity => $periodicity, >+ weeklength => $weeklength, >+ monthlength =>$monthlength, >+ numberlength => $numberlength >+ }); >+ > if($subtype eq "issues") { >- $enddate = GuessEnddate($nextacquidate, $periodicity, $numberlength, $weeklength, $monthlength); >- } else { >- $enddate = GuessEnddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength); >+ $subscription->startdate($nextacquidate); > } >+ $enddate = $subscription->guess_enddate; > } > > my $nextexpected = GetNextExpected($subscriptionid); >diff --git a/serials/subscription-renew.pl b/serials/subscription-renew.pl >index d3edaf3..c19979cf7 100755 >--- a/serials/subscription-renew.pl >+++ b/serials/subscription-renew.pl >@@ -147,11 +147,14 @@ if ( $op eq "renew" ) { > my $subscription_o = Koha::Subscriptions->find($subscription->{subscriptionid}); > my $lengthtype = $subscription_o->lengthtype; > my $nextexpected = GetNextExpected($subscriptionid); >- my $enddate = GuessEnddate($subscription->{enddate} || dt_from_string, >- $subscription->{periodicity}, >- $subscription->{numberlength}, >- $subscription->{weeklength}, >- $subscription->{monthlength}); >+ $subscription_o->update({ >+ startdate => $subscription->{enddate}, >+ periodicity => $subscription->{periodicity}, >+ weeklength => $subscription->{weeklength}, >+ monthlength => $subscription->{monthlength}, >+ numberlength => $subscription->{numberlength} >+ }); >+ my $enddate = $subscription_o->guess_enddate; > > my $sub_length; > foreach my $length_unit (qw(numberlength weeklength monthlength)) { >diff --git a/t/db_dependent/Koha/Subscription/GuessEnddate.t b/t/db_dependent/Koha/Subscription/GuessEnddate.t >new file mode 100644 >index 0000000..c16fb32 >--- /dev/null >+++ b/t/db_dependent/Koha/Subscription/GuessEnddate.t >@@ -0,0 +1,148 @@ >+#!/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 >+# WIT HOUT 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 => 15; >+use t::lib::TestBuilder; >+ >+use Koha::Database; >+use Koha::Subscriptions; >+ >+BEGIN { >+ use_ok('Koha::Subscriptions'); >+} >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+$schema->storage->txn_begin; >+ >+ >+my $frequency = $builder->build({ >+ source => 'SubscriptionFrequency', >+ value => { >+ unit => 'day', >+ unitsperissue => 1, >+ issuesperunit => 1 >+ } >+}); >+ >+my $subscription = $builder->build({ >+ source => 'Subscription', >+ value => { >+ startdate => '2018-01-01', >+ weeklength => 0, >+ monthlength => 0, >+ numberlength => 7, >+ periodicity => $frequency->{id}, >+ } >+}); >+ >+$subscription = Koha::Subscriptions->find($subscription->{subscriptionid}); >+$frequency = $schema->resultset('SubscriptionFrequency')->find($frequency->{id}); >+is($subscription->guess_enddate, '2018-01-08'); >+ >+$frequency->update({ >+ unit => 'day', >+ unitsperissue => 2, >+ issuesperunit => 1 >+}); >+is($subscription->guess_enddate, '2018-01-15'); >+ >+$frequency->update({ >+ unit => 'day', >+ unitsperissue => 1, >+ issuesperunit => 2 >+}); >+is($subscription->guess_enddate, '2018-01-04'); >+ >+$frequency->update({ >+ unit => 'week', >+ unitsperissue => 1, >+ issuesperunit => 1 >+}); >+is($subscription->guess_enddate, '2018-02-19'); >+ >+$frequency->update({ >+ unit => 'week', >+ unitsperissue => 2, >+ issuesperunit => 1 >+}); >+is($subscription->guess_enddate, '2018-04-09'); >+ >+$frequency->update({ >+ unit => 'week', >+ unitsperissue => 1, >+ issuesperunit => 2 >+}); >+is($subscription->guess_enddate, '2018-01-25'); >+ >+$frequency->update({ >+ unit => 'month', >+ unitsperissue => 1, >+ issuesperunit => 1 >+}); >+is($subscription->guess_enddate, '2018-08-01'); >+ >+$frequency->update({ >+ unit => 'month', >+ unitsperissue => 2, >+ issuesperunit => 1 >+}); >+is($subscription->guess_enddate, '2019-03-01'); >+ >+$frequency->update({ >+ unit => 'month', >+ unitsperissue => 1, >+ issuesperunit => 2 >+}); >+is($subscription->guess_enddate, '2018-04-01'); >+ >+$frequency->update({ >+ unit => 'year', >+ unitsperissue => 1, >+ issuesperunit => 1 >+}); >+is($subscription->guess_enddate, '2025-01-01'); >+ >+$frequency->update({ >+ unit => 'year', >+ unitsperissue => 2, >+ issuesperunit => 1 >+}); >+is($subscription->guess_enddate, '2032-01-01'); >+ >+$frequency->update({ >+ unit => 'year', >+ unitsperissue => 1, >+ issuesperunit => 2 >+}); >+is($subscription->guess_enddate, '2021-01-01'); >+ >+ >+$subscription->numberlength(0); >+$subscription->weeklength(2); >+$subscription->store; >+is($subscription->guess_enddate, '2018-01-15'); >+ >+$subscription->weeklength(0); >+$subscription->monthlength(1); >+$subscription->store; >+is($subscription->guess_enddate, '2018-02-01'); >+ >+$schema->storage->txn_rollback; >-- >2.7.4
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 17656
:
68259
|
68261
|
68607
|
68608
|
68665
|
69124
|
69207
|
69279
|
69553
|
69814
|
69820
|
69915
|
70335
|
70336
|
70430
|
70619
|
75403
|
75404
|
75405
|
75406
|
75407
|
75408
|
75721
|
75722
|
75723
|
75724
|
75725
|
75726
|
75953
|
102724
|
102725
|
102726
|
102727
|
102728
|
102729
|
102730
|
102860
|
102861
|
102862
|
102863
|
102864
|
102865
|
102866
|
102867
|
102960
|
102961
|
102962
|
102963
|
102964
|
102965
|
102966
|
102967
|
102968
|
103623
|
103624
|
103625
|
103626
|
103627
|
103628
|
103629
|
103630
|
103631
|
103657
|
103658
|
103659
|
103660
|
103661
|
103662
|
103663
|
103664
|
103665
|
103667
|
117789
|
117790
|
117791
|
117792
|
117846
|
117851
|
117852
|
118856
|
119106
|
120863
|
121082
|
121083
|
121084
|
121085
|
121086
|
121087
|
121088
|
121192
|
121193
|
121194
|
121195
|
121196
|
121197
|
121198
|
121296
|
121297
|
121298
|
121299
|
121300
|
121301
|
121302
|
128489
|
128491
|
128492
|
128493
|
128494
|
128495
|
128496
|
128498
|
128499
|
128500
|
128501
|
128502
|
128503
|
128504
|
132412
|
132413
|
132415
|
132416
|
132417
|
132418
|
132447
|
132448
|
132692
|
132779