View | Details | Raw Unified | Return to bug 21946
Collapse All | Expand All

(-)a/C4/Circulation.pm (-80 / +155 lines)
Lines 387-394 sub TooMany { Link Here
387
    $branch = _GetCircControlBranch($item_object->unblessed,$borrower);
387
    $branch = _GetCircControlBranch($item_object->unblessed,$borrower);
388
    my $type = $item_object->effective_itemtype;
388
    my $type = $item_object->effective_itemtype;
389
389
390
    my ($type_object, $parent_type, $parent_maxissueqty_rule);
391
    $type_object = Koha::ItemTypes->find( $type );
392
    $parent_type = $type_object->parent_type if $type_object;
393
    my $child_types = Koha::ItemTypes->search({ parent_type => $type });
394
    # Find any children if we are a parent_type;
395
390
    # given branch, patron category, and item type, determine
396
    # given branch, patron category, and item type, determine
391
    # applicable issuing rule
397
    # applicable issuing rule
398
399
    $parent_maxissueqty_rule = Koha::CirculationRules->get_effective_rule(
400
        {
401
            categorycode => $cat_borrower,
402
            itemtype     => $parent_type,
403
            branchcode   => $branch,
404
            rule_name    => 'maxissueqty',
405
        }
406
    ) if $parent_type;
407
    # If the parent rule is for default type we discount it
408
    $parent_maxissueqty_rule = undef if $parent_maxissueqty_rule && !defined $parent_maxissueqty_rule->itemtype;
409
392
    my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule(
410
    my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule(
393
        {
411
        {
394
            categorycode => $cat_borrower,
412
            categorycode => $cat_borrower,
Lines 397-402 sub TooMany { Link Here
397
            rule_name    => 'maxissueqty',
415
            rule_name    => 'maxissueqty',
398
        }
416
        }
399
    );
417
    );
418
419
400
    my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule(
420
    my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule(
401
        {
421
        {
402
            categorycode => $cat_borrower,
422
            categorycode => $cat_borrower,
Lines 410-419 sub TooMany { Link Here
410
    # if a rule is found and has a loan limit set, count
430
    # if a rule is found and has a loan limit set, count
411
    # how many loans the patron already has that meet that
431
    # how many loans the patron already has that meet that
412
    # rule
432
    # rule
413
    if (defined($maxissueqty_rule) and $maxissueqty_rule->rule_value ne '') {
433
    if (defined($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) {
434
414
        my @bind_params;
435
        my @bind_params;
415
        my $count_query = q|
436
        my $count_query = "";
416
            SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
437
438
        if (C4::Context->preference('item-level_itypes')) {
439
            $count_query .= q|SELECT COALESCE( SUM( IF(items.itype = '| .$type . q|',1,0) ), 0) as type_total, COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts|;
440
        } else{
441
            $count_query .= q|SELECT COALESCE(SUM( IF(biblioitems.itemtype = '| .$type . q|',1,0) ), 0) as type_total, COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts|;
442
        }
443
444
        $count_query .= q|
417
            FROM issues
445
            FROM issues
418
            JOIN items USING (itemnumber)
446
            JOIN items USING (itemnumber)
419
        |;
447
        |;
Lines 423-459 sub TooMany { Link Here
423
            # matching rule has the default item type, so count only
451
            # matching rule has the default item type, so count only
424
            # those existing loans that don't fall under a more
452
            # those existing loans that don't fall under a more
425
            # specific rule
453
            # specific rule
454
            my $issuing_itemtypes_query  = q{
455
                SELECT itemtype FROM circulation_rules
456
                WHERE branchcode = ?
457
                AND   (categorycode = ? OR categorycode = ?)
458
                AND   itemtype IS NOT NULL
459
                AND   rule_name = 'maxissueqty'
460
            };
426
            if (C4::Context->preference('item-level_itypes')) {
461
            if (C4::Context->preference('item-level_itypes')) {
427
                $count_query .= " WHERE items.itype NOT IN (
462
                $count_query .= " WHERE items.itype NOT IN ( $issuing_itemtypes_query )";
428
                                    SELECT itemtype FROM circulation_rules
429
                                    WHERE branchcode = ?
430
                                    AND   (categorycode = ? OR categorycode = ?)
431
                                    AND   itemtype IS NOT NULL
432
                                    AND   rule_name = 'maxissueqty'
433
                                  ) ";
434
            } else {
463
            } else {
435
                $count_query .= " JOIN  biblioitems USING (biblionumber)
464
                $count_query .= " WHERE biblioitems.itemtype NOT IN ( $issuing_itemtypes_query )";
436
                                  WHERE biblioitems.itemtype NOT IN (
437
                                    SELECT itemtype FROM circulation_rules
438
                                    WHERE branchcode = ?
439
                                    AND   (categorycode = ? OR categorycode = ?)
440
                                    AND   itemtype IS NOT NULL
441
                                    AND   rule_name = 'maxissueqty'
442
                                  ) ";
443
            }
465
            }
444
            push @bind_params, $maxissueqty_rule->branchcode;
466
            push @bind_params, $maxissueqty_rule->branchcode;
445
            push @bind_params, $maxissueqty_rule->categorycode;
467
            push @bind_params, $maxissueqty_rule->categorycode;
446
            push @bind_params, $cat_borrower;
468
            push @bind_params, $cat_borrower;
447
        } else {
469
        } else {
448
            # rule has specific item type, so count loans of that
470
            my @types;
449
            # specific item type
471
            if ( $parent_maxissueqty_rule ) {
472
            # if we have a parent item type then we count loans of the
473
            # specific item type or its siblings or parent
474
                my $children = Koha::ItemTypes->search({ parent_type => $parent_type });
475
                @types = $children->get_column('itemtype');
476
                push @types, $parent_type;
477
            } elsif ( $child_types ) {
478
            # If we are a parent type, we need to count all child types and our own type
479
                @types = $child_types->get_column('itemtype');
480
                push @types, $type; # And don't forget to count our own types
481
            } else { push @types, $type; } # Otherwise only count the specific itemtype
482
            my $types_param = ( '?,' ) x @types;
483
            $types_param =~ s/,$//;
450
            if (C4::Context->preference('item-level_itypes')) {
484
            if (C4::Context->preference('item-level_itypes')) {
451
                $count_query .= " WHERE items.itype = ? ";
485
                $count_query .= " WHERE items.itype IN (" . $types_param . ")";
452
            } else { 
486
            } else { 
453
                $count_query .= " JOIN  biblioitems USING (biblionumber) 
487
                $count_query .= " JOIN  biblioitems USING (biblionumber) 
454
                                  WHERE biblioitems.itemtype= ? ";
488
                                  WHERE biblioitems.itemtype IN (" . $types_param . ")";
455
            }
489
            }
456
            push @bind_params, $type;
490
            push @bind_params, @types;
457
        }
491
        }
458
492
459
        $count_query .= " AND borrowernumber = ? ";
493
        $count_query .= " AND borrowernumber = ? ";
Lines 471-508 sub TooMany { Link Here
471
            }
505
            }
472
        }
506
        }
473
507
474
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
508
        my ( $checkout_count_type, $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params );
475
509
476
        my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : undef;
477
        my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : undef;
510
        my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : undef;
478
511
479
        if ( $onsite_checkout and $max_onsite_checkouts_allowed ne '' ) {
512
        # If parent rules exists
480
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
513
        if ( defined($parent_maxissueqty_rule) and defined($parent_maxissueqty_rule->rule_value) ){
481
                return {
514
            my $max_checkouts_allowed = $parent_maxissueqty_rule->rule_value;
482
                    reason => 'TOO_MANY_ONSITE_CHECKOUTS',
515
483
                    count => $onsite_checkout_count,
516
            my $qty_over = _check_max_qty({
484
                    max_allowed => $max_onsite_checkouts_allowed,
517
                checkout_count => $checkout_count,
485
                }
518
                onsite_checkout_count => $onsite_checkout_count,
486
            }
519
                onsite_checkout => $onsite_checkout,
487
        }
520
                max_checkouts_allowed => $max_checkouts_allowed,
488
        if ( C4::Context->preference('ConsiderOnSiteCheckoutsAsNormalCheckouts') ) {
521
                max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed,
489
            my $delta = $switch_onsite_checkout ? 1 : 0;
522
                switch_onsite_checkout       => $switch_onsite_checkout
490
            if ( $checkout_count >= $max_checkouts_allowed + $delta ) {
523
            });
491
                return {
524
            return $qty_over if defined $qty_over;
492
                    reason => 'TOO_MANY_CHECKOUTS',
525
493
                    count => $checkout_count,
526
494
                    max_allowed => $max_checkouts_allowed,
527
           # If the parent rule is less than or equal to the child, we only need check the parent
495
                };
528
           if( $maxissueqty_rule->rule_value < $parent_maxissueqty_rule->rule_value && defined($maxissueqty_rule->itemtype) ) {
496
            }
529
               my $max_checkouts_allowed = $maxissueqty_rule->rule_value;
497
        } elsif ( not $onsite_checkout ) {
530
               my $qty_over = _check_max_qty({
498
            if ( $checkout_count - $onsite_checkout_count >= $max_checkouts_allowed )  {
531
                   checkout_count => $checkout_count_type,
499
                return {
532
                   onsite_checkout_count => $onsite_checkout_count,
500
                    reason => 'TOO_MANY_CHECKOUTS',
533
                   onsite_checkout => $onsite_checkout,
501
                    count => $checkout_count - $onsite_checkout_count,
534
                   max_checkouts_allowed => $max_checkouts_allowed,
502
                    max_allowed => $max_checkouts_allowed,
535
                   max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed,
503
                };
536
                   switch_onsite_checkout       => $switch_onsite_checkout
504
            }
537
               });
538
               return $qty_over if defined $qty_over;
539
           }
540
541
        } else {
542
            my $max_checkouts_allowed = $maxissueqty_rule->rule_value;
543
            my $qty_over = _check_max_qty({
544
                checkout_count => $checkout_count,
545
                onsite_checkout_count => $onsite_checkout_count,
546
                onsite_checkout => $onsite_checkout,
547
                max_checkouts_allowed => $max_checkouts_allowed,
548
                max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed,
549
                switch_onsite_checkout       => $switch_onsite_checkout
550
            });
551
            return $qty_over if defined $qty_over;
505
        }
552
        }
553
554
506
    }
555
    }
507
556
508
    # Now count total loans against the limit for the branch
557
    # Now count total loans against the limit for the branch
Lines 528-562 sub TooMany { Link Here
528
        }
577
        }
529
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $branch_count_query, {}, @bind_params );
578
        my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $branch_count_query, {}, @bind_params );
