Browse Source

Bug 18936: More fixes

Signed-off-by: Minna Kivinen <minna.kivinen@hamk.fi>
Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
20.05.x
Jonathan Druart 5 years ago
committed by Martin Renvoize
parent
commit
72442dc8d2
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 2
      C4/Reserves.pm
  2. 12
      Koha/Charges/Fees.pm
  3. 8
      Koha/CirculationRules.pm
  4. 3
      Koha/REST/V1/Checkouts.pm
  5. 22
      admin/smart-rules.pl
  6. 67
      koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
  7. 13
      t/db_dependent/Circulation/CalcFine.t
  8. 17
      t/db_dependent/Circulation/TooMany.t
  9. 17
      t/db_dependent/Circulation/issue.t
  10. 55
      t/db_dependent/Holds.t
  11. 51
      t/db_dependent/ILSDI_Services.t
  12. 69
      t/db_dependent/Koha/IssuingRules.t
  13. 1
      t/db_dependent/SIP/Transaction.t
  14. 2
      t/db_dependent/selenium/administration_tasks.t

2
C4/Reserves.pm

@ -1218,7 +1218,7 @@ sub IsAvailableForItemLevelRequest {
$item->withdrawn || $item->withdrawn ||
($item->damaged && !C4::Context->preference('AllowHoldsOnDamagedItems')); ($item->damaged && !C4::Context->preference('AllowHoldsOnDamagedItems'));
my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } ); my $on_shelf_holds = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } );
if ($pickup_branchcode) { if ($pickup_branchcode) {
my $destination = Koha::Libraries->find($pickup_branchcode); my $destination = Koha::Libraries->find($pickup_branchcode);

12
Koha/Charges/Fees.pm

@ -22,7 +22,6 @@ use Modern::Perl;
use Carp qw( carp confess ); use Carp qw( carp confess );
use Koha::Calendar; use Koha::Calendar;
use Koha::IssuingRules;
use Koha::DateUtils qw( dt_from_string ); use Koha::DateUtils qw( dt_from_string );
use Koha::Exceptions; use Koha::Exceptions;
@ -90,17 +89,18 @@ sub new {
sub accumulate_rentalcharge { sub accumulate_rentalcharge {
my ($self) = @_; my ($self) = @_;
my $itemtype = Koha::ItemTypes->find( $self->item->effective_itemtype ); my $itemtype = Koha::ItemTypes->find( $self->item->effective_itemtype );
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( my $lengthunit_rule = Koha::CirculationRules->get_effective_rule(
{ {
categorycode => $self->patron->categorycode, categorycode => $self->patron->categorycode,
itemtype => $itemtype->id, itemtype => $itemtype->id,
branchcode => $self->library->id branchcode => $self->library->id,
rule_name => 'lengthunit',
} }
); );
return 0 unless $issuing_rule; return 0 unless $lengthunit_rule;
my $units = $issuing_rule->lengthunit; my $units = $lengthunit_rule->rule_value;
my $rentalcharge_increment = my $rentalcharge_increment =
( $units eq 'days' ) ( $units eq 'days' )
? $itemtype->rentalcharge_daily ? $itemtype->rentalcharge_daily

8
Koha/CirculationRules.pm

@ -154,6 +154,9 @@ our $RULE_KINDS = {
suspension_chargeperiod => { suspension_chargeperiod => {
scope => [ 'branchcode', 'categorycode', 'itemtype' ], scope => [ 'branchcode', 'categorycode', 'itemtype' ],
}, },
note => { # This is not really a rule. Maybe we will want to separate this later.
scope => [ 'branchcode', 'categorycode', 'itemtype' ],
},
# Not included (deprecated?): # Not included (deprecated?):
# * accountsent # * accountsent
# * reservecharge # * reservecharge
@ -180,8 +183,9 @@ sub get_effective_rule {
my $itemtype = $params->{itemtype}; my $itemtype = $params->{itemtype};
my $branchcode = $params->{branchcode}; my $branchcode = $params->{branchcode};
my @c = caller;
Koha::Exceptions::MissingParameter->throw( Koha::Exceptions::MissingParameter->throw(
"Required parameter 'rule_name' missing") "Required parameter 'rule_name' missing" . "@c")
unless $rule_name; unless $rule_name;
for my $v ( $branchcode, $categorycode, $itemtype ) { for my $v ( $branchcode, $categorycode, $itemtype ) {
@ -372,7 +376,7 @@ sub get_opacitemholds_policy {
return unless $item or $patron; return unless $item or $patron;
my $rule = Koha::CirculationRules->get_effective_issuing_rule( my $rule = Koha::CirculationRules->get_effective_rule(
{ {
categorycode => $patron->categorycode, categorycode => $patron->categorycode,
itemtype => $item->effective_itemtype, itemtype => $item->effective_itemtype,

3
Koha/REST/V1/Checkouts.pm

@ -24,7 +24,6 @@ use C4::Auth qw( haspermission );
use C4::Context; use C4::Context;
use C4::Circulation; use C4::Circulation;
use Koha::Checkouts; use Koha::Checkouts;
use Koha::IssuingRules;
use Koha::Old::Checkouts; use Koha::Old::Checkouts;
use Try::Tiny; use Try::Tiny;
@ -209,7 +208,7 @@ sub allows_renewal {
my $renewable = Mojo::JSON->false; my $renewable = Mojo::JSON->false;
$renewable = Mojo::JSON->true if $can_renew; $renewable = Mojo::JSON->true if $can_renew;
my $rule = Koha::IssuingRules->get_effective_issuing_rule( my $rule = Koha::CirculationRules->get_effective_rule(
{ {
categorycode => $checkout->patron->categorycode, categorycode => $checkout->patron->categorycode,
itemtype => $checkout->item->effective_itemtype, itemtype => $checkout->item->effective_itemtype,

22
admin/smart-rules.pl

@ -85,15 +85,16 @@ if ($op eq 'delete') {
branchcode => $branch eq '*' ? undef : $branch, branchcode => $branch eq '*' ? undef : $branch,
itemtype => $itemtype eq '*' ? undef : $itemtype, itemtype => $itemtype eq '*' ? undef : $itemtype,
rules => { rules => {
restrictedtype => undef, maxissueqty => undef,
maxonsiteissueqty => undef,
rentaldiscount => undef, rentaldiscount => undef,
fine => undef, fine => undef,
finedays => undef, finedays => undef,
maxsuspensiondays => undef, maxsuspensiondays => undef,
suspension_chargeperiod => undef,
firstremind => undef, firstremind => undef,
chargeperiod => undef, chargeperiod => undef,
chargeperiod_charge_at => undef, chargeperiod_charge_at => undef,
accountsent => undef,
issuelength => undef, issuelength => undef,
lengthunit => undef, lengthunit => undef,
hardduedate => undef, hardduedate => undef,
@ -106,11 +107,13 @@ if ($op eq 'delete') {
no_auto_renewal_after_hard_limit => undef, no_auto_renewal_after_hard_limit => undef,
reservesallowed => undef, reservesallowed => undef,
holds_per_record => undef, holds_per_record => undef,
overduefinescap => undef, holds_per_day => undef,
cap_fine_to_replacement_price => undef,
onshelfholds => undef, onshelfholds => undef,
opacitemholds => undef, opacitemholds => undef,
overduefinescap => undef,
cap_fine_to_replacement_price => undef,
article_requests => undef, article_requests => undef,
note => undef,
} }
} }
); );
@ -298,6 +301,7 @@ elsif ($op eq 'add') {
my $rules = { my $rules = {
maxissueqty => $maxissueqty, maxissueqty => $maxissueqty,
maxonsiteissueqty => $maxonsiteissueqty, maxonsiteissueqty => $maxonsiteissueqty,
rentaldiscount => $rentaldiscount,
fine => $fine, fine => $fine,
finedays => $finedays, finedays => $finedays,
maxsuspensiondays => $maxsuspensiondays, maxsuspensiondays => $maxsuspensiondays,
@ -305,6 +309,10 @@ elsif ($op eq 'add') {
firstremind => $firstremind, firstremind => $firstremind,
chargeperiod => $chargeperiod, chargeperiod => $chargeperiod,
chargeperiod_charge_at => $chargeperiod_charge_at, chargeperiod_charge_at => $chargeperiod_charge_at,
issuelength => $issuelength,
lengthunit => $lengthunit,
hardduedate => $hardduedate,
hardduedatecompare => $hardduedatecompare,
renewalsallowed => $renewalsallowed, renewalsallowed => $renewalsallowed,
renewalperiod => $renewalperiod, renewalperiod => $renewalperiod,
norenewalbefore => $norenewalbefore, norenewalbefore => $norenewalbefore,
@ -314,11 +322,6 @@ elsif ($op eq 'add') {
reservesallowed => $reservesallowed, reservesallowed => $reservesallowed,
holds_per_record => $holds_per_record, holds_per_record => $holds_per_record,
holds_per_day => $holds_per_day, holds_per_day => $holds_per_day,
issuelength => $issuelength,
lengthunit => $lengthunit,
hardduedate => $hardduedate,
hardduedatecompare => $hardduedatecompare,
rentaldiscount => $rentaldiscount,
onshelfholds => $onshelfholds, onshelfholds => $onshelfholds,
opacitemholds => $opacitemholds, opacitemholds => $opacitemholds,
overduefinescap => $overduefinescap, overduefinescap => $overduefinescap,
@ -403,7 +406,6 @@ elsif ($op eq "set-branch-defaults") {
{ {
branchcode => $branch, branchcode => $branch,
categorycode => undef, categorycode => undef,
itemtype => undef,
rule_name => 'max_holds', rule_name => 'max_holds',
rule_value => $max_holds, rule_value => $max_holds,
} }

67
koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt

@ -124,40 +124,37 @@
[% SET row_count = 0 %] [% SET row_count = 0 %]
[% FOREACH c IN categorycodes %] [% FOREACH c IN categorycodes %]
[% FOREACH i IN itemtypes %] [% FOREACH i IN itemtypes %]
[% SET note = CirculationRules.Get( branchcode, c, i, 'note' ) %] [% SET note = CirculationRules.Search( branchcode, c, i, 'note' ) %]
[% SET maxissueqty = CirculationRules.Get( branchcode, c, i, 'maxissueqty' ) %] [% SET maxissueqty = CirculationRules.Search( branchcode, c, i, 'maxissueqty' ) %]
[% SET maxonsiteissueqty = CirculationRules.Get( branchcode, c, i, 'maxonsiteissueqty' ) %] [% SET maxonsiteissueqty = CirculationRules.Search( branchcode, c, i, 'maxonsiteissueqty' ) %]
[% SET issuelength = CirculationRules.Get( branchcode, c, i, 'issuelength' ) %] [% SET issuelength = CirculationRules.Search( branchcode, c, i, 'issuelength' ) %]
[% SET lengthunit = CirculationRules.Get( branchcode, c, i, 'lengthunit' ) %] [% SET lengthunit = CirculationRules.Search( branchcode, c, i, 'lengthunit' ) %]
[% SET hardduedate = CirculationRules.Get( branchcode, c, i, 'hardduedate' ) %] [% SET hardduedate = CirculationRules.Search( branchcode, c, i, 'hardduedate' ) %]
[% SET hardduedatecompare = CirculationRules.Get( branchcode, c, i, 'hardduedatecompare' ) %] [% SET hardduedatecompare = CirculationRules.Search( branchcode, c, i, 'hardduedatecompare' ) %]
[% SET fine = CirculationRules.Get( branchcode, c, i, 'fine' ) %] [% SET fine = CirculationRules.Search( branchcode, c, i, 'fine' ) %]
[% SET chargeperiod = CirculationRules.Get( branchcode, c, i, 'chargeperiod' ) %] [% SET chargeperiod = CirculationRules.Search( branchcode, c, i, 'chargeperiod' ) %]
[% SET chargeperiod_charge_at = CirculationRules.Get( branchcode, c, i, 'chargeperiod_charge_at' ) %] [% SET chargeperiod_charge_at = CirculationRules.Search( branchcode, c, i, 'chargeperiod_charge_at' ) %]
[% SET firstremind = CirculationRules.Get( branchcode, c, i, 'firstremind' ) %] [% SET firstremind = CirculationRules.Search( branchcode, c, i, 'firstremind' ) %]
[% SET overduefinescap = CirculationRules.Get( branchcode, c, i, 'overduefinescap' ) %] [% SET overduefinescap = CirculationRules.Search( branchcode, c, i, 'overduefinescap' ) %]
[% SET cap_fine_to_replacement_price = CirculationRules.Get( branchcode, c, i, 'cap_fine_to_replacement_price' ) %] [% SET cap_fine_to_replacement_price = CirculationRules.Search( branchcode, c, i, 'cap_fine_to_replacement_price' ) %]
[% SET finedays = CirculationRules.Get( branchcode, c, i, 'finedays' ) %] [% SET finedays = CirculationRules.Search( branchcode, c, i, 'finedays' ) %]
[% SET maxsuspensiondays = CirculationRules.Get( branchcode, c, i, 'maxsuspensiondays' ) %] [% SET maxsuspensiondays = CirculationRules.Search( branchcode, c, i, 'maxsuspensiondays' ) %]
[% SET suspension_chargeperiod = CirculationRules.Get( branchcode, c, i, 'suspension_chargeperiod' ) %] [% SET suspension_chargeperiod = CirculationRules.Search( branchcode, c, i, 'suspension_chargeperiod' ) %]
[% SET renewalsallowed = CirculationRules.Get( branchcode, c, i, 'renewalsallowed' ) %] [% SET renewalsallowed = CirculationRules.Search( branchcode, c, i, 'renewalsallowed' ) %]
[% SET renewalperiod = CirculationRules.Get( branchcode, c, i, 'renewalperiod' ) %] [% SET renewalperiod = CirculationRules.Search( branchcode, c, i, 'renewalperiod' ) %]
[% SET norenewalbefore = CirculationRules.Get( branchcode, c, i, 'norenewalbefore' ) %] [% SET norenewalbefore = CirculationRules.Search( branchcode, c, i, 'norenewalbefore' ) %]
[% SET auto_renew = CirculationRules.Get( branchcode, c, i, 'auto_renew' ) %] [% SET auto_renew = CirculationRules.Search( branchcode, c, i, 'auto_renew' ) %]
[% SET no_auto_renewal_after = CirculationRules.Get( branchcode, c, i, 'no_auto_renewal_after' ) %] [% SET no_auto_renewal_after = CirculationRules.Search( branchcode, c, i, 'no_auto_renewal_after' ) %]
[% SET no_auto_renewal_after_hard_limit = CirculationRules.Get( branchcode, c, i, 'no_auto_renewal_after_hard_limit' ) %] [% SET no_auto_renewal_after_hard_limit = CirculationRules.Search( branchcode, c, i, 'no_auto_renewal_after_hard_limit' ) %]
[% SET reservesallowed = CirculationRules.Get( branchcode, c, i, 'reservesallowed' ) %] [% SET reservesallowed = CirculationRules.Search( branchcode, c, i, 'reservesallowed' ) %]
[% SET holds_per_day = CirculationRules.Get( branchcode, c, i, 'holds_per_day' ) %] [% SET holds_per_day = CirculationRules.Search( branchcode, c, i, 'holds_per_day' ) %]
[% SET holds_per_record = CirculationRules.Get( branchcode, c, i, 'holds_per_record' ) %] [% SET holds_per_record = CirculationRules.Search( branchcode, c, i, 'holds_per_record' ) %]
[% SET onshelfholds = CirculationRules.Get( branchcode, c, i, 'onshelfholds' ) %] [% SET onshelfholds = CirculationRules.Search( branchcode, c, i, 'onshelfholds' ) %]
[% SET opacitemholds = CirculationRules.Get( branchcode, c, i, 'opacitemholds' ) %] [% SET opacitemholds = CirculationRules.Search( branchcode, c, i, 'opacitemholds' ) %]
[% SET article_requests = CirculationRules.Get( branchcode, c, i, 'article_requests' ) %] [% SET article_requests = CirculationRules.Search( branchcode, c, i, 'article_requests' ) %]
[% SET rentaldiscount = CirculationRules.Get( branchcode, c, i, 'rentaldiscount' ) %] [% SET rentaldiscount = CirculationRules.Search( branchcode, c, i, 'rentaldiscount' ) %]
[% SET show_rule = maxissueqty || maxonsiteissueqty || issuelength || lengthunit || hardduedate || hardduedatebefore || hardduedateexact || fine || chargeperiod [% SET show_rule = maxissueqty || maxonsiteissueqty || issuelength || lengthunit || hardduedate || hardduedatebefore || hardduedateexact || fine || chargeperiod || chargeperiod_charge_at || firstremind || overduefinescap || cap_fine_to_replacement_price || finedays || maxsuspensiondays || suspension_chargeperiod || renewalsallowed || renewalsallowed || norenewalbefore || auto_renew || no_auto_renewal_after || no_auto_renewal_after_hard_limit || reservesallowed || holds_per_day || holds_per_record || onshelfholds || opacitemholds || article_requests || article_requests %]
|| chargeperiod_charge_at || firstremind || overduefinescap || cap_fine_to_replacement_price || finedays || maxsuspensiondays || suspension_chargeperiod || renewalsallowed
|| renewalsallowed || norenewalbefore || auto_renew || no_auto_renewal_after || no_auto_renewal_after_hard_limit || reservesallowed
|| holds_per_day || holds_per_record || onshelfholds || opacitemholds || article_requests || article_requests %]
[% IF show_rule %] [% IF show_rule %]
[% SET row_count = row_count + 1 %] [% SET row_count = row_count + 1 %]
<tr row_countd="row_[% row_count %]"> <tr row_countd="row_[% row_count %]">
@ -180,8 +177,8 @@
<a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype || '*' %]&amp;categorycode=[% rule.categorycode || '*' %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a> <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype || '*' %]&amp;categorycode=[% rule.categorycode || '*' %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
</td> </td>
<td> <td>
[% IF rule.note %] [% IF note.defined %]
<a name="viewnote" data-toggle="popover" title="Note" data-content="[% rule.note | html %]" data-placement="top" data-trigger="hover">View note</a> <a name="viewnote" data-toggle="popover" title="Note" data-content="[% note | html %]" data-placement="top" data-trigger="hover">View note</a>
[% ELSE %]<span>&nbsp;</span>[% END %] [% ELSE %]<span>&nbsp;</span>[% END %]
</td> </td>
<td> <td>

13
t/db_dependent/Circulation/CalcFine.t

@ -165,13 +165,12 @@ subtest 'Test cap_fine_to_replacement_pricew with overduefinescap' => sub {
plan tests => 2; plan tests => 2;
t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1'); t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1');
my $issuingrule = $builder->build_object( Koha::CirculationRules->set_rules(
{ {
class => 'Koha::IssuingRules', branchcode => undef,
value => { categorycode => undef,
branchcode => '*', itemtype => undef,
categorycode => '*', rules => {
itemtype => '*',
fine => '1.00', fine => '1.00',
lengthunit => 'days', lengthunit => 'days',
finedays => 0, finedays => 0,
@ -198,7 +197,7 @@ subtest 'Test cap_fine_to_replacement_pricew with overduefinescap' => sub {
my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt ); my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
is( int($amount), 3, 'Got the lesser of overduefinescap and replacement price where overduefinescap < replacement price' ); is( int($amount), 3, 'Got the lesser of overduefinescap and replacement price where overduefinescap < replacement price' );
$issuingrule->overduefinescap(6)->store(); Koha::CirculationRules->set_rule({ rule_name => 'overduefinescap', rule_value => 6, branchcode => undef, categorycode => undef, itemtype => undef });
($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt ); ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
is( int($amount), 5, 'Get the lesser of overduefinescap and replacement price where overduefinescap > replacement price' ); is( int($amount), 5, 'Get the lesser of overduefinescap and replacement price where overduefinescap > replacement price' );

17
t/db_dependent/Circulation/TooMany.t

@ -500,18 +500,19 @@ subtest 'General vs specific rules limit quantity correctly' => sub {
}); });
# Set up an issuing rule # Set up an issuing rule
my $rule = $builder->build({ Koha::CirculationRules->set_rules(
source => 'Issuingrule', {
value => {
categorycode => '*', categorycode => '*',
itemtype => $itemtype->{itemtype}, itemtype => $itemtype->{itemtype},
branchcode => '*', branchcode => '*',
issuelength => 1, rules => {
firstremind => 1, # 1 day of grace issuelength => 1,
finedays => 2, # 2 days of fine per day of overdue firstremind => 1, # 1 day of grace
lengthunit => 'days', finedays => 2, # 2 days of fine per day of overdue
lengthunit => 'days',
}
} }
}); );
# Set an All->All for an itemtype # Set an All->All for an itemtype
Koha::CirculationRules->set_rules( Koha::CirculationRules->set_rules(

17
t/db_dependent/Circulation/issue.t

@ -87,16 +87,15 @@ my $categorycode = $builder->build({
})->{categorycode}; })->{categorycode};
# A default issuingrule should always be present # A default issuingrule should always be present
my $issuingrule = $builder->build( Koha::CirculationRules->set_rules(
{ {
source => 'Issuingrule', itemtype => '*',
value => { categorycode => '*',
itemtype => '*', branchcode => '*',
categorycode => '*', rules => {
branchcode => '*', lengthunit => 'days',
lengthunit => 'days', issuelength => 0,
issuelength => 0, renewalperiod => 0,
renewalperiod => 0,
renewalsallowed => 0 renewalsallowed => 0
} }
} }

55
t/db_dependent/Holds.t

@ -460,7 +460,7 @@ subtest 'Test max_holds per library/patron category' => sub {
$dbh->do('DELETE FROM reserves'); $dbh->do('DELETE FROM reserves');
$dbh->do('DELETE FROM circulation_rules'); $dbh->do('DELETE FROM circulation_rules');
$biblio = $builder->build_sample_biblio({ itemtype => 'TEST' }); $biblio = $builder->build_sample_biblio;
( $item_bibnum, $item_bibitemnum, $itemnumber ) = ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 },
$biblio->biblionumber ); $biblio->biblionumber );
@ -468,7 +468,7 @@ subtest 'Test max_holds per library/patron category' => sub {
{ {
categorycode => undef, categorycode => undef,
branchcode => undef, branchcode => undef,
itemtype => $testitemtype, itemtype => $biblio->itemtype,
rules => { rules => {
reservesallowed => 99, reservesallowed => 99,
holds_per_record => 99, holds_per_record => 99,
@ -535,11 +535,17 @@ subtest 'Pickup location availability tests' => sub {
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) my ( $item_bibnum, $item_bibitemnum, $itemnumber )
= AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber ); = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber );
#Add a default rule to allow some holds #Add a default rule to allow some holds
$dbh->do(
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) Koha::CirculationRules->set_rules(
VALUES (?, ?, ?, ?, ?)}, {
{}, branchcode => undef,
'*', '*', '*', 25, 99 categorycode => undef,
itemtype => undef,
rules => {
reservesallowed => 25,
holds_per_record => 99,
}
}
); );
my $item = Koha::Items->find($itemnumber); my $item = Koha::Items->find($itemnumber);
my $branch_to = $builder->build({ source => 'Branch' })->{ branchcode }; my $branch_to = $builder->build({ source => 'Branch' })->{ branchcode };
@ -641,7 +647,16 @@ subtest 'CanItemBeReserved / holds_per_day tests' => sub {
); );
# Raise reservesallowed to avoid tooManyReserves from it # Raise reservesallowed to avoid tooManyReserves from it
$issuingrule->set( { reservesallowed => 3 } )->store; Koha::CirculationRules->set_rule(
{
categorycode => '*',
branchcode => '*',
itemtype => $itemtype->itemtype,
rule_name => 'reservesallowed',
rule_value => 3,
}
);
is_deeply( is_deeply(
CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ), CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ),
@ -669,7 +684,17 @@ subtest 'CanItemBeReserved / holds_per_day tests' => sub {
); );
# Set holds_per_day to 0 # Set holds_per_day to 0
$issuingrule->set( { holds_per_day => 0 } )->store; Koha::CirculationRules->set_rule(
{
categorycode => '*',
branchcode => '*',
itemtype => $itemtype->itemtype,
rule_name => 'holds_per_day',
rule_value => 0,
}
);
# Delete existing holds # Delete existing holds
Koha::Holds->search->delete; Koha::Holds->search->delete;
@ -679,7 +704,17 @@ subtest 'CanItemBeReserved / holds_per_day tests' => sub {
'Patron cannot reserve if holds_per_day is 0 (i.e. 0 is 0)' 'Patron cannot reserve if holds_per_day is 0 (i.e. 0 is 0)'
); );
$issuingrule->set( { holds_per_day => undef } )->store; Koha::CirculationRules->set_rule(
{
categorycode => '*',
branchcode => '*',
itemtype => $itemtype->itemtype,
rule_name => 'holds_per_day',
rule_value => undef,
}
);
Koha::Holds->search->delete; Koha::Holds->search->delete;
is_deeply( is_deeply(
CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ), CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ),

51
t/db_dependent/ILSDI_Services.t

@ -379,20 +379,21 @@ subtest 'Holds test' => sub {
source => 'Item', source => 'Item',
value => { value => {
biblionumber => $biblio2->{biblionumber}, biblionumber => $biblio2->{biblionumber},
damaged => 0 damaged => 0,
itype => $builder->build_object({ class => 'Koha::ItemTypes' })->itemtype,
} }
}); });
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' ); t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
my $issuingrule = $builder->build({ Koha::CirculationRules->set_rule(
source => 'Issuingrule', {
value => {
categorycode => $patron->{categorycode}, categorycode => $patron->{categorycode},
itemtype => $item2->{itype}, itemtype => $item2->{itype},
branchcode => $patron->{branchcode}, branchcode => $patron->{branchcode},
reservesallowed => 0, rule_name => 'reservesallowed',
rule_value => 0,
} }
}); );
$query = new CGI; $query = new CGI;
$query->param( 'patron_id', $patron->{borrowernumber}); $query->param( 'patron_id', $patron->{borrowernumber});
@ -419,6 +420,7 @@ subtest 'Holds test' => sub {
value => { value => {
biblionumber => $biblio3->{biblionumber}, biblionumber => $biblio3->{biblionumber},
damaged => 0, damaged => 0,
itype => $builder->build_object({ class => 'Koha::ItemTypes' })->itemtype,
} }
}); });
@ -427,18 +429,19 @@ subtest 'Holds test' => sub {
value => { value => {
biblionumber => $biblio3->{biblionumber}, biblionumber => $biblio3->{biblionumber},
damaged => 1, damaged => 1,
itype => $builder->build_object({ class => 'Koha::ItemTypes' })->itemtype,
} }
}); });
my $issuingrule2 = $builder->build({ Koha::CirculationRules->set_rule(
source => 'Issuingrule', {
value => {
categorycode => $patron->{categorycode}, categorycode => $patron->{categorycode},
itemtype => $item3->{itype}, itemtype => $item3->{itype},
branchcode => $patron->{branchcode}, branchcode => $patron->{branchcode},
reservesallowed => 10, rule_name => 'reservesallowed',
rule_value => 10,
} }
}); );
$query = new CGI; $query = new CGI;
$query->param( 'patron_id', $patron->{borrowernumber}); $query->param( 'patron_id', $patron->{borrowernumber});
@ -499,19 +502,19 @@ subtest 'Holds test for branch transfer limits' => sub {
biblionumber => $biblio->{biblionumber}, biblionumber => $biblio->{biblionumber},
damaged => 0, damaged => 0,
itemlost => 0, itemlost => 0,
itype => $builder->build_object({ class => 'Koha::ItemTypes' })->itemtype,
} }
}); });
Koha::IssuingRules->search()->delete(); Koha::CirculationRules->set_rule(
my $issuingrule = $builder->build({ {
source => 'Issuingrule', categorycode => undef,
value => { itemtype => undef,
categorycode => '*', branchcode => undef,
itemtype => '*', rule_name => 'reservesallowed',
branchcode => '*', rule_value => 99,
reservesallowed => 99,
} }
}); );
my $limit = Koha::Item::Transfer::Limit->new({ my $limit = Koha::Item::Transfer::Limit->new({
toBranch => $pickup_branch->{branchcode}, toBranch => $pickup_branch->{branchcode},

69
t/db_dependent/Koha/IssuingRules.t

@ -19,7 +19,7 @@
use Modern::Perl; use Modern::Perl;
use Test::More tests => 3; use Test::More tests => 2;
use Test::Deep qw( cmp_methods ); use Test::Deep qw( cmp_methods );
use Test::Exception; use Test::Exception;
@ -54,6 +54,7 @@ subtest 'get_effective_issuing_rule' => sub {
categorycode => undef, categorycode => undef,
itemtype => undef, itemtype => undef,
rule_name => 'fine', rule_name => 'fine',
rule_value => 1,
}); });
is($rule, undef, 'When I attempt to get effective issuing rule by' is($rule, undef, 'When I attempt to get effective issuing rule by'
.' providing undefined values, then undef is returned.'); .' providing undefined values, then undef is returned.');
@ -62,6 +63,7 @@ subtest 'get_effective_issuing_rule' => sub {
categorycode => undef, categorycode => undef,
itemtype => undef, itemtype => undef,
rule_name => 'fine', rule_name => 'fine',
rule_value => 2,
})->store, 'Given I added an issuing rule branchcode => undef,' })->store, 'Given I added an issuing rule branchcode => undef,'
.' categorycode => undef, itemtype => undef,'); .' categorycode => undef, itemtype => undef,');
$rule = Koha::CirculationRules->get_effective_rule({ $rule = Koha::CirculationRules->get_effective_rule({
@ -69,6 +71,7 @@ subtest 'get_effective_issuing_rule' => sub {
categorycode => undef, categorycode => undef,
itemtype => undef, itemtype => undef,
rule_name => 'fine', rule_name => 'fine',
rule_value => 3,
}); });
_is_row_match( _is_row_match(
$rule, $rule,
@ -94,6 +97,7 @@ subtest 'get_effective_issuing_rule' => sub {
categorycode => $categorycode, categorycode => $categorycode,
itemtype => $itemtype, itemtype => $itemtype,
rule_name => 'fine', rule_name => 'fine',
rule_value => 4,
}); });
is($rule, undef, 'When I attempt to get effective issuing rule, then undef' is($rule, undef, 'When I attempt to get effective issuing rule, then undef'
.' is returned.'); .' is returned.');
@ -103,12 +107,14 @@ subtest 'get_effective_issuing_rule' => sub {
categorycode => undef, categorycode => undef,
itemtype => undef, itemtype => undef,
rule_name => 'fine', rule_name => 'fine',
rule_value => 5,
})->store, 'Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => undef,'); })->store, 'Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => undef,');
$rule = Koha::CirculationRules->get_effective_rule({ $rule = Koha::CirculationRules->get_effective_rule({
branchcode => $branchcode, branchcode => $branchcode,
categorycode => $categorycode, categorycode => $categorycode,
itemtype => $itemtype, itemtype => $itemtype,
rule_name => 'fine', rule_name => 'fine',
rule_value => 6,
}); });
_is_row_match( _is_row_match(
$rule, $rule,
@ -126,12 +132,14 @@ subtest 'get_effective_issuing_rule' => sub {
categorycode => undef, categorycode => undef,
itemtype => $itemtype, itemtype => $itemtype,
rule_name => 'fine', rule_name => 'fine',
rule_value => 7,
})->store, "Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => $itemtype,"); })->store, "Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => $itemtype,");
$rule = Koha::CirculationRules->get_effective_rule({ $rule = Koha::CirculationRules->get_effective_rule({
branchcode => $branchcode, branchcode => $branchcode,
categorycode => $categorycode, categorycode => $categorycode,
itemtype => $itemtype, itemtype => $itemtype,
rule_name => 'fine', rule_name => 'fine',
rule_value => 8,
}); });
_is_row_match( _is_row_match(
$rule, $rule,
@ -149,12 +157,14 @@ subtest 'get_effective_issuing_rule' => sub {
categorycode => $categorycode, categorycode => $categorycode,
itemtype => undef, itemtype => undef,
rule_name => 'fine', rule_name => 'fine',
rule_value => 9,
})->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => undef,"); })->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => undef,");
$rule = Koha::CirculationRules->get_effective_rule({ $rule = Koha::CirculationRules->get_effective_rule({
branchcode => $branchcode, branchcode => $branchcode,
categorycode => $categorycode, categorycode => $categorycode,
itemtype => $itemtype, itemtype => $itemtype,
rule_name => 'fine', rule_name => 'fine',
rule_value => 10,
}); });
_is_row_match( _is_row_match(
$rule, $rule,
@ -172,12 +182,14 @@ subtest 'get_effective_issuing_rule' => sub {
categorycode => $categorycode, categorycode => $categorycode,
itemtype => $itemtype, itemtype => $itemtype,
rule_name => 'fine', rule_name => 'fine',
rule_value => 11,
})->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => $itemtype,"); })->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => $itemtype,");
$rule = Koha::CirculationRules->get_effective_rule({ $rule = Koha::CirculationRules->get_effective_rule({
branchcode => $branchcode, branchcode => $branchcode,
categorycode => $categorycode, categorycode => $categorycode,
itemtype => $itemtype, itemtype => $itemtype,
rule_name => 'fine', rule_name => 'fine',
rule_value => 12,
}); });
_is_row_match( _is_row_match(
$rule, $rule,
@ -195,12 +207,14 @@ subtest 'get_effective_issuing_rule' => sub {
categorycode => undef, categorycode => undef,
itemtype => undef, itemtype => undef,
rule_name => 'fine', rule_name => 'fine',
rule_value => 13,
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => undef,"); })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => undef,");
$rule = Koha::CirculationRules->get_effective_rule({ $rule = Koha::CirculationRules->get_effective_rule({
branchcode => $branchcode, branchcode => $branchcode,
categorycode => $categorycode, categorycode => $categorycode,
itemtype => $itemtype, itemtype => $itemtype,
rule_name => 'fine', rule_name => 'fine',
rule_value => 14,
}); });
_is_row_match( _is_row_match(
$rule, $rule,
@ -218,12 +232,14 @@ subtest 'get_effective_issuing_rule' => sub {
categorycode => undef, categorycode => undef,
itemtype => $itemtype, itemtype => $itemtype,
rule_name => 'fine', rule_name => 'fine',
rule_value => 15,
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => $itemtype,"); })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => $itemtype,");
$rule = Koha::CirculationRules->get_effective_rule({ $rule = Koha::CirculationRules->get_effective_rule({
branchcode => $branchcode, branchcode => $branchcode,
categorycode => $categorycode, categorycode => $categorycode,
itemtype => $itemtype, itemtype => $itemtype,
rule_name => 'fine', rule_name => 'fine',
rule_value => 16,
}); });
_is_row_match( _is_row_match(
$rule, $rule,
@ -241,12 +257,14 @@ subtest 'get_effective_issuing_rule' => sub {
categorycode => $categorycode, categorycode => $categorycode,
itemtype => undef, itemtype => undef,
rule_name => 'fine', rule_name => 'fine',
rule_value => 17,
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => undef,"); })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => undef,");
$rule = Koha::CirculationRules->get_effective_rule({ $rule = Koha::CirculationRules->get_effective_rule({
branchcode => $branchcode, branchcode => $branchcode,
categorycode => $categorycode, categorycode => $categorycode,
itemtype => $itemtype, itemtype => $itemtype,
rule_name => 'fine', rule_name => 'fine',
rule_value => 18,
}); });
_is_row_match( _is_row_match(
$rule, $rule,
@ -264,12 +282,14 @@ subtest 'get_effective_issuing_rule' => sub {
categorycode => $categorycode, categorycode => $categorycode,
itemtype => $itemtype, itemtype => $itemtype,
rule_name => 'fine', rule_name => 'fine',
rule_value => 19,
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype,"); })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype,");
$rule = Koha::CirculationRules->get_effective_rule({ $rule = Koha::CirculationRules->get_effective_rule({
branchcode => $branchcode, branchcode => $branchcode,
categorycode => $categorycode, categorycode => $categorycode,
itemtype => $itemtype, itemtype => $itemtype,
rule_name => 'fine', rule_name => 'fine',
rule_value => 20,
}); });
_is_row_match( _is_row_match(
$rule, $rule,
@ -460,53 +480,6 @@ subtest 'set_rule' => sub {
}; };
}; };
subtest 'delete' => sub {
plan tests => 1;
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
my $library = $builder->build_object({ class => 'Koha::Libraries' });
my $category = $builder->build_object({ class => 'Koha::Patron::Categories' });
# We make an issuing rule
my $issue_rule = $builder->build_object({ class => 'Koha::IssuingRules', value => {
categorycode => $category->categorycode,
itemtype => $itemtype->itemtype,
branchcode => $library->branchcode
}
});
my $count = Koha::CirculationRules->search()->count;
# Note how many circulation rules we start with
# We make some circulation rules for the same thing
$builder->build_object({ class => 'Koha::CirculationRules', value => {
categorycode => $category->categorycode,
itemtype => $itemtype->itemtype,
branchcode => $library->branchcode,
rule_name => 'maxissueqty',
}
});
$builder->build_object({ class => 'Koha::CirculationRules', value => {
categorycode => $category->categorycode,
itemtype => $itemtype->itemtype,
branchcode => $library->branchcode,
rule_name => 'maxonsiteissueqty',
}
});
$builder->build_object({ class => 'Koha::CirculationRules', value => {
categorycode => $category->categorycode,
itemtype => $itemtype->itemtype,
branchcode => $library->branchcode,
rule_name => 'another_rule', # That must not be deleted
}
});
# Now we delete the issuing rule
$issue_rule->delete;
is( Koha::CirculationRules->search()->count ,$count + 1, "We remove related circ rules maxissueqty and maxonsiteissueqty with our issuing rule");
};
sub _is_row_match { sub _is_row_match {
my ( $rule, $expected, $message ) = @_; my ( $rule, $expected, $message ) = @_;

1
t/db_dependent/SIP/Transaction.t

@ -16,7 +16,6 @@ use C4::SIP::ILS::Transaction::FeePayment;
use C4::SIP::ILS::Transaction::Hold; use C4::SIP::ILS::Transaction::Hold;
use C4::Reserves; use C4::Reserves;
use Koha::IssuingRules;
my $schema = Koha::Database->new->schema; my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin; $schema->storage->txn_begin;

2
t/db_dependent/selenium/administration_tasks.t

@ -84,7 +84,7 @@ SKIP: {
$elt = $driver->find_elements('//table[@id="default-circulation-rules"]/tbody/tr/td[contains(text(),"'.$itype->description.'")]/following-sibling::td/span[text() = "Unlimited"]'); $elt = $driver->find_elements('//table[@id="default-circulation-rules"]/tbody/tr/td[contains(text(),"'.$itype->description.'")]/following-sibling::td/span[text() = "Unlimited"]');
is( @$elt,2,"We have unlimited checkouts"); is( @$elt,2,"We have unlimited checkouts");
#Clean up #Clean up
Koha::IssuingRules->find({itemtype=>$itype->itemtype})->delete(); Koha::CirculationRules->search( { itemtype => $itype->itemtype } )->delete;
$itype->delete; $itype->delete;
# TODO Create more smart rules navigation here # TODO Create more smart rules navigation here
}; };

Loading…
Cancel
Save