Bugzilla – Attachment 137293 Details for
Bug 30650
Add a curbside pickup module
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30650: Allow to restrict curbside pickup for waiting holds only
Bug-30650-Allow-to-restrict-curbside-pickup-for-wa.patch (text/plain), 17.02 KB, created by
Jonathan Druart
on 2022-07-07 13:02:19 UTC
(
hide
)
Description:
Bug 30650: Allow to restrict curbside pickup for waiting holds only
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2022-07-07 13:02:19 UTC
Size:
17.02 KB
patch
obsolete
>From ef3ad2f7fa3ff61bcd4f4ce1ecd83c87561e0846 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 10 May 2022 09:04:36 +0200 >Subject: [PATCH] Bug 30650: Allow to restrict curbside pickup for waiting > holds only > >Sponsored-by: Association KohaLa - https://koha-fr.org/ > >Signed-off-by: Koha Team University Lyon 3 <koha@univ-lyon3.fr> >--- > Koha/CurbsidePickup.pm | 16 ++++- > Koha/CurbsidePickupPolicy.pm | 16 +++++ > Koha/Exceptions/CurbsidePickup.pm | 4 ++ > admin/curbside_pickup.pl | 1 + > .../prog/en/modules/admin/curbside_pickup.tt | 10 +++ > .../prog/en/modules/circ/curbside_pickups.tt | 42 +++++++------ > .../en/modules/opac-curbside-pickups.tt | 15 +++++ > t/db_dependent/Koha/CurbsidePickups.t | 61 ++++++++----------- > 8 files changed, 107 insertions(+), 58 deletions(-) > >diff --git a/Koha/CurbsidePickup.pm b/Koha/CurbsidePickup.pm >index b9de7a514d0..c82c7fa3148 100644 >--- a/Koha/CurbsidePickup.pm >+++ b/Koha/CurbsidePickup.pm >@@ -49,6 +49,20 @@ Koha::CurbsidePickup - Koha Curbside Pickup Object class > sub new { > my ( $self, $params ) = @_; > >+ my $policy = >+ Koha::CurbsidePickupPolicies->find( { branchcode => $params->{branchcode} } ); >+ >+ Koha::Exceptions::CubsidePickup::NotEnabled->throw >+ unless $policy && $policy->enabled; >+ >+ if ( $policy->enable_waiting_holds_only ) { >+ my $patron = Koha::Patrons->find( $params->{borrowernumber} ); >+ my $waiting_holds = $patron->holds->search( >+ { found => 'W', branchcode => $params->{branchcode} } ); >+ >+ Koha::Exceptions::CubsidePickup::NoWaitingHolds->throw >+ unless $waiting_holds->count; >+ } > my $existing_curbside_pickups = Koha::CurbsidePickups->search( > { > branchcode => $params->{branchcode}, >@@ -62,8 +76,6 @@ sub new { > borrowernumber => $params->{borrowernumber} > ) if $existing_curbside_pickups->count; > >- my $policy = >- Koha::CurbsidePickupPolicies->find( { branchcode => $params->{branchcode} } ); > my $is_valid = > $policy->is_valid_pickup_datetime( $params->{scheduled_pickup_datetime} ); > unless ($is_valid) { >diff --git a/Koha/CurbsidePickupPolicy.pm b/Koha/CurbsidePickupPolicy.pm >index 118e178f498..07e0719d170 100644 >--- a/Koha/CurbsidePickupPolicy.pm >+++ b/Koha/CurbsidePickupPolicy.pm >@@ -47,6 +47,14 @@ sub library { > return Koha::Library->_new_from_dbic( $rs ); > } > >+=head3 opening_slots >+ >+$policy->opening_slots >+ >+Return the list of opening slots (Koha::CurbsidePickupOpeningSlots object) >+ >+=cut >+ > sub opening_slots { > my ( $self ) = @_; > my $rs = $self->_result->curbside_pickup_opening_slots; >@@ -54,6 +62,14 @@ sub opening_slots { > return Koha::CurbsidePickupOpeningSlots->_new_from_dbic( $rs ); > } > >+=head3 add_opening_slot >+ >+$policy->add("$d-12:00-15:00"); >+ >+Add a new opening slot for this library. It must be formatted "day:start:end" with 'start' and 'end' in 24-hour format. >+ >+=cut >+ > sub add_opening_slot { > my ( $self, $slot ) = @_; > >diff --git a/Koha/Exceptions/CurbsidePickup.pm b/Koha/Exceptions/CurbsidePickup.pm >index 72c9a5f9b8a..a1e10d0c3fb 100644 >--- a/Koha/Exceptions/CurbsidePickup.pm >+++ b/Koha/Exceptions/CurbsidePickup.pm >@@ -41,6 +41,10 @@ use Exception::Class ( > isa => 'Koha::Exceptions::CurbsidePickup', > description => 'No more pickups available for this slot', > }, >+ 'Koha::Exceptions::CubsidePickup::NoWaitingHolds' => { >+ isa => 'Koha::Exceptions::CurbsidePickup', >+ description => 'Cannot create a pickup, patron does not have waiting holds', >+ }, > ); > > 1; >diff --git a/admin/curbside_pickup.pl b/admin/curbside_pickup.pl >index 21992c00f7d..528d8466116 100755 >--- a/admin/curbside_pickup.pl >+++ b/admin/curbside_pickup.pl >@@ -45,6 +45,7 @@ if ( $op eq 'save' ) { > my $params = { > branchcode => $branchcode, > enabled => scalar $input->param("enable-$branchcode") || 0, >+ enable_waiting_holds_only => scalar $input->param("enable-waiting-holds-only-$branchcode") || 0, > pickup_interval => scalar $input->param("interval-$branchcode"), > patrons_per_interval => scalar $input->param("max-per-interval-$branchcode"), > patron_scheduled_pickup => scalar $input->param("patron-scheduled-$branchcode") || 0, >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/curbside_pickup.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/curbside_pickup.tt >index 9ce491234d5..c8d337aae04 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/curbside_pickup.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/curbside_pickup.tt >@@ -112,6 +112,16 @@ > [% END %] > <span class="hint">Enable patrons to schedule their own curbside pickups.</span> > </li> >+ >+ <li> >+ <label for="enable-waiting-holds-only-[% l.branchcode | html %]">Enable for waiting holds only: </label> >+ [% IF policies.$branchcode.enable_waiting_holds_only %] >+ <input name="enable-waiting-holds-only-[% l.branchcode | html %]" id="enable-waiting-holds-only-[% l.branchcode | html %]" value="1" type="checkbox" checked> >+ [% ELSE %] >+ <input name="enable-waiting-holds-only-[% l.branchcode | html %]" id="enable-waiting-holds-only-[% l.branchcode | html %]" value="1" type="checkbox"> >+ [% END %] >+ <span class="hint">Enable only if the patron has waiting holds.</span> >+ </li> > </ol> > </fieldset> > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt >index f5a95163bf5..71549834281 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt >@@ -433,23 +433,24 @@ > <button type="submit" class="btn btn-default">Submit</button> > </form> > [% ELSE %] >- <form id="create-pickup" method="post" class="form-horizontal"> >- <fieldset class="rows" style="float: none;"> >- <input type="hidden" name="borrowernumber" value="[% patron.id | html %]"/> >- <input type="hidden" name="op" value="create-pickup"/> >- <input type="hidden" name="tab" value="schedule-pickup"/> >- <ol> >- <li> >- <label>Patron: </label> >- <span>[% INCLUDE 'patron-title.inc' patron=patron %]</span> >- </li> >- >- <li> >- <label>Items ready for pickup: </label> >- <span> >- [% SET waiting_holds = patron.holds.search( found => 'W', branchcode => logged_in_user.branchcode ) %] >- [% IF waiting_holds.count %] >- [% FOREACH h IN waiting_holds %] >+ [% SET waiting_holds = patron.holds.search( found => 'W', branchcode => logged_in_user.branchcode ) %] >+ [% IF !policy.enable_waiting_holds_only || waiting_holds.count > 0 %] >+ <form id="create-pickup" method="post"> >+ <fieldset class="rows" style="float: none;"> >+ <input type="hidden" name="borrowernumber" value="[% patron.id | html %]"/> >+ <input type="hidden" name="op" value="create-pickup"/> >+ <input type="hidden" name="tab" value="schedule-pickup"/> >+ <ol> >+ <li> >+ <label>Patron: </label> >+ <span>[% INCLUDE 'patron-title.inc' patron=patron %]</span> >+ </li> >+ >+ <li> >+ <label>Items ready for pickup: </label> >+ <span> >+ [% IF waiting_holds.count %] >+ [% FOREACH h IN waiting_holds %] > <p> > <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% h.biblionumber | uri %]">[% h.biblio.title | html %]</a> ([% h.biblio.author | html %], <a href="/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=[% h.itemnumber | html %]&biblionumber=[% h.biblionumber | html %]#item[% h.itemnumber | html %]">[% h.item.barcode | html %]</a>) > </p> >@@ -477,15 +478,16 @@ > <fieldset class="action"> > <input id="schedule-pickup-button" type="submit" value="Submit" /> > </fieldset> >- > </form> >+ [% ELSE %] >+ <div class="dialog alert">The patron does not have waitings holds.</div> > [% END %] >- </div> >+ [% END %] > </div> > </div> > </main> > </div> >- </div> <!-- /.row --> >+ </div> <!-- /.row --> > > [% MACRO jsinclude BLOCK %] > [% Asset.js("lib/dayjs/dayjs.min.js") | $raw %] >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt >index 68a29987f6b..1462cfd7266 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt >@@ -200,6 +200,7 @@ > map[e.branchcode] = e; > return map; > }, {}); >+ let can_schedule_at = {}; > [% FOR p IN policies %] > var opening_slots = [% To.json(p.opening_slots.unblessed) | $raw %]; > var slots_per_day = {}; >@@ -209,6 +210,13 @@ > slots_per_day[day].push(slot); > }); > policies['[% p.branchcode | html %]'].slots_per_day = slots_per_day; >+ >+ [% IF p.enable_waiting_holds_only %] >+ [% SET waiting_holds = logged_in_user.holds.search( found => 'W', branchcode => p.branchcode ) %] >+ [% UNLESS waiting_holds.count %] >+ policies['[% p.branchcode | html %]'].enabled = 0; >+ [% END %] >+ [% END %] > [% END %] > > let existingPickupMoments = []; >@@ -220,6 +228,13 @@ > existingPickupMoments[pickup.branchcode].push(pickupMoment); > }); > >+ $("#pickup-branch option").each(function(){ >+ if ( $(this).val() != "" && !policies[$(this).val()].enabled ) { >+ $(this).prop("disabled", "disabled"); >+ $(this).attr("title", _("You don't have waiting holds at this location")); >+ } >+ }); >+ > $('#pickup-branch').on('change', function() { > let branchcode = $(this).val(); > >diff --git a/t/db_dependent/Koha/CurbsidePickups.t b/t/db_dependent/Koha/CurbsidePickups.t >index 599ccc617bf..0d027312d46 100755 >--- a/t/db_dependent/Koha/CurbsidePickups.t >+++ b/t/db_dependent/Koha/CurbsidePickups.t >@@ -54,6 +54,7 @@ my $policy = Koha::CurbsidePickupPolicy->new( > { > branchcode => $library->branchcode, > enabled => 1, >+ enable_waiting_holds_only => 0, > pickup_interval => 30, > patrons_per_interval => 2, > patron_scheduled_pickup => 1 >@@ -63,6 +64,7 @@ my $policy_disabled = Koha::CurbsidePickupPolicy->new( > { > branchcode => $library_disabled->branchcode, > enabled => 0, >+ enable_waiting_holds_only => 0, > pickup_interval => 30, > patrons_per_interval => 2, > patron_scheduled_pickup => 1 >@@ -75,32 +77,40 @@ $policy->add_opening_slot('1-12:00-18:00'); > my $today = dt_from_string; > > subtest 'Create a pickup' => sub { >- plan tests => 5; >+ plan tests => 7; > > # Day and datetime are ok > my $next_monday = > $today->clone->add( days => ( 1 - $today->day_of_week ) % 7 ); > my $schedule_dt = > $next_monday->set_hour(15)->set_minute(00)->set_second(00); >- my $cp = Koha::CurbsidePickup->new( >+ my $params = > { > branchcode => $library->branchcode, > borrowernumber => $patron->borrowernumber, > scheduled_pickup_datetime => $schedule_dt, > notes => 'just a note' >- } >- )->store; >+ }; >+ >+ throws_ok { >+ Koha::CurbsidePickup->new({%$params, branchcode => $library_disabled->branchcode})->store; >+ } >+ 'Koha::Exceptions::CubsidePickup::NotEnabled', >+ 'Cannot create pickup if the policy does not allow it'; >+ >+ $policy->enable_waiting_holds_only(1)->store; >+ throws_ok { >+ Koha::CurbsidePickup->new($params)->store; >+ } >+ 'Koha::Exceptions::CubsidePickup::NoWaitingHolds', >+ 'Cannot create pickup for a patron without waiting hold if flag is set'; >+ >+ $policy->enable_waiting_holds_only(0)->store; >+ my $cp = Koha::CurbsidePickup->new($params)->store; > is( $cp->status, 'to-be-staged' ); > > throws_ok { >- Koha::CurbsidePickup->new( >- { >- branchcode => $library->branchcode, >- borrowernumber => $patron->borrowernumber, >- scheduled_pickup_datetime => $schedule_dt, >- notes => 'just a note' >- } >- )->store >+ Koha::CurbsidePickup->new($params)->store > } > 'Koha::Exceptions::CubsidePickup::TooManyPickups', > 'Cannot create 2 pickups for the same patron'; >@@ -112,14 +122,7 @@ subtest 'Create a pickup' => sub { > $today->clone->add( days => ( 2 - $today->day_of_week ) % 7 ); > $schedule_dt = $next_tuesday->set_hour(15)->set_minute(00)->set_second(00); > throws_ok { >- Koha::CurbsidePickup->new( >- { >- branchcode => $library->branchcode, >- borrowernumber => $patron->borrowernumber, >- scheduled_pickup_datetime => $schedule_dt, >- notes => 'just a note' >- } >- )->store >+ Koha::CurbsidePickup->new({%$params, scheduled_pickup_datetime => $schedule_dt})->store; > } > 'Koha::Exceptions::CubsidePickup::NoMatchingSlots', > 'Cannot create a pickup on a day without opening slots defined'; >@@ -127,14 +130,7 @@ subtest 'Create a pickup' => sub { > # Day ok but datetime not ok > $schedule_dt = $next_monday->set_hour(19)->set_minute(00)->set_second(00); > throws_ok { >- Koha::CurbsidePickup->new( >- { >- branchcode => $library->branchcode, >- borrowernumber => $patron->borrowernumber, >- scheduled_pickup_datetime => $schedule_dt, >- notes => 'just a note' >- } >- )->store >+ Koha::CurbsidePickup->new({%$params, scheduled_pickup_datetime => $schedule_dt})->store; > } > 'Koha::Exceptions::CubsidePickup::NoMatchingSlots', > 'Cannot create a pickup on a time without opening slots defined'; >@@ -142,14 +138,7 @@ subtest 'Create a pickup' => sub { > # Day ok, datetime inside the opening slot, but wrong (15:15 for instance) > $schedule_dt = $next_monday->set_hour(15)->set_minute(15)->set_second(00); > throws_ok { >- Koha::CurbsidePickup->new( >- { >- branchcode => $library->branchcode, >- borrowernumber => $patron->borrowernumber, >- scheduled_pickup_datetime => $schedule_dt, >- notes => 'just a note' >- } >- )->store >+ Koha::CurbsidePickup->new({%$params, scheduled_pickup_datetime => $schedule_dt})->store; > } > 'Koha::Exceptions::CubsidePickup::NoMatchingSlots', > 'Cannot create a pickup on a time that is not matching the start of an interval'; >-- >2.25.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 30650
:
136584
|
136585
|
136586
|
136587
|
136588
|
136589
|
136590
|
136591
|
136592
|
136593
|
136594
|
136595
|
136596
|
136597
|
136598
|
136599
|
136600
|
136601
|
136602
|
136603
|
136604
|
136605
|
136606
|
136607
|
136608
|
136609
|
136610
|
137095
|
137100
|
137199
|
137211
|
137212
|
137277
|
137278
|
137279
|
137280
|
137281
|
137282
|
137283
|
137284
|
137285
|
137286
|
137287
|
137288
|
137289
|
137290
|
137291
|
137292
|
137293
|
137294
|
137295
|
137296
|
137297
|
137298
|
137299
|
137300
|
137301
|
137302
|
137303
|
137304
|
137305
|
137306
|
137307
|
138261
|
138262
|
138263
|
138264
|
138265
|
138266
|
138267
|
138268
|
138269
|
138270
|
138271
|
138272
|
138273
|
138274
|
138275
|
138276
|
138277
|
138278
|
138279
|
138280
|
138281
|
138282
|
138283
|
138284
|
138285
|
138286
|
138287
|
138288
|
138289
|
138290
|
138291
|
138292
|
138319
|
138320
|
138321
|
138322
|
138323
|
138324
|
138325
|
138330
|
138331
|
138332
|
138333
|
138334
|
138335
|
138336
|
138337
|
138338
|
138339
|
138340
|
138341
|
138342
|
138343
|
138344
|
138345
|
138346
|
138347
|
138348
|
138349
|
138350
|
138351
|
138352
|
138353
|
138354
|
138355
|
138356
|
138357
|
138358
|
138359
|
138360
|
138361
|
138362
|
138363
|
138364
|
138365
|
138366
|
138367
|
138368
|
138369
|
138375
|
138401
|
138610