From c954261cd7aee617eef4246b88e9344b2524b23d Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Sun, 5 Apr 2020 19:17:15 +0000 Subject: [PATCH] Bug 26814: Add onsite_checkout to Koha::CirculationRules To test: 1. prove t/db_dependent/Koha/CirculationRules.t Sponsored-by: The National Library of Finland --- Koha/CirculationRules.pm | 67 +++++++++++++++----------- t/db_dependent/Koha/CirculationRules.t | 36 +++++++++++--- 2 files changed, 68 insertions(+), 35 deletions(-) diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm index 05850bee0f..e31f691473 100644 --- a/Koha/CirculationRules.pm +++ b/Koha/CirculationRules.pm @@ -51,7 +51,7 @@ our $RULE_KINDS = { }, patron_maxissueqty => { - scope => [ 'branchcode', 'categorycode' ], + scope => [ 'branchcode', 'categorycode', 'onsite_checkout' ], }, patron_maxonsiteissueqty => { scope => [ 'branchcode', 'categorycode' ], @@ -77,31 +77,31 @@ our $RULE_KINDS = { scope => [ 'branchcode', 'categorycode', 'itemtype' ], }, auto_renew => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, cap_fine_to_replacement_price => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, chargeperiod => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, chargeperiod_charge_at => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, fine => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, finedays => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, firstremind => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, hardduedate => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, hardduedatecompare => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, holds_per_day => { scope => [ 'branchcode', 'categorycode', 'itemtype' ], @@ -110,31 +110,31 @@ our $RULE_KINDS = { scope => [ 'branchcode', 'categorycode', 'itemtype' ], }, issuelength => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, daysmode => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, lengthunit => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, maxissueqty => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, maxonsiteissueqty => { scope => [ 'branchcode', 'categorycode', 'itemtype' ], }, maxsuspensiondays => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, no_auto_renewal_after => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, no_auto_renewal_after_hard_limit => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, norenewalbefore => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, onshelfholds => { scope => [ 'branchcode', 'categorycode', 'itemtype' ], @@ -143,25 +143,25 @@ our $RULE_KINDS = { scope => [ 'branchcode', 'categorycode', 'itemtype' ], }, overduefinescap => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, renewalperiod => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, renewalsallowed => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, rentaldiscount => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, reservesallowed => { scope => [ 'branchcode', 'categorycode', 'itemtype' ], }, suspension_chargeperiod => { - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, note => { # This is not really a rule. Maybe we will want to separate this later. - scope => [ 'branchcode', 'categorycode', 'itemtype' ], + scope => [ 'branchcode', 'categorycode', 'itemtype', 'onsite_checkout' ], }, # Not included (deprecated?): # * accountsent @@ -188,17 +188,18 @@ sub get_effective_rule { my $categorycode = $params->{categorycode}; my $itemtype = $params->{itemtype}; my $branchcode = $params->{branchcode}; + my $onsite_checkout = $params->{onsite_checkout}; Koha::Exceptions::MissingParameter->throw( "Required parameter 'rule_name' missing") unless $rule_name; - for my $v ( $branchcode, $categorycode, $itemtype ) { + for my $v ( $branchcode, $onsite_checkout, $categorycode, $itemtype ) { $v = undef if $v and $v eq '*'; } my $order_by = $params->{order_by} - // { -desc => [ 'branchcode', 'categorycode', 'itemtype' ] }; + // { -desc => [ 'branchcode', 'onsite_checkout', 'categorycode', 'itemtype', ] }; my $search_params; $search_params->{rule_name} = $rule_name; @@ -206,6 +207,7 @@ sub get_effective_rule { $search_params->{categorycode} = defined $categorycode ? [ $categorycode, undef ] : undef; $search_params->{itemtype} = defined $itemtype ? [ $itemtype, undef ] : undef; $search_params->{branchcode} = defined $branchcode ? [ $branchcode, undef ] : undef; + $search_params->{onsite_checkout} = defined $onsite_checkout ? [ $onsite_checkout, undef ] : undef; my $rule = $self->search( $search_params, @@ -228,6 +230,7 @@ sub get_effective_rules { my $rules = $params->{rules}; my $categorycode = $params->{categorycode}; my $itemtype = $params->{itemtype}; + my $onsite_checkout = $params->{onsite_checkout}; my $branchcode = $params->{branchcode}; my $r; @@ -238,6 +241,7 @@ sub get_effective_rules { categorycode => $categorycode, itemtype => $itemtype, branchcode => $branchcode, + onsite_checkout => $onsite_checkout, } ); @@ -266,7 +270,7 @@ sub set_rule { unless defined $kind_info; # Enforce scope; a rule should be set for its defined scope, no more, no less. - foreach my $scope_level ( qw( branchcode categorycode itemtype ) ) { + foreach my $scope_level ( qw( branchcode onsite_checkout categorycode itemtype ) ) { if ( grep /$scope_level/, @{ $kind_info->{scope} } ) { croak "set_rule needs '$scope_level' to set '$params->{rule_name}'!" unless exists $params->{$scope_level}; @@ -279,12 +283,13 @@ sub set_rule { my $branchcode = $params->{branchcode}; my $categorycode = $params->{categorycode}; my $itemtype = $params->{itemtype}; + my $onsite_checkout = $params->{onsite_checkout}; my $rule_name = $params->{rule_name}; my $rule_value = $params->{rule_value}; my $can_be_blank = defined $kind_info->{can_be_blank} ? $kind_info->{can_be_blank} : 1; $rule_value = undef if defined $rule_value && $rule_value eq "" && !$can_be_blank; - for my $v ( $branchcode, $categorycode, $itemtype ) { + for my $v ( $branchcode, $onsite_checkout, $categorycode, $itemtype ) { $v = undef if $v and $v eq '*'; } my $rule = $self->search( @@ -293,6 +298,7 @@ sub set_rule { branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype, + onsite_checkout => $onsite_checkout, } )->next(); @@ -312,6 +318,7 @@ sub set_rule { branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype, + onsite_checkout => $onsite_checkout, rule_name => $rule_name, rule_value => $rule_value, } @@ -334,6 +341,8 @@ sub set_rules { $set_params{branchcode} = $params->{branchcode} if exists $params->{branchcode}; $set_params{categorycode} = $params->{categorycode} if exists $params->{categorycode}; $set_params{itemtype} = $params->{itemtype} if exists $params->{itemtype}; + $set_params{onsite_checkout} = $params->{onsite_checkout} if exists $params->{onsite_checkout}; + my $rules = $params->{rules}; my $rule_objects = []; @@ -538,12 +547,14 @@ sub get_effective_daysmode { my $categorycode = $params->{categorycode}; my $itemtype = $params->{itemtype}; my $branchcode = $params->{branchcode}; + my $onsite_checkout = $params->{onsite_checkout}; my $daysmode_rule = $class->get_effective_rule( { categorycode => $categorycode, itemtype => $itemtype, branchcode => $branchcode, + onsite_checkout => $onsite_checkout, rule_name => 'daysmode', } ); diff --git a/t/db_dependent/Koha/CirculationRules.t b/t/db_dependent/Koha/CirculationRules.t index cc5468e7eb..97829248a4 100755 --- a/t/db_dependent/Koha/CirculationRules.t +++ b/t/db_dependent/Koha/CirculationRules.t @@ -22,6 +22,7 @@ use Modern::Perl; use Test::More tests => 4; use Test::Exception; +use Koha::Checkouts; use Koha::CirculationRules; use Koha::Database; @@ -41,6 +42,7 @@ subtest 'set_rule + get_effective_rule' => sub { my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes' } )->itemtype; my $branchcode = $builder->build_object( { class => 'Koha::Libraries' } )->branchcode; my $branchcode_2 = $builder->build_object( { class => 'Koha::Libraries' } )->branchcode; + my $onsite_checkout = 1; my $rule_name = 'maxissueqty'; my $default_rule_value = 1; @@ -56,6 +58,7 @@ subtest 'set_rule + get_effective_rule' => sub { branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype, + onsite_checkout => undef, rule_name => $rule_name, } ); @@ -66,6 +69,7 @@ subtest 'set_rule + get_effective_rule' => sub { branchcode => '*', categorycode => '*', itemtype => '*', + onsite_checkout => '*', rule_name => $rule_name, rule_value => $default_rule_value, } @@ -76,6 +80,7 @@ subtest 'set_rule + get_effective_rule' => sub { branchcode => undef, categorycode => undef, itemtype => undef, + onsite_checkout => undef, rule_name => $rule_name, } ); @@ -85,6 +90,7 @@ subtest 'set_rule + get_effective_rule' => sub { branchcode => '*', categorycode => '*', itemtype => '*', + onsite_checkout => '*', rule_name => $rule_name, } ); @@ -96,6 +102,7 @@ subtest 'set_rule + get_effective_rule' => sub { branchcode => $branchcode_2, categorycode => '*', itemtype => '*', + onsite_checkout => '*', rule_name => $rule_name, } ); @@ -133,6 +140,7 @@ subtest 'set_rule + get_effective_rule' => sub { branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype, + onsite_checkout => $onsite_checkout, }, 'maxissueqty' ); @@ -151,6 +159,7 @@ subtest 'set_rule + get_effective_rule' => sub { branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype, + onsite_checkout => $onsite_checkout, rule_name => $rule_name, } ); @@ -167,9 +176,9 @@ subtest 'set_rule + get_effective_rule' => sub { }; my $our_branch_rules = Koha::CirculationRules->search({branchcode => $branchcode}); - is( $our_branch_rules->count, 4, "We added 8 rules"); + is( $our_branch_rules->count, 8, "We added 16 rules"); $our_branch_rules->delete; - is( $our_branch_rules->count, 0, "We deleted 8 rules"); + is( $our_branch_rules->count, 0, "We deleted 16 rules"); $schema->storage->txn_rollback; }; @@ -223,7 +232,8 @@ subtest 'get_effective_daysmode' => sub { { categorycode => undef, itemtype => $item_1->effective_itemtype, - branchcode => undef + branchcode => undef, + onsite_checkout => undef, } ), 'Datedue', @@ -235,6 +245,7 @@ subtest 'get_effective_daysmode' => sub { branchcode => '*', categorycode => '*', itemtype => '*', + onsite_checkout => '*', rule_name => 'daysmode', rule_value => 'Calendar', } @@ -244,6 +255,7 @@ subtest 'get_effective_daysmode' => sub { branchcode => '*', categorycode => '*', itemtype => $item_1->effective_itemtype, + onsite_checkout => '*', rule_name => 'daysmode', rule_value => 'Days', } @@ -254,7 +266,8 @@ subtest 'get_effective_daysmode' => sub { { categorycode => undef, itemtype => $item_1->effective_itemtype, - branchcode => undef + branchcode => undef, + onsite_checkout => undef, } ), 'Days', @@ -265,7 +278,8 @@ subtest 'get_effective_daysmode' => sub { { categorycode => undef, itemtype => $item_2->effective_itemtype, - branchcode => undef + branchcode => undef, + onsite_checkout => undef, } ), 'Calendar', @@ -277,6 +291,7 @@ subtest 'get_effective_daysmode' => sub { branchcode => '*', categorycode => '*', itemtype => $item_2->effective_itemtype, + onsite_checkout => '*', rule_name => 'daysmode', rule_value => '', } @@ -287,7 +302,8 @@ subtest 'get_effective_daysmode' => sub { { categorycode => undef, itemtype => $item_2->effective_itemtype, - branchcode => undef + branchcode => undef, + onsite_checkout => undef, } ), 'Datedue', @@ -311,6 +327,7 @@ subtest 'get_lostreturn_policy() tests' => sub { branchcode => undef, categorycode => undef, itemtype => undef, + onsite_checkout => undef, rule_name => 'refund', rule_value => 1 } @@ -324,6 +341,7 @@ subtest 'get_lostreturn_policy() tests' => sub { branchcode => $branchcode, categorycode => undef, itemtype => undef, + onsite_checkout => undef, rule_name => 'refund', rule_value => 0 } @@ -337,6 +355,7 @@ subtest 'get_lostreturn_policy() tests' => sub { branchcode => $branchcode2, categorycode => undef, itemtype => undef, + onsite_checkout => undef, rule_name => 'refund', rule_value => 1 } @@ -351,6 +370,7 @@ subtest 'get_lostreturn_policy() tests' => sub { branchcode => $branchcode3, categorycode => undef, itemtype => undef, + onsite_checkout => undef, rule_name => 'refund', } } @@ -362,6 +382,7 @@ subtest 'get_lostreturn_policy() tests' => sub { branchcode => $branch_without_rule, categorycode => undef, itemtype => undef, + onsite_checkout => undef, rule_name => 'refund' } ) @@ -410,6 +431,7 @@ subtest 'get_lostreturn_policy() tests' => sub { branchcode => undef, categorycode => undef, itemtype => undef, + onsite_checkout => undef, rule_name => 'refund' } ) @@ -454,7 +476,7 @@ sub prepare_tests_for_rule_scope_combinations { # We must maintain the order in order to keep the test valid. This should be # equal to Koha/CirculationRules.pm "order_by" of C sub. # Let's explicitly define the order and fail test if we are missing a scope: - my $order = [ 'branchcode', 'categorycode', 'itemtype' ]; + my $order = [ 'branchcode', 'onsite_checkout', 'categorycode', 'itemtype' ]; is( join(", ", sort keys %$scope), join(", ", sort @$order), 'Missing a scope!' ) if keys %$scope ne scalar @$order; -- 2.17.1