530
        my $max_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxissueqty};
579
        my $max_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxissueqty};
531
        my $max_onsite_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxonsiteissueqty};
580
        my $max_onsite_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxonsiteissueqty} || undef;
532
581
533
        if ( $onsite_checkout and $max_onsite_checkouts_allowed ne '' ) {
582
        my $qty_over = _check_max_qty({
534
            if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
583
            checkout_count => $checkout_count,
535
                return {
584
            onsite_checkout_count => $onsite_checkout_count,
536
                    reason => 'TOO_MANY_ONSITE_CHECKOUTS',
585
            onsite_checkout => $onsite_checkout,
537
                    count => $onsite_checkout_count,
586
            max_checkouts_allowed => $max_checkouts_allowed,
538
                    max_allowed => $max_onsite_checkouts_allowed,
587
            max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed,
539
                }
588
            switch_onsite_checkout       => $switch_onsite_checkout
540
            }
589
        });
541
        }
590
        return $qty_over if defined $qty_over;
542
        if ( C4::Context->preference('ConsiderOnSiteCheckoutsAsNormalCheckouts') ) {
591
543
            my $delta = $switch_onsite_checkout ? 1 : 0;
544
            if ( $checkout_count >= $max_checkouts_allowed + $delta ) {
545
                return {
546
                    reason => 'TOO_MANY_CHECKOUTS',
547
                    count => $checkout_count,
548
                    max_allowed => $max_checkouts_allowed,
549
                };
550
            }
551
        } elsif ( not $onsite_checkout ) {
552
            if ( $checkout_count - $onsite_checkout_count >= $max_checkouts_allowed )  {
553
                return {
554
                    reason => 'TOO_MANY_CHECKOUTS',
555
                    count => $checkout_count - $onsite_checkout_count,
556
                    max_allowed => $max_checkouts_allowed,
557
                };
558
            }
559
        }
