From d7c4bb053d82cde627739eb2f6c95059bffc808f Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Tue, 17 Nov 2020 22:36:51 +0100 Subject: [PATCH] Bug 8137: (follow-up) Fix error on the rules cloning functionality Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Kyle M Hall --- Koha/CirculationRule.pm | 1 + Koha/CirculationRules.pm | 4 ++-- Koha/Schema/Result/CirculationRule.pm | 7 +++++-- .../intranet-tmpl/prog/en/modules/admin/smart-rules.tt | 9 +++++---- t/db_dependent/Circulation.t | 4 ++++ 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Koha/CirculationRule.pm b/Koha/CirculationRule.pm index 818ca513e8..7c04324223 100644 --- a/Koha/CirculationRule.pm +++ b/Koha/CirculationRule.pm @@ -92,6 +92,7 @@ sub clone { my $cloned_rule = $self->unblessed; $cloned_rule->{branchcode} = $to_branch; + $cloned_rule->{has_priority} = undef; delete $cloned_rule->{id}; return Koha::CirculationRule->new( $cloned_rule )->store; } diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm index a3478443db..badaa5416e 100644 --- a/Koha/CirculationRules.pm +++ b/Koha/CirculationRules.pm @@ -384,7 +384,7 @@ sub set_rule { my $branchcode = $params->{branchcode}; my $categorycode = $params->{categorycode}; my $itemtype = $params->{itemtype}; - my $has_priority = $params->{has_priority}; + my $has_priority = $params->{has_priority} ? 1 : undef; 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; @@ -399,13 +399,13 @@ sub set_rule { branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype, - has_priority => $has_priority, } )->next(); if ($rule) { if ( defined $rule_value ) { $rule->rule_value($rule_value); + $rule->has_priority($has_priority); $rule->update(); } else { diff --git a/Koha/Schema/Result/CirculationRule.pm b/Koha/Schema/Result/CirculationRule.pm index 4284c3894a..e78869b1b0 100644 --- a/Koha/Schema/Result/CirculationRule.pm +++ b/Koha/Schema/Result/CirculationRule.pm @@ -52,7 +52,8 @@ __PACKAGE__->table("circulation_rules"); =head2 has_priority - data_type: 'integer' + data_type: 'tinyint' + default_value: 0 is_nullable: 1 =head2 rule_name @@ -79,7 +80,7 @@ __PACKAGE__->add_columns( "itemtype", { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 }, "has_priority", - { data_type => "integer", is_nullable => 1, is_boolean => 1 }, + { data_type => "tinyint", default_value => 0, is_nullable => 1 }, "rule_name", { data_type => "varchar", is_nullable => 0, size => 32 }, "rule_value", @@ -187,6 +188,8 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-07-22 13:19:28 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1mg3weVQdfPTJ+jX6X5K+Q +__PACKAGE__->add_columns( '+has_priority' => { is_boolean => 1 }); + sub koha_objects_class { 'Koha::CirculationRules'; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index b027569c00..e22c224c3d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -1613,10 +1613,15 @@ itm = $(this).text(); itm = itm.replace(/^\s*|\s*$/g,''); var current_column = $("#edit_row td:eq("+i+")"); + var may_have_priority = (0 == $('select#branch option[selected]').length); + if ( i > 4) i+=may_have_priority; if ( i == 3 ) { // specific processing for the Note column var note = $(this).find("a[name='viewnote']").data("content"); $(current_column).find("input[type='text']").val(note); + } else if ( i == 4 && may_have_priority ) { + var has_priority = $(this).find("input[type='checkbox']"); + $('#has_priority').prop('checked', has_priority.is(':checked') ); } else if ( i == 9 ) { // specific processing for the Hard due date column var select_value = $(this).find("input[type='hidden'][name='hardduedatecomparebackup']").val(); @@ -1633,10 +1638,6 @@ var cap_fine_to_replacement_price = $(this).find("input[type='checkbox']"); $('#cap_fine_to_replacement_price').prop('checked', cap_fine_to_replacement_price.is(':checked') ); $('#overduefinescap').prop('disabled', cap_fine_to_replacement_price.is(':checked') ); - } else if ( i == 3 ) { - var has_priority = $(this).find("input[type='checkbox']"); - $('#has_priority').prop('checked', has_priority.is(':checked') ); - //$('#overduefinescap').prop('disabled', cap_fine_to_replacement_price.is(':checked') ); } else { $(current_column).find("input[type='text']").val(itm); // select the corresponding option diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 0ba8d69742..c99188b4fd 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -3223,6 +3223,7 @@ subtest 'AddReturn | is_overdue' => sub { branchcode => $branchcode_false, categorycode => undef, itemtype => undef, + has_priority => undef, rule_name => 'lostreturn', rule_value => 0 } @@ -3237,6 +3238,7 @@ subtest 'AddReturn | is_overdue' => sub { branchcode => $branchcode_refund, categorycode => undef, itemtype => undef, + has_priority => undef, rule_name => 'lostreturn', rule_value => 'refund' } @@ -3251,6 +3253,7 @@ subtest 'AddReturn | is_overdue' => sub { branchcode => $branchcode_restore, categorycode => undef, itemtype => undef, + has_priority => undef, rule_name => 'lostreturn', rule_value => 'restore' } @@ -3265,6 +3268,7 @@ subtest 'AddReturn | is_overdue' => sub { branchcode => $branchcode_charge, categorycode => undef, itemtype => undef, + has_priority => undef, rule_name => 'lostreturn', rule_value => 'charge' } -- 2.25.1