@@ -, +, @@
- Create an issuing rule a patron category and itemtype. make it
has priority,
- create more permissive issuing rules for all other branches,
- check that the priority rule is taken into account for this
category
and itemtype.
---
Koha/IssuingRules.pm | 16 +++++++++++
admin/smart-rules.pl | 2 ++
...137-add-column-has_priority-in-issuingrules.sql | 3 ++
.../prog/en/modules/admin/smart-rules.tt | 32 +++++++++++++++++++---
t/db_dependent/Koha/IssuingRules.t | 29 +++++++++++++++++++-
5 files changed, 77 insertions(+), 5 deletions(-)
create mode 100644 installer/data/mysql/atomicupdate/Bug_8137-add-column-has_priority-in-issuingrules.sql
--- a/Koha/IssuingRules.pm
+++ a/Koha/IssuingRules.pm
@@ -58,6 +58,22 @@ sub get_effective_issuing_rule {
$search_branchcode = { 'in' => [ $branchcode, $default ] };
}
+ # First check for priority rules
+ if (my $rule = $self->search({
+ categorycode => $search_categorycode,
+ itemtype => $search_itemtype,
+ branchcode => '*',
+ has_priority => 1,
+ }, {
+ order_by => {
+ -desc => ['branchcode', 'categorycode', 'itemtype']
+ },
+ rows => 1,
+ })->single) {
+ return $rule;
+ }
+
+
my $rule = $self->search({
categorycode => $search_categorycode,
itemtype => $search_itemtype,
--- a/admin/smart-rules.pl
+++ a/admin/smart-rules.pl
@@ -121,6 +121,7 @@ elsif ($op eq 'add') {
my $br = $branch; # branch
my $bor = $input->param('categorycode'); # borrower category
my $itemtype = $input->param('itemtype'); # item type
+ my $has_priority = $input->param('has_priority') ? 1 : 0;
my $fine = $input->param('fine');
my $finedays = $input->param('finedays');
my $maxsuspensiondays = $input->param('maxsuspensiondays');
@@ -165,6 +166,7 @@ elsif ($op eq 'add') {
branchcode => $br,
categorycode => $bor,
itemtype => $itemtype,
+ has_priority => $has_priority,
fine => $fine,
finedays => $finedays,
maxsuspensiondays => $maxsuspensiondays,
--- a/installer/data/mysql/atomicupdate/Bug_8137-add-column-has_priority-in-issuingrules.sql
+++ a/installer/data/mysql/atomicupdate/Bug_8137-add-column-has_priority-in-issuingrules.sql
@@ -0,0 +1,3 @@
+ALTER TABLE issuingrules ADD has_priority INT(1) DEFAULT 0 AFTER itemtype;
+ALTER TABLE issuingrules DROP primary key;
+ALTER TABLE issuingrules ADD primary key(branchcode , categorycode, itemtype, has_priority);
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
@@ -65,6 +65,7 @@
Patron category |
Item type |
Actions |
+ [% UNLESS humanbranch %]Has priority | [% END %]
Current checkouts allowed |
Current on-site checkouts allowed |
Loan period |
@@ -113,6 +114,15 @@
Delete
+ [% UNLESS humanbranch %]
+
+ [% IF rule.has_priority %]
+
+ [% ELSE %]
+
+ [% END %]
+ |
+ [% END %]
[% IF ( rule.unlimited_maxissueqty ) %]
Unlimited
[% ELSE %]
@@ -223,6 +233,11 @@
|
+ [% UNLESS humanbranch %]
+
+
+ |
+ [% END %]
|
|
|
@@ -304,6 +319,7 @@
Patron category |
Item type |
|
+ [% UNLESS humanbranch %]Has priority | [% END %]
Current checkouts allowed |
Current on-site checkouts allowed |
Loan period |
@@ -497,7 +513,11 @@
[% UNLESS humanbranch %]
-
+ [% IF branch_cat_rule_loo.has_priority %]
+
+ [% ELSE %]
+
+ [% END %]
|
[% END %]
@@ -795,7 +815,7 @@
itm = $(this).text();
itm = itm.replace(/^\s*|\s*$/g,'');
var current_column = $("#edit_row td:eq("+i+")");
- if ( i == 7 ) {
+ if ( i == 8 ) {
// specific processing for the Hard due date column
var select_value = $(this).find("input[type='hidden'][name='hardduedatecomparebackup']").val();
var input_value = '';
@@ -806,11 +826,15 @@
}
$(current_column).find("input[type='text']").val(input_value);
$(current_column).find("select").val(select_value);
- } else if ( i == 13 ) {
+ } else if ( i == 14 ) {
// specific processing for cap_fine_to_replacement_price
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
@@ -831,7 +855,7 @@
// Remove potential previous input added
$(current_column).find("input").remove();
$(current_column).append("");
- } else if ( i == 3 || i == 4 ) {
+ } else if ( i == 4 || i == 5 ) {
// If the value is not an integer for "Current checkouts allowed" or "Current on-site checkouts allowed"
// The value is "Unlimited" (or an equivalent translated string)
// an it should be set to an empty string
--- a/t/db_dependent/Koha/IssuingRules.t
+++ a/t/db_dependent/Koha/IssuingRules.t
@@ -34,7 +34,7 @@ $schema->storage->txn_begin;
my $builder = t::lib::TestBuilder->new;
subtest 'get_effective_issuing_rule' => sub {
- plan tests => 3;
+ plan tests => 4;
my $patron = $builder->build({ source => 'Borrower' });
my $item = $builder->build({ source => 'Item' });
@@ -43,6 +43,33 @@ subtest 'get_effective_issuing_rule' => sub {
my $itemtype = $item->{'itype'};
my $branchcode = $item->{'homebranch'};
+ subtest 'Priority rule' => sub {
+ plan tests => 3;
+
+ Koha::IssuingRules->delete;
+
+ ok(Koha::IssuingRule->new({
+ branchcode => $branchcode,
+ categorycode => $categorycode,
+ itemtype => $itemtype,
+ })->store, "Given I added an issuing rule branchcode => $branchcode,'
+ .' categorycode => $categorycode, itemtype => $itemtype,");
+
+ ok(Koha::IssuingRule->new({
+ branchcode => '*',
+ categorycode => $categorycode,
+ itemtype => $itemtype,
+ has_priority => 1,
+ })->store, "Add a priority rule.");
+
+ my $rule = Koha::IssuingRules->get_effective_issuing_rule({
+ branchcode => $branchcode,
+ categorycode => $categorycode,
+ itemtype => $itemtype,
+ });
+ is($rule->has_priority, 1, 'Priority rule should be returned');
+ };
+
subtest 'Call with undefined values' => sub {
plan tests => 4;
--