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

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

Return to bug 21946