560
    }
592
    }
561
593
562
    if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{patron_maxissueqty}) ) {
594
    if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{patron_maxissueqty}) ) {
Lines 567-572 sub TooMany { Link Here
567
    return;
599
    return;
568
}
600
}
569
601
602
sub _check_max_qty {
603
    my $params = shift;
604
    my $checkout_count = $params->{checkout_count};
605
    my $onsite_checkout_count = $params->{onsite_checkout_count};
606
    my $onsite_checkout = $params->{onsite_checkout};
607
    my $max_checkouts_allowed = $params->{max_checkouts_allowed};
608
    my $max_onsite_checkouts_allowed = $params->{max_onsite_checkouts_allowed};
609
    my $switch_onsite_checkout = $params->{switch_onsite_checkout};
610
611
    if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
612
        if( $max_onsite_checkouts_allowed eq '' ){ return;}
613
        if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed )  {
614
            return {
615
                reason => 'TOO_MANY_ONSITE_CHECKOUTS',
616
                count => $onsite_checkout_count,
617
                max_allowed => $max_onsite_checkouts_allowed,
618
            }
619
        }
620
    }
621
    if ( C4::Context->preference('ConsiderOnSiteCheckoutsAsNormalCheckouts') ) {
622
        if( $max_checkouts_allowed eq '' ){ return;}
623
        my $delta = $switch_onsite_checkout ? 1 : 0;
624
        if ( $checkout_count >= $max_checkouts_allowed + $delta ) {
625
            return {
626
                reason => 'TOO_MANY_CHECKOUTS',
627
                count => $checkout_count,
628
                max_allowed => $max_checkouts_allowed,
629
            };
630
        }
631
    } elsif ( not $onsite_checkout ) {
632
        if( $max_checkouts_allowed eq '' ){ return;}
633
        if ( $checkout_count - $onsite_checkout_count >= $max_checkouts_allowed )  {
634
            return {
635
                reason => 'TOO_MANY_CHECKOUTS',
636
                count => $checkout_count - $onsite_checkout_count,
637
                max_allowed => $max_checkouts_allowed,
638
            };
639
        }
640
    }
641
642
    return;
643
}
644
570
=head2 CanBookBeIssued
645
=head2 CanBookBeIssued
571
646
572
  ( $issuingimpossible, $needsconfirmation, [ $alerts ] ) =  CanBookBeIssued( $patron,
647
  ( $issuingimpossible, $needsconfirmation, [ $alerts ] ) =  CanBookBeIssued( $patron,
(-)a/t/db_dependent/Circulation/TooMany.t (-2 / +263 lines)
Lines 15-21 Link Here
15
# with Koha; if not, see <http://www.gnu.org/licenses>.
15
# with Koha; if not, see <http://www.gnu.org/licenses>.
16
16
17
use Modern::Perl;
17
use Modern::Perl;
18
use Test::More tests => 9;
18
use Test::More tests => 10;
19
use C4::Context;
19
use C4::Context;
20
20
21
use C4::Members;
21
use C4::Members;
Lines 707-712 subtest 'empty string means unlimited' => sub { Link Here
707
        C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ),
707
        C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ),
708
        undef,
708
        undef,
709
        'maxonsiteissueqty="" should mean unlimited'
709
        'maxonsiteissueqty="" should mean unlimited'
710
      );
711
};
712
713
subtest 'itemtype group tests' => sub {
714
    plan tests => 13;
715
716
    t::lib::Mocks::mock_preference( 'CircControl', 'ItemHomeLibrary' );
717
    Koha::CirculationRules->set_rules(
718
        {
719
            branchcode   => '*',
720
            categorycode => '*',
721
            itemtype     => '*',
722
            rules        => {
723
                maxissueqty       => '',
724
                maxonsiteissueqty => '',
725
                issuelength       => 1,
726
                firstremind       => 1,      # 1 day of grace
727
                finedays          => 2,      # 2 days of fine per day of overdue
728
                lengthunit        => 'days',
729
            }
730
        },
731
    );
732
733
    my $parent_itype = $builder->build(
734
        {
735
            source => 'Itemtype',
736
            value  => {
737
                parent_type         => undef,
738
                rentalcharge        => undef,
739
                rentalcharge_daily  => undef,
740
                rentalcharge_hourly => undef,
741
                notforloan          => 0,
742
            }
743
        }
744
    );
745
    my $child_itype_1 = $builder->build(
746
        {
747
            source => 'Itemtype',
748
            value  => {
749
                parent_type         => $parent_itype->{itemtype},
750
                rentalcharge        => 0,
751
                rentalcharge_daily  => 0,
752
                rentalcharge_hourly => 0,
753
                notforloan          => 0,
754
            }
755
        }
756
    );
757
    my $child_itype_2 = $builder->build(
758
        {
759
            source => 'Itemtype',
760
            value  => {
761
                parent_type         => $parent_itype->{itemtype},
762
                rentalcharge        => 0,
763
                rentalcharge_daily  => 0,
764
                rentalcharge_hourly => 0,
765
                notforloan          => 0,
766
            }
767
        }
768
    );
769
770
    my $branch   = $builder->build( { source => 'Branch', } );
771
    my $category = $builder->build( { source => 'Category', } );
772
    my $patron   = $builder->build(
773
        {
774
            source => 'Borrower',
775
            value  => {
776
                categorycode => $category->{categorycode},
777
                branchcode   => $branch->{branchcode},
778
            },
779
        }
780
    );
781
    my $item = $builder->build_sample_item(
782
        {
783
            homebranch    => $branch->{branchcode},
784
            holdingbranch => $branch->{branchcode},
785
            itype         => $child_itype_1->{itemtype}
786
        }
787
    );
788
789
    my $all_iq_rule = $builder->build(
790
        {
791
            source => 'CirculationRule',
792
            value  => {
793
                branchcode   => $branch->{branchcode},
794
                categorycode => $category->{categorycode},
795
                itemtype     => undef,
796
                rule_name    => 'maxissueqty',
797
                rule_value   => 1
798
            }
799
        }
800
    );
801
    is( C4::Circulation::TooMany( $patron, $item ),
802
        undef, 'Checkout allowed, using all rule of 1' );
803
804
    #Checkout an item
805
    my $issue =
806
      C4::Circulation::AddIssue( $patron, $item->barcode, dt_from_string() );
807
    like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
808
809
    #Patron has 1 checkout of child itype1
810
811
    my $parent_iq_rule = $builder->build(
812
        {
813
            source => 'CirculationRule',
814
            value  => {
815
                branchcode   => $branch->{branchcode},
816
                categorycode => $category->{categorycode},
817
                itemtype     => $parent_itype->{itemtype},
818
                rule_name    => 'maxissueqty',
819
                rule_value   => 2
820
            }
821
        }
822
    );
823
824
    is( C4::Circulation::TooMany( $patron, $item ),
825
        undef, 'Checkout allowed, using parent type rule of 2' );
826
827
    my $child1_iq_rule = $builder->build_object(
828
        {
829
            class => 'Koha::CirculationRules',
830
            value => {
831
                branchcode   => $branch->{branchcode},
832
                categorycode => $category->{categorycode},
833
                itemtype     => $child_itype_1->{itemtype},
834
                rule_name    => 'maxissueqty',
835
                rule_value   => 1
836
            }
837
        }
838
    );
839
840
    is_deeply(
841
        C4::Circulation::TooMany( $patron, $item ),
842
        {
843
            reason      => 'TOO_MANY_CHECKOUTS',
844
            count       => 1,
845
            max_allowed => 1,
846
        },
847
        'Checkout not allowed, using specific type rule of 1'
848
    );
849
850
    my $item_1 = $builder->build_sample_item(
851
        {
852
            homebranch    => $branch->{branchcode},
853
            holdingbranch => $branch->{branchcode},
854
            itype         => $child_itype_2->{itemtype}
855
        }
856
    );
857
858
    my $child2_iq_rule = $builder->build(
859
        {
860
            source => 'CirculationRule',
861
            value  => {
862
                branchcode   => $branch->{branchcode},
863
                categorycode => $category->{categorycode},
864
                itemtype     => $child_itype_2->{itemtype},
865
                rule_name    => 'maxissueqty',
866
                rule_value   => 3
867
            }
868
        }
869
    );
870
871
    is( C4::Circulation::TooMany( $patron, $item_1 ),
872
        undef, 'Checkout allowed' );
873
874
    #checkout an item
875
    $issue =
876
      C4::Circulation::AddIssue( $patron, $item_1->barcode, dt_from_string() );
877
    like( $issue->issue_id, qr|^\d+$|, 'the issue should have been inserted' );
878
879
    #patron has 1 checkout of childitype1 and 1 checkout of childitype2
880
881
    is_deeply(
882
        C4::Circulation::TooMany( $patron, $item ),
883
        {
884
            reason      => 'TOO_MANY_CHECKOUTS',
885
            count       => 2,
886
            max_allowed => 2,
887
        },
888
'Checkout not allowed, using parent type rule of 2, checkout of sibling itemtype counted'
889
    );
890
891
    my $parent_item = $builder->build_sample_item(
892
        {
893
            homebranch    => $branch->{branchcode},
894
            holdingbranch => $branch->{branchcode},
895
            itype         => $parent_itype->{itemtype}
896
        }
897
    );
898
899
    is_deeply(
900
        C4::Circulation::TooMany( $patron, $parent_item ),
901
        {
902
            reason      => 'TOO_MANY_CHECKOUTS',
903
            count       => 2,
904
            max_allowed => 2,
905
        },
906
'Checkout not allowed, using parent type rule of 2, checkout of child itemtypes counted'
907
    );
908
909
    #increase parent type to greater than specific
910
    my $circ_rule_object =
911
      Koha::CirculationRules->find( $parent_iq_rule->{id} );
912
    $circ_rule_object->rule_value(4)->store();
913
914
    is( C4::Circulation::TooMany( $patron, $item_1 ),
915
        undef, 'Checkout allowed, using specific type rule of 3' );
916
917
    my $item_2 = $builder->build_sample_item(
918
        {
919
            homebranch    => $branch->{branchcode},
920
            holdingbranch => $branch->{branchcode},
921
            itype         => $child_itype_2->{itemtype}
922
        }
923
    );
924
925
    #checkout an item
926
    $issue =
927
      C4::Circulation::AddIssue( $patron, $item_2->barcode, dt_from_string(),
928
        undef, undef, undef );
929
    like( $issue->issue_id, qr|^\d+$|, 'the issue should have been inserted' );
930
931
    #patron has 1 checkoout of childitype1 and 2 of childitype2
932
933
    is(
934
        C4::Circulation::TooMany( $patron, $item_2 ),
935
        undef,
936
'Checkout allowed, using specific type rule of 3, checkout of sibling itemtype not counted'
937
    );
938
939
    $child1_iq_rule->rule_value(2)->store(); #Allow 2 checkouts for child type 1
940
941
    my $item_3 = $builder->build_sample_item(
942
        {
943
            homebranch    => $branch->{branchcode},
944
            holdingbranch => $branch->{branchcode},
945
            itype         => $child_itype_1->{itemtype}
946
        }
947
    );
948
    my $item_4 = $builder->build_sample_item(
949
        {
950
            homebranch    => $branch->{branchcode},
951
            holdingbranch => $branch->{branchcode},
952
            itype         => $child_itype_2->{itemtype}
953
        }
954
    );
955
956
    #checkout an item
957
    $issue =
958
      C4::Circulation::AddIssue( $patron, $item_4->barcode, dt_from_string(),
959
        undef, undef, undef );
960
    like( $issue->issue_id, qr|^\d+$|, 'the issue should have been inserted' );
961
962
    #patron has 1 checkout of childitype 1 and 3 of childitype2
963
964
    is_deeply(
965
        C4::Circulation::TooMany( $patron, $item_3 ),
966
        {
967
            reason      => 'TOO_MANY_CHECKOUTS',
968
            max_allowed => 4,
969
            count       => 4,
970
        },
971
'Checkout not allowed, using specific type rule of 2, checkout of sibling itemtype not counted, but parent rule (4) prevents another'
710
    );
972
    );
711
973
712
    teardown();
974
    teardown();
713
- 

Return to bug 21946