@@ -, +, @@ holds only --- 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(-) --- a/Koha/CurbsidePickup.pm +++ a/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) { --- a/Koha/CurbsidePickupPolicy.pm +++ a/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 ) = @_; --- a/Koha/Exceptions/CurbsidePickup.pm +++ a/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; --- a/admin/curbside_pickup.pl +++ a/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, --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/curbside_pickup.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/curbside_pickup.tt @@ -112,6 +112,16 @@ [% END %] Enable patrons to schedule their own curbside pickups. + +