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

(-)a/C4/Circulation.pm (-64 / +61 lines)
Lines 414-429 sub transferbook { Link Here
414
414
415
415
416
sub TooMany {
416
sub TooMany {
417
    my $borrower        = shift;
417
    my ($patron, $item, $params) = @_;
418
    my $item_object = shift;
419
    my $params = shift;
420
    my $onsite_checkout = $params->{onsite_checkout} || 0;
418
    my $onsite_checkout = $params->{onsite_checkout} || 0;
421
    my $switch_onsite_checkout = $params->{switch_onsite_checkout} || 0;
419
    my $switch_onsite_checkout = $params->{switch_onsite_checkout} || 0;
422
    my $cat_borrower    = $borrower->{'categorycode'};
420
    my $cat_borrower    = $patron->categorycode;
423
    my $dbh             = C4::Context->dbh;
421
    my $dbh             = C4::Context->dbh;
424
    # Get which branchcode we need
422
    # Get which branchcode we need
425
    my $branch = _GetCircControlBranch($item_object->unblessed,$borrower);
423
    my $branch = _GetCircControlBranch($item, $patron);
426
    my $type = $item_object->effective_itemtype;
424
    my $type = $item->effective_itemtype;
427
425
428
    my ($type_object, $parent_type, $parent_maxissueqty_rule);
426
    my ($type_object, $parent_type, $parent_maxissueqty_rule);
429
    $type_object = Koha::ItemTypes->find( $type );
427
    $type_object = Koha::ItemTypes->find( $type );
Lines 463-470 sub TooMany { Link Here
463
        }
461
        }
464
    );
462
    );
465
463
466
467
    my $patron = Koha::Patrons->find($borrower->{borrowernumber});
468
    # if a rule is found and has a loan limit set, count
464
    # if a rule is found and has a loan limit set, count
469
    # how many loans the patron already has that meet that
465
    # how many loans the patron already has that meet that
470
    # rule
466
    # rule
Lines 791-800 sub CanBookBeIssued { Link Here
791
    my $dbh             = C4::Context->dbh;
787
    my $dbh             = C4::Context->dbh;
792
    my $patron_unblessed = $patron->unblessed;
788
    my $patron_unblessed = $patron->unblessed;
793
789
794
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_unblessed, $patron_unblessed) );
790
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_object, $patron) );
795
791
796
    my $now = dt_from_string();
792
    my $now = dt_from_string();
797
    $duedate ||= CalcDateDue( $now, $effective_itemtype, $circ_library->branchcode, $patron_unblessed );
793
    $duedate ||= CalcDateDue( $now, $effective_itemtype, $circ_library->branchcode, $patron );
798
    if (DateTime->compare($duedate,$now) == -1 ) { # duedate cannot be before now
794
    if (DateTime->compare($duedate,$now) == -1 ) { # duedate cannot be before now
799
         $needsconfirmation{INVALID_DATE} = $duedate;
795
         $needsconfirmation{INVALID_DATE} = $duedate;
800
    }
796
    }
Lines 998-1004 sub CanBookBeIssued { Link Here
998
      and $issue
994
      and $issue
999
      and $issue->onsite_checkout
995
      and $issue->onsite_checkout
1000
      and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
996
      and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
1001
    my $toomany = TooMany( $patron_unblessed, $item_object, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
997
    my $toomany = TooMany( $patron, $item_object, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
1002
    # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
998
    # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
1003
    if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) {
999
    if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) {
1004
        if ( $toomany->{max_allowed} == 0 ) {
1000
        if ( $toomany->{max_allowed} == 0 ) {
Lines 1338-1344 sub CanBookBeReturned { Link Here
1338
1334
1339
sub checkHighHolds {
1335
sub checkHighHolds {
1340
    my ( $item, $patron ) = @_;
1336
    my ( $item, $patron ) = @_;
1341
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
1337
    my $branchcode = _GetCircControlBranch( $item, $patron );
1342
1338
1343
    my $return_data = {
1339
    my $return_data = {
1344
        exceeded    => 0,
1340
        exceeded    => 0,
Lines 1405-1411 sub checkHighHolds { Link Here
1405
        );
1401
        );
1406
        my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
1402
        my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
1407
1403
1408
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron->unblessed );
1404
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron );
1409
1405
1410
        my $rule = Koha::CirculationRules->get_effective_rule_value(
1406
        my $rule = Koha::CirculationRules->get_effective_rule_value(
1411
            {
1407
            {
Lines 1440-1452 sub checkHighHolds { Link Here
1440
1436
1441
=head2 AddIssue
1437
=head2 AddIssue
1442
1438
1443
  &AddIssue($borrower, $barcode, [$datedue], [$cancelreserve], [$issuedate])
1439
  &AddIssue($patron, $barcode, [$datedue], [$cancelreserve], [$issuedate])
1444
1440
1445
Issue a book. Does no check, they are done in CanBookBeIssued. If we reach this sub, it means the user confirmed if needed.
1441
Issue a book. Does no check, they are done in CanBookBeIssued. If we reach this sub, it means the user confirmed if needed.
1446
1442
1447
=over 4
1443
=over 4
1448
1444
1449
=item C<$borrower> is a hash with borrower informations (from Koha::Patron->unblessed).
1445
=item C<$patron> is a patron object.
1450
1446
1451
=item C<$barcode> is the barcode of the item being issued.
1447
=item C<$barcode> is the barcode of the item being issued.
1452
1448
Lines 1481-1487 AddIssue does the following things : Link Here
1481
=cut
1477
=cut
1482
1478
1483
sub AddIssue {
1479
sub AddIssue {
1484
    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode, $params ) = @_;
1480
    my ( $patron, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode, $params ) = @_;
1485
1481
1486
    my $onsite_checkout = $params && $params->{onsite_checkout} ? 1 : 0;
1482
    my $onsite_checkout = $params && $params->{onsite_checkout} ? 1 : 0;
1487
    my $switch_onsite_checkout = $params && $params->{switch_onsite_checkout};
1483
    my $switch_onsite_checkout = $params && $params->{switch_onsite_checkout};
Lines 1509-1530 sub AddIssue { Link Here
1509
    }
1505
    }
1510
1506
1511
    # Stop here if the patron or barcode doesn't exist
1507
    # Stop here if the patron or barcode doesn't exist
1512
    if ( $borrower && $barcode && $barcodecheck ) {
1508
    if ( $patron && $barcode && $barcodecheck ) {
1513
        # find which item we issue
1509
        # find which item we issue
1514
        my $item_object = Koha::Items->find({ barcode => $barcode })
1510
        my $item_object = Koha::Items->find({ barcode => $barcode })
1515
          or return;    # if we don't get an Item, abort.
1511
          or return;    # if we don't get an Item, abort.
1516
        my $item_unblessed = $item_object->unblessed;
1512
        my $item_unblessed = $item_object->unblessed;
1517
1513
1518
        my $branchcode = _GetCircControlBranch( $item_unblessed, $borrower );
1514
        my $branchcode = _GetCircControlBranch( $item_object, $patron );
1519
1515
1520
        # get actual issuing if there is one
1516
        # get actual issuing if there is one
1521
        my $actualissue = $item_object->checkout;
1517
        my $actualissue = $item_object->checkout;
1522
1518
1523
        # check if we just renew the issue.
1519
        # check if we just renew the issue.
1524
        if ( $actualissue and $actualissue->borrowernumber eq $borrower->{'borrowernumber'}
1520
        if ( $actualissue and $actualissue->borrowernumber eq $patron->borrowernumber
1525
                and not $switch_onsite_checkout ) {
1521
                and not $switch_onsite_checkout ) {
1526
            $datedue = AddRenewal(
1522
            $datedue = AddRenewal(
1527
                $borrower->{'borrowernumber'},
1523
                $patron->borrowernumber,
1528
                $item_object->itemnumber,
1524
                $item_object->itemnumber,
1529
                $branchcode,
1525
                $branchcode,
1530
                $datedue,
1526
                $datedue,
Lines 1534-1540 sub AddIssue { Link Here
1534
        else {
1530
        else {
1535
            unless ($datedue) {
1531
            unless ($datedue) {
1536
                my $itype = $item_object->effective_itemtype;
1532
                my $itype = $item_object->effective_itemtype;
1537
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1533
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $patron );
1538
1534
1539
            }
1535
            }
1540
1536
Lines 1543-1549 sub AddIssue { Link Here
1543
                # Check if there is an ILL connected with the biblio of the item we are issuing
1539
                # Check if there is an ILL connected with the biblio of the item we are issuing
1544
                my $ill_request = Koha::Illrequests->search({
1540
                my $ill_request = Koha::Illrequests->search({
1545
                    biblio_id => $item_object->biblionumber,
1541
                    biblio_id => $item_object->biblionumber,
1546
                    borrowernumber => $borrower->{'borrowernumber'},
1542
                    borrowernumber => $patron->borrowernumber,
1547
                    completed => undef,
1543
                    completed => undef,
1548
                    due_date => { '!=', undef },
1544
                    due_date => { '!=', undef },
1549
                })->next;
1545
                })->next;
Lines 1558-1564 sub AddIssue { Link Here
1558
1554
1559
            $datedue->truncate( to => 'minute' );
1555
            $datedue->truncate( to => 'minute' );
1560
1556
1561
            my $patron = Koha::Patrons->find( $borrower );
1562
            my $library = Koha::Libraries->find( $branchcode );
1557
            my $library = Koha::Libraries->find( $branchcode );
1563
            my $fees = Koha::Charges::Fees->new(
1558
            my $fees = Koha::Charges::Fees->new(
1564
                {
1559
                {
Lines 1586-1597 sub AddIssue { Link Here
1586
                        action         => $cancel_recall,
1581
                        action         => $cancel_recall,
1587
                        recall_id      => $recall_id,
1582
                        recall_id      => $recall_id,
1588
                        item           => $item_object,
1583
                        item           => $item_object,
1589
                        borrowernumber => $borrower->{borrowernumber},
1584
                        borrowernumber => $patron->borrowernumber,
1590
                    }
1585
                    }
1591
                );
1586
                );
1592
            }
1587
            }
1593
1588
1594
            C4::Reserves::MoveReserve( $item_object->itemnumber, $borrower->{'borrowernumber'}, $cancelreserve );
1589
            C4::Reserves::MoveReserve( $item_object->itemnumber, $patron->borrowernumber, $cancelreserve );
1595
1590
1596
            # Starting process for transfer job (checking transfert and validate it if we have one)
1591
            # Starting process for transfer job (checking transfert and validate it if we have one)
1597
            if ( my $transfer = $item_object->get_transfer ) {
1592
            if ( my $transfer = $item_object->get_transfer ) {
Lines 1616-1622 sub AddIssue { Link Here
1616
            unless ($auto_renew) {
1611
            unless ($auto_renew) {
1617
                my $rule = Koha::CirculationRules->get_effective_rule_value(
1612
                my $rule = Koha::CirculationRules->get_effective_rule_value(
1618
                    {
1613
                    {
1619
                        categorycode => $borrower->{categorycode},
1614
                        categorycode => $patron->categorycode,
1620
                        itemtype     => $item_object->effective_itemtype,
1615
                        itemtype     => $item_object->effective_itemtype,
1621
                        branchcode   => $branchcode,
1616
                        branchcode   => $branchcode,
1622
                        rule_name    => 'auto_renew'
1617
                        rule_name    => 'auto_renew'
Lines 1627-1633 sub AddIssue { Link Here
1627
            }
1622
            }
1628
1623
1629
            my $issue_attributes = {
1624
            my $issue_attributes = {
1630
                borrowernumber  => $borrower->{'borrowernumber'},
1625
                borrowernumber  => $patron->borrowernumber,
1631
                issuedate       => $issuedate,
1626
                issuedate       => $issuedate,
1632
                date_due        => $datedue,
1627
                date_due        => $datedue,
1633
                branchcode      => C4::Context->userenv->{'branch'},
1628
                branchcode      => C4::Context->userenv->{'branch'},
Lines 1661-1667 sub AddIssue { Link Here
1661
                )->store;
1656
                )->store;
1662
            }
1657
            }
1663
            $issue->discard_changes;
1658
            $issue->discard_changes;
1664
            C4::Auth::track_login_daily( $borrower->{userid} );
1659
            C4::Auth::track_login_daily( $patron->userid );
1665
            if ( $item_object->location && $item_object->location eq 'CART'
1660
            if ( $item_object->location && $item_object->location eq 'CART'
1666
                && ( !$item_object->permanent_location || $item_object->permanent_location ne 'CART' ) ) {
1661
                && ( !$item_object->permanent_location || $item_object->permanent_location ne 'CART' ) ) {
1667
            ## Item was moved to cart via UpdateItemLocationOnCheckin, anything issued should be taken off the cart.
1662
            ## Item was moved to cart via UpdateItemLocationOnCheckin, anything issued should be taken off the cart.
Lines 1687-1717 sub AddIssue { Link Here
1687
            if ($was_lost) {
1682
            if ($was_lost) {
1688
                if ( $item_object->{_charge} ) {
1683
                if ( $item_object->{_charge} ) {
1689
                    $actualissue //= Koha::Old::Checkouts->search(
1684
                    $actualissue //= Koha::Old::Checkouts->search(
1690
                        { itemnumber => $item_unblessed->{itemnumber} },
1685
                        { itemnumber => $item_object->itemnumber },
1691
                        {
1686
                        {
1692
                            order_by => { '-desc' => 'returndate' },
1687
                            order_by => { '-desc' => 'returndate' },
1693
                            rows     => 1
1688
                            rows     => 1
1694
                        }
1689
                        }
1695
                    )->single;
1690
                    )->single;
1696
                    unless ( exists( $borrower->{branchcode} ) ) {
1691
                    unless ( $patron->branchcode ) {
1697
                        my $patron = $actualissue->patron;
1692
                        $patron = $actualissue->patron;
1698
                        $borrower = $patron->unblessed;
1699
                    }
1693
                    }
1700
                    _CalculateAndUpdateFine(
1694
                    _CalculateAndUpdateFine(
1701
                        {
1695
                        {
1702
                            issue       => $actualissue,
1696
                            issue       => $actualissue,
1703
                            item        => $item_unblessed,
1697
                            item        => $item_unblessed,
1704
                            borrower    => $borrower,
1698
                            borrower    => $patron->unblessed,
1705
                            return_date => $issuedate
1699
                            return_date => $issuedate
1706
                        }
1700
                        }
1707
                    );
1701
                    );
1708
                    _FixOverduesOnReturn( $borrower->{borrowernumber},
1702
                    _FixOverduesOnReturn( $patron->borrowernumber,
1709
                        $item_object->itemnumber, undef, 'RENEWED' );
1703
                        $item_object->itemnumber, undef, 'RENEWED' );
1710
                }
1704
                }
1711
            }
1705
            }
1712
1706
1713
            # If it costs to borrow this book, charge it to the patron's account.
1707
            # If it costs to borrow this book, charge it to the patron's account.
1714
            my ( $charge, $itemtype ) = GetIssuingCharges( $item_object->itemnumber, $borrower->{'borrowernumber'} );
1708
            my ( $charge, $itemtype ) = GetIssuingCharges( $item_object->itemnumber, $patron->borrowernumber );
1715
            if ( $charge && $charge > 0 ) {
1709
            if ( $charge && $charge > 0 ) {
1716
                AddIssuingCharge( $issue, $charge, 'RENT' );
1710
                AddIssuingCharge( $issue, $charge, 'RENT' );
1717
            }
1711
            }
Lines 1736-1742 sub AddIssue { Link Here
1736
                    itemnumber     => $item_object->itemnumber,
1730
                    itemnumber     => $item_object->itemnumber,
1737
                    itemtype       => $item_object->effective_itemtype,
1731
                    itemtype       => $item_object->effective_itemtype,
1738
                    location       => $item_object->location,
1732
                    location       => $item_object->location,
1739
                    borrowernumber => $borrower->{'borrowernumber'},
1733
                    borrowernumber => $patron->borrowernumber,
1740
                    ccode          => $item_object->ccode,
1734
                    ccode          => $item_object->ccode,
1741
                }
1735
                }
1742
            );
1736
            );
Lines 1745-1751 sub AddIssue { Link Here
1745
            my $circulation_alert = 'C4::ItemCirculationAlertPreference';
1739
            my $circulation_alert = 'C4::ItemCirculationAlertPreference';
1746
            my %conditions        = (
1740
            my %conditions        = (
1747
                branchcode   => $branchcode,
1741
                branchcode   => $branchcode,
1748
                categorycode => $borrower->{categorycode},
1742
                categorycode => $patron->categorycode,
1749
                item_type    => $item_object->effective_itemtype,
1743
                item_type    => $item_object->effective_itemtype,
1750
                notification => 'CHECKOUT',
1744
                notification => 'CHECKOUT',
1751
            );
1745
            );
Lines 1754-1767 sub AddIssue { Link Here
1754
                    {
1748
                    {
1755
                        type     => 'CHECKOUT',
1749
                        type     => 'CHECKOUT',
1756
                        item     => $item_object->unblessed,
1750
                        item     => $item_object->unblessed,
1757
                        borrower => $borrower,
1751
                        borrower => $patron->unblessed,
1758
                        branch   => $branchcode,
1752
                        branch   => $branchcode,
1759
                    }
1753
                    }
1760
                );
1754
                );
1761
            }
1755
            }
1762
            logaction(
1756
            logaction(
1763
                "CIRCULATION", "ISSUE",
1757
                "CIRCULATION", "ISSUE",
1764
                $borrower->{'borrowernumber'},
1758
                $patron->borrowernumber,
1765
                $item_object->itemnumber,
1759
                $item_object->itemnumber,
1766
            ) if C4::Context->preference("IssueLog");
1760
            ) if C4::Context->preference("IssueLog");
1767
1761
Lines 2564-2573 to ease testing. Link Here
2564
sub _calculate_new_debar_dt {
2558
sub _calculate_new_debar_dt {
2565
    my ( $borrower, $item, $dt_due, $return_date ) = @_;
2559
    my ( $borrower, $item, $dt_due, $return_date ) = @_;
2566
2560
2567
    my $branchcode = _GetCircControlBranch( $item, $borrower );
2561
    my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
2562
    $item = Koha::Items->find( $item->{itemnumber} );
2563
2564
    my $branchcode = _GetCircControlBranch( $item, $patron );
2568
    my $circcontrol = C4::Context->preference('CircControl');
2565
    my $circcontrol = C4::Context->preference('CircControl');
2569
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2566
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2570
        {   categorycode => $borrower->{categorycode},
2567
        {   categorycode => $patron->categorycode,
2571
            itemtype     => $item->{itype},
2568
            itemtype     => $item->{itype},
2572
            branchcode   => $branchcode,
2569
            branchcode   => $branchcode,
2573
            rules => [
2570
            rules => [
Lines 2617-2624 sub _calculate_new_debar_dt { Link Here
2617
        }
2614
        }
2618
2615
2619
        my ( $has_been_extended );
2616
        my ( $has_been_extended );
2620
        if ( C4::Context->preference('CumulativeRestrictionPeriods') and $borrower->{debarred} ) {
2617
        if ( C4::Context->preference('CumulativeRestrictionPeriods') and $patron->is_debarred ) {
2621
            my $debarment = @{ GetDebarments( { borrowernumber => $borrower->{borrowernumber}, type => 'SUSPENSION' } ) }[0];
2618
            my $debarment = @{ GetDebarments( { borrowernumber => $patron->borrowernumber, type => 'SUSPENSION' } ) }[0];
2622
            if ( $debarment ) {
2619
            if ( $debarment ) {
2623
                $return_date = dt_from_string( $debarment->{expiration}, 'sql' );
2620
                $return_date = dt_from_string( $debarment->{expiration}, 'sql' );
2624
                $has_been_extended = 1;
2621
                $has_been_extended = 1;
Lines 2752-2768 sub _FixOverduesOnReturn { Link Here
2752
2749
2753
=head2 _GetCircControlBranch
2750
=head2 _GetCircControlBranch
2754
2751
2755
   my $circ_control_branch = _GetCircControlBranch($iteminfos, $borrower);
2752
   my $circ_control_branch = _GetCircControlBranch($item, $patron);
2756
2753
2757
Internal function : 
2754
Internal function :
2758
2755
2759
Return the library code to be used to determine which circulation
2756
Return the library code to be used to determine which circulation
2760
policy applies to a transaction.  Looks up the CircControl and
2757
policy applies to a transaction.  Looks up the CircControl and
2761
HomeOrHoldingBranch system preferences.
2758
HomeOrHoldingBranch system preferences.
2762
2759
2763
C<$iteminfos> is a hashref to iteminfo. Only {homebranch or holdingbranch} is used.
2760
C<$item> is an item object.
2764
2761
2765
C<$borrower> is a hashref to borrower. Only {branchcode} is used.
2762
C<$patron> is a patron object.
2766
2763
2767
=cut
2764
=cut
2768
2765
Lines 2772-2787 sub _GetCircControlBranch { Link Here
2772
    my $branch;
2769
    my $branch;
2773
2770
2774
    if ($circcontrol eq 'PickupLibrary' and (C4::Context->userenv and C4::Context->userenv->{'branch'}) ) {
2771
    if ($circcontrol eq 'PickupLibrary' and (C4::Context->userenv and C4::Context->userenv->{'branch'}) ) {
2775
        $branch= C4::Context->userenv->{'branch'};
2772
        $branch = C4::Context->userenv->{'branch'};
2776
    } elsif ($circcontrol eq 'PatronLibrary') {
2773
    } elsif ($circcontrol eq 'PatronLibrary') {
2777
        $branch=$borrower->{branchcode};
2774
        $branch = $borrower->branchcode;
2778
    } else {
2775
    } else {
2779
        my $branchfield = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch';
2776
        my $branchfield = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch';
2780
        $branch = $item->{$branchfield};
2777
        $branch = $item->get_column($branchfield);
2781
        # default to item home branch if holdingbranch is used
2778
        # default to item home branch if holdingbranch is used
2782
        # and is not defined
2779
        # and is not defined
2783
        if (!defined($branch) && $branchfield eq 'holdingbranch') {
2780
        if (!defined($branch) && $branchfield eq 'holdingbranch') {
2784
            $branch = $item->{homebranch};
2781
            $branch = $item->homebranch;
2785
        }
2782
        }
2786
    }
2783
    }
2787
    return $branch;
2784
    return $branch;
Lines 2857-2863 sub CanBookBeRenewed { Link Here
2857
2854
2858
       # override_limit will override anything else except on_reserve
2855
       # override_limit will override anything else except on_reserve
2859
    unless ( $override_limit ){
2856
    unless ( $override_limit ){
2860
        my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
2857
        my $branchcode = _GetCircControlBranch( $item, $patron );
2861
        my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2858
        my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2862
            {
2859
            {
2863
                categorycode => $patron->categorycode,
2860
                categorycode => $patron->categorycode,
Lines 3047-3053 sub AddRenewal { Link Here
3047
    my $patron = Koha::Patrons->find( $borrowernumber ) or return; # FIXME Should do more than just return
3044
    my $patron = Koha::Patrons->find( $borrowernumber ) or return; # FIXME Should do more than just return
3048
    my $patron_unblessed = $patron->unblessed;
3045
    my $patron_unblessed = $patron->unblessed;
3049
3046
3050
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_unblessed, $patron_unblessed) );
3047
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_object, $patron) );
3051
3048
3052
    my $schema = Koha::Database->schema;
3049
    my $schema = Koha::Database->schema;
3053
    $schema->txn_do(sub{
3050
    $schema->txn_do(sub{
Lines 3066-3072 sub AddRenewal { Link Here
3066
            $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
3063
            $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
3067
                                            dt_from_string( $issue->date_due, 'sql' ) :
3064
                                            dt_from_string( $issue->date_due, 'sql' ) :
3068
                                            dt_from_string();
3065
                                            dt_from_string();
3069
            $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, 'is a renewal');
3066
            $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron, 'is a renewal');
3070
        }
3067
        }
3071
3068
3072
        my $fees = Koha::Charges::Fees->new(
3069
        my $fees = Koha::Charges::Fees->new(
Lines 3234-3240 sub GetRenewCount { Link Here
3234
    $renewcount = $data->{'renewals_count'} if $data->{'renewals_count'};
3231
    $renewcount = $data->{'renewals_count'} if $data->{'renewals_count'};
3235
    $unseencount = $data->{'unseen_renewals'} if $data->{'unseen_renewals'};
3232
    $unseencount = $data->{'unseen_renewals'} if $data->{'unseen_renewals'};
3236
    # $item and $borrower should be calculated
3233
    # $item and $borrower should be calculated
3237
    my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed);
3234
    my $branchcode = _GetCircControlBranch($item, $patron);
3238
3235
3239
    my $rules = Koha::CirculationRules->get_effective_rules(
3236
    my $rules = Koha::CirculationRules->get_effective_rules(
3240
        {
3237
        {
Lines 3290-3296 sub GetSoonestRenewDate { Link Here
3290
3287
3291
    my $dbh = C4::Context->dbh;
3288
    my $dbh = C4::Context->dbh;
3292
3289
3293
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
3290
    my $branchcode = _GetCircControlBranch( $item, $patron );
3294
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
3291
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
3295
        {   categorycode => $patron->categorycode,
3292
        {   categorycode => $patron->categorycode,
3296
            itemtype     => $item->effective_itemtype,
3293
            itemtype     => $item->effective_itemtype,
Lines 3357-3364 sub GetLatestAutoRenewDate { Link Here
3357
    return unless $item;
3354
    return unless $item;
3358
3355
3359
    my $dbh = C4::Context->dbh;
3356
    my $dbh = C4::Context->dbh;
3360
3361
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
3357
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
3358
3362
    my $circulation_rules = Koha::CirculationRules->get_effective_rules(
3359
    my $circulation_rules = Koha::CirculationRules->get_effective_rules(
3363
        {
3360
        {
3364
            categorycode => $patron->categorycode,
3361
            categorycode => $patron->categorycode,
Lines 3654-3672 checking against the holidays calendar as per the daysmode circulation rule. Link Here
3654
C<$startdate>   = DateTime object representing start date of loan period (assumed to be today)
3651
C<$startdate>   = DateTime object representing start date of loan period (assumed to be today)
3655
C<$itemtype>  = itemtype code of item in question
3652
C<$itemtype>  = itemtype code of item in question
3656
C<$branch>  = location whose calendar to use
3653
C<$branch>  = location whose calendar to use
3657
C<$borrower> = Borrower object
3654
C<$patron> = Patron object
3658
C<$isrenewal> = Boolean: is true if we want to calculate the date due for a renewal. Else is false.
3655
C<$isrenewal> = Boolean: is true if we want to calculate the date due for a renewal. Else is false.
3659
3656
3660
=cut
3657
=cut
3661
3658
3662
sub CalcDateDue {
3659
sub CalcDateDue {
3663
    my ( $startdate, $itemtype, $branch, $borrower, $isrenewal ) = @_;
3660
    my ( $startdate, $itemtype, $branch, $patron, $isrenewal ) = @_;
3664
3661
3665
    $isrenewal ||= 0;
3662
    $isrenewal ||= 0;
3666
3663
3667
    # loanlength now a href
3664
    # loanlength now a href
3668
    my $loanlength =
3665
    my $loanlength =
3669
            GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch );
3666
            GetLoanLength( $patron->categorycode, $itemtype, $branch );
3670
3667
3671
    my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} and $loanlength->{renewalperiod} ne q{} )
3668
    my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} and $loanlength->{renewalperiod} ne q{} )
3672
            ? qq{renewalperiod}
3669
            ? qq{renewalperiod}
Lines 3686-3692 sub CalcDateDue { Link Here
3686
3683
3687
    my $daysmode = Koha::CirculationRules->get_effective_daysmode(
3684
    my $daysmode = Koha::CirculationRules->get_effective_daysmode(
3688
        {
3685
        {
3689
            categorycode => $borrower->{categorycode},
3686
            categorycode => $patron->categorycode,
3690
            itemtype     => $itemtype,
3687
            itemtype     => $itemtype,
3691
            branchcode   => $branch,
3688
            branchcode   => $branch,
3692
        }
3689
        }
Lines 3720-3726 sub CalcDateDue { Link Here
3720
3717
3721
    # if Hard Due Dates are used, retrieve them and apply as necessary
3718
    # if Hard Due Dates are used, retrieve them and apply as necessary
3722
    my ( $hardduedate, $hardduedatecompare ) =
3719
    my ( $hardduedate, $hardduedatecompare ) =
3723
      GetHardDueDate( $borrower->{'categorycode'}, $itemtype, $branch );
3720
      GetHardDueDate( $patron->categorycode, $itemtype, $branch );
3724
    if ($hardduedate) {    # hardduedates are currently dates
3721
    if ($hardduedate) {    # hardduedates are currently dates
3725
        $hardduedate->truncate( to => 'minute' );
3722
        $hardduedate->truncate( to => 'minute' );
3726
        $hardduedate->set_hour(23);
3723
        $hardduedate->set_hour(23);
Lines 3740-3746 sub CalcDateDue { Link Here
3740
3737
3741
    # if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate
3738
    # if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate
3742
    if ( C4::Context->preference('ReturnBeforeExpiry') ) {
3739
    if ( C4::Context->preference('ReturnBeforeExpiry') ) {
3743
        my $expiry_dt = dt_from_string( $borrower->{dateexpiry}, 'iso', 'floating');
3740
        my $expiry_dt = dt_from_string( $patron->dateexpiry, 'iso', 'floating');
3744
        if( $expiry_dt ) { #skip empty expiry date..
3741
        if( $expiry_dt ) { #skip empty expiry date..
3745
            $expiry_dt->set( hour => 23, minute => 59);
3742
            $expiry_dt->set( hour => 23, minute => 59);
3746
            my $d1= $datedue->clone->set_time_zone('floating');
3743
            my $d1= $datedue->clone->set_time_zone('floating');
Lines 4024-4030 sub ProcessOfflineIssue { Link Here
4024
            );
4021
            );
4025
        }
4022
        }
4026
        AddIssue(
4023
        AddIssue(
4027
            $patron->unblessed,
4024
            $patron,
4028
            $operation->{'barcode'},
4025
            $operation->{'barcode'},
4029
            undef,
4026
            undef,
4030
            undef,
4027
            undef,
(-)a/C4/SIP/ILS/Transaction/Checkout.pm (-1 / +1 lines)
Lines 141-147 sub do_checkout { Link Here
141
        });
141
        });
142
    } else {
142
    } else {
143
        # can issue
143
        # can issue
144
        my $issue = AddIssue( $patron->unblessed, $barcode, $overridden_duedate, 0 );
144
        my $issue = AddIssue( $patron, $barcode, $overridden_duedate, 0 );
145
        $self->{due} = $self->duedatefromissue($issue, $itemnumber);
145
        $self->{due} = $self->duedatefromissue($issue, $itemnumber);
146
    }
146
    }
147
147
(-)a/C4/SIP/ILS/Transaction/Renew.pm (-1 / +1 lines)
Lines 46-52 sub do_renew_for { Link Here
46
46
47
    }
47
    }
48
    if ($renewokay){
48
    if ($renewokay){
49
        my $issue = AddIssue( $borrower, $self->{item}->id, undef, 0 );
49
        my $issue = AddIssue( $patron, $self->{item}->id, undef, 0 );
50
        $self->{due} = $self->duedatefromissue($issue, $self->{item}->{itemnumber});
50
        $self->{due} = $self->duedatefromissue($issue, $self->{item}->{itemnumber});
51
        $self->renewal_ok(1);
51
        $self->renewal_ok(1);
52
    } else {
52
    } else {
(-)a/Koha/CurbsidePickup.pm (-1 / +1 lines)
Lines 250-256 sub mark_as_delivered { Link Here
250
250
251
            unless ( keys %$issuingimpossible ) {
251
            unless ( keys %$issuingimpossible ) {
252
                my $issue =
252
                my $issue =
253
                  C4::Circulation::AddIssue( $patron->unblessed, $hold->item->barcode );
253
                  C4::Circulation::AddIssue( $patron, $hold->item->barcode );
254
                if ($issue) {
254
                if ($issue) {
255
                    Koha::CurbsidePickupIssue->new(
255
                    Koha::CurbsidePickupIssue->new(
256
                        {
256
                        {
(-)a/Koha/Illrequest.pm (-2 lines)
Lines 1270-1277 sub check_out { Link Here
1270
        }
1270
        }
1271
1271
1272
        # We can allegedly check out, so make it so
1272
        # We can allegedly check out, so make it so
1273
        # For some reason, AddIssue requires an unblessed Patron
1274
        $issue_args[0] = $patron->unblessed;
1275
        my $issue = C4::Circulation::AddIssue(@issue_args);
1273
        my $issue = C4::Circulation::AddIssue(@issue_args);
1276
1274
1277
        if ($issue) {
1275
        if ($issue) {
(-)a/Koha/Item.pm (-1 / +1 lines)
Lines 1764-1770 sub can_be_recalled { Link Here
1764
1764
1765
    my $branchcode = C4::Context->userenv->{'branch'};
1765
    my $branchcode = C4::Context->userenv->{'branch'};
1766
    if ( $patron ) {
1766
    if ( $patron ) {
1767
        $branchcode = C4::Circulation::_GetCircControlBranch( $self->unblessed, $patron->unblessed );
1767
        $branchcode = C4::Circulation::_GetCircControlBranch( $self, $patron );
1768
    }
1768
    }
1769
1769
1770
    # Check the circulation rule for each relevant itemtype for this item
1770
    # Check the circulation rule for each relevant itemtype for this item
(-)a/Koha/Recall.pm (-1 / +1 lines)
Lines 258-264 sub calc_expirationdate { Link Here
258
258
259
    my $branchcode = $self->patron->branchcode;
259
    my $branchcode = $self->patron->branchcode;
260
    if ( $item ) {
260
    if ( $item ) {
261
        $branchcode = C4::Circulation::_GetCircControlBranch( $item->unblessed, $self->patron->unblessed );
261
        $branchcode = C4::Circulation::_GetCircControlBranch( $item, $self->patron );
262
    }
262
    }
263
263
264
    my $rule = Koha::CirculationRules->get_effective_rule({
264
    my $rule = Koha::CirculationRules->get_effective_rule({
(-)a/circ/circulation.pl (-1 / +1 lines)
Lines 400-406 if (@$barcodes) { Link Here
400
                );
400
                );
401
                $recall_id = ( $recall and $recall->id ) ? $recall->id : undef;
401
                $recall_id = ( $recall and $recall->id ) ? $recall->id : undef;
402
            }
402
            }
403
            my $issue = AddIssue( $patron->unblessed, $barcode, $datedue, $cancelreserve, undef, undef, { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew'), switch_onsite_checkout => $switch_onsite_checkout, cancel_recall => $cancel_recall, recall_id => $recall_id, } );
403
            my $issue = AddIssue( $patron, $barcode, $datedue, $cancelreserve, undef, undef, { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew'), switch_onsite_checkout => $switch_onsite_checkout, cancel_recall => $cancel_recall, recall_id => $recall_id, } );
404
            $template_params->{issue} = $issue;
404
            $template_params->{issue} = $issue;
405
            $session->clear('auto_renew');
405
            $session->clear('auto_renew');
406
            $inprocess = 1;
406
            $inprocess = 1;
(-)a/offline_circ/process_koc.pl (-19 / +18 lines)
Lines 246-252 sub kocIssueItem { Link Here
246
246
247
    my $branchcode = C4::Context->userenv->{branch};
247
    my $branchcode = C4::Context->userenv->{branch};
248
    my $patron = Koha::Patrons->find( { cardnumber => $circ->{cardnumber} } );
248
    my $patron = Koha::Patrons->find( { cardnumber => $circ->{cardnumber} } );
249
    my $borrower = $patron->unblessed;
250
    my $item = Koha::Items->find({ barcode => $circ->{barcode} });
249
    my $item = Koha::Items->find({ barcode => $circ->{barcode} });
251
    my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
250
    my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
252
    my $biblio = $item->biblio;
251
    my $biblio = $item->biblio;
Lines 254-260 sub kocIssueItem { Link Here
254
    if ( $issue ) { ## Item is currently checked out to another person.
253
    if ( $issue ) { ## Item is currently checked out to another person.
255
        #warn "Item Currently Issued.";
254
        #warn "Item Currently Issued.";
256
255
257
        if ( $issue->borrowernumber eq $borrower->{'borrowernumber'} ) { ## Issued to this person already, renew it.
256
        if ( $issue->borrowernumber eq $patron->borrowernumber ) { ## Issued to this person already, renew it.
258
            #warn "Item issued to this member already, renewing.";
257
            #warn "Item issued to this member already, renewing.";
259
258
260
            C4::Circulation::AddRenewal(
259
            C4::Circulation::AddRenewal(
Lines 270-280 sub kocIssueItem { Link Here
270
                title => $biblio->title,
269
                title => $biblio->title,
271
                biblionumber => $biblio->biblionumber,
270
                biblionumber => $biblio->biblionumber,
272
                barcode => $item->barcode,
271
                barcode => $item->barcode,
273
                firstname => $borrower->{ 'firstname' },
272
                firstname => $patron->firstname,
274
                surname => $borrower->{ 'surname' },
273
                surname => $patron->surname,
275
                borrowernumber => $borrower->{'borrowernumber'},
274
                borrowernumber => $patron->borrowernumber,
276
                cardnumber => $borrower->{'cardnumber'},
275
                cardnumber => $patron->cardnumber,
277
                datetime => $circ->{ 'datetime' }
276
                datetime => $circ->datetime
278
            };
277
            };
279
278
280
        } else {
279
        } else {
Lines 285-301 sub kocIssueItem { Link Here
285
            my ( $c_y, $c_m, $c_d ) = split( /-/, $circ->{'date'} );
284
            my ( $c_y, $c_m, $c_d ) = split( /-/, $circ->{'date'} );
286
285
287
            if ( Date_to_Days( $i_y, $i_m, $i_d ) < Date_to_Days( $c_y, $c_m, $c_d ) ) { ## Current issue to a different persion is older than this issue, return and issue.
286
            if ( Date_to_Days( $i_y, $i_m, $i_d ) < Date_to_Days( $c_y, $c_m, $c_d ) ) { ## Current issue to a different persion is older than this issue, return and issue.
288
                C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
287
                C4::Circulation::AddIssue( $patron, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
289
                push @output, {
288
                push @output, {
290
                    issue => 1,
289
                    issue => 1,
291
                    title => $biblio->title,
290
                    title => $biblio->title,
292
                    biblionumber => $biblio->biblionumber,
291
                    biblionumber => $biblio->biblionumber,
293
                    barcode => $item->barcode,
292
                    barcode => $item->barcode,
294
                    firstname => $borrower->{ 'firstname' },
293
                    firstname => $patron->firstname,
295
                    surname => $borrower->{ 'surname' },
294
                    surname => $patron->surname,
296
                    borrowernumber => $borrower->{'borrowernumber'},
295
                    borrowernumber => $patron->borrowernumber,
297
                    cardnumber => $borrower->{'cardnumber'},
296
                    cardnumber => $patron->cardnumber,
298
                    datetime => $circ->{ 'datetime' }
297
                    datetime => $circ->datetime
299
                };
298
                };
300
299
301
            } else { ## Current issue is *newer* than this issue, write a 'returned' issue, as the item is most likely in the hands of someone else now.
300
            } else { ## Current issue is *newer* than this issue, write a 'returned' issue, as the item is most likely in the hands of someone else now.
Lines 305-321 sub kocIssueItem { Link Here
305
            }
304
            }
306
        }
305
        }
307
    } else { ## Item is not checked out to anyone at the moment, go ahead and issue it
306
    } else { ## Item is not checked out to anyone at the moment, go ahead and issue it
308
        C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
307
        C4::Circulation::AddIssue( $patron, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
309
        push @output, {
308
        push @output, {
310
            issue => 1,
309
            issue => 1,
311
            title => $biblio->title,
310
            title => $biblio->title,
312
            biblionumber => $biblio->biblionumber,
311
            biblionumber => $biblio->biblionumber,
313
            barcode => $item->barcode,
312
            barcode => $item->barcode,
314
            firstname => $borrower->{ 'firstname' },
313
            firstname => $patron->firstname,
315
            surname => $borrower->{ 'surname' },
314
            surname => $patron->surname,
316
            borrowernumber => $borrower->{'borrowernumber'},
315
            borrowernumber => $patron->borrowernumber,
317
            cardnumber => $borrower->{'cardnumber'},
316
            cardnumber => $patron->cardnumber,
318
            datetime =>$circ->{ 'datetime' }
317
            datetime =>$circ->datetime
319
        };
318
        };
320
    }
319
    }
321
}
320
}
(-)a/opac/sco/sco-main.pl (-1 / +1 lines)
Lines 245-251 elsif ( $patron && ( $op eq 'checkout' ) ) { Link Here
245
                )->count;
245
                )->count;
246
            }
246
            }
247
247
248
            AddIssue( $patron->unblessed, $barcode );
248
            AddIssue( $patron, $barcode );
249
            $template->param( issued => 1 );
249
            $template->param( issued => 1 );
250
            push @newissueslist, $barcode;
250
            push @newissueslist, $barcode;
251
251
(-)a/reserve/request.pl (-2 / +1 lines)
Lines 475-482 if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold ) Link Here
475
                }
475
                }
476
476
477
                if ( $patron ) {
477
                if ( $patron ) {
478
                    my $patron_unblessed = $patron->unblessed;
478
                    my $branch = _GetCircControlBranch($item_object, $patron);
479
                    my $branch = C4::Circulation::_GetCircControlBranch($item, $patron_unblessed);
480
479
481
                    my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
480
                    my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
482
481
(-)a/svc/letters/preview (-5 / +2 lines)
Lines 151-159 if ( $code eq 'CHECKIN' ) { Link Here
151
    my $checkout = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
151
    my $checkout = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
152
    if ($checkout) {
152
    if ($checkout) {
153
        my $patron = Koha::Patrons->find( $checkout->borrowernumber );
153
        my $patron = Koha::Patrons->find( $checkout->borrowernumber );
154
        my $branchcode =
154
        my $branchcode = C4::Circulation::_GetCircControlBranch( $item, $patron );
155
          C4::Circulation::_GetCircControlBranch( $item->unblessed,
156
            $patron->unblessed );
157
        $letter_params = {
155
        $letter_params = {
158
            tables => {
156
            tables => {
159
                issues      => $item->itemnumber,
157
                issues      => $item->itemnumber,
Lines 177-184 elsif ( $code eq 'CHECKOUT' ) { Link Here
177
    my $patron = Koha::Patrons->find( $borrowernumber );
175
    my $patron = Koha::Patrons->find( $borrowernumber );
178
    if ($item and $patron) {
176
    if ($item and $patron) {
179
        my $branchcode =
177
        my $branchcode =
180
          C4::Circulation::_GetCircControlBranch( $item->unblessed,
178
          C4::Circulation::_GetCircControlBranch( $item, $patron );
181
            $patron->unblessed );
182
        $letter_params = {
179
        $letter_params = {
183
            tables => {
180
            tables => {
184
                issues      => $item->itemnumber,
181
                issues      => $item->itemnumber,
(-)a/t/db_dependent/Circulation.t (-71 / +84 lines)
Lines 164-177 my $patron_category = $builder->build( Link Here
164
my $CircControl = C4::Context->preference('CircControl');
164
my $CircControl = C4::Context->preference('CircControl');
165
my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch');
165
my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch');
166
166
167
my $item = {
167
my $item = $builder->build_object({
168
    homebranch => $library2->{branchcode},
168
    class => 'Koha::Items',
169
    holdingbranch => $library2->{branchcode}
169
    value => {
170
};
170
        homebranch => $library2->{branchcode},
171
        holdingbranch => $library2->{branchcode}
172
    }
173
});
171
174
172
my $borrower = {
175
my $borrower = $builder->build_object({
173
    branchcode => $library2->{branchcode}
176
    class => 'Koha::Patrons',
174
};
177
    value => { branchcode => $library2->{branchcode} }
178
});
175
179
176
t::lib::Mocks::mock_preference('AutoReturnCheckedOutItems', 0);
180
t::lib::Mocks::mock_preference('AutoReturnCheckedOutItems', 0);
177
181
Lines 185-191 is( Link Here
185
);
189
);
186
is(
190
is(
187
    C4::Circulation::_GetCircControlBranch($item, $borrower),
191
    C4::Circulation::_GetCircControlBranch($item, $borrower),
188
    $item->{$HomeOrHoldingBranch},
192
    $item->get_column($HomeOrHoldingBranch),
189
    '_GetCircControlBranch returned item branch (no userenv defined)'
193
    '_GetCircControlBranch returned item branch (no userenv defined)'
190
);
194
);
191
195
Lines 198-204 is( Link Here
198
);
202
);
199
is(
203
is(
200
    C4::Circulation::_GetCircControlBranch($item, $borrower),
204
    C4::Circulation::_GetCircControlBranch($item, $borrower),
201
    $borrower->{branchcode},
205
    $borrower->branchcode,
202
    '_GetCircControlBranch returned borrower branch'
206
    '_GetCircControlBranch returned borrower branch'
203
);
207
);
204
208
Lines 210-216 is( Link Here
210
    'CircControl changed to ItemHomeLibrary'
214
    'CircControl changed to ItemHomeLibrary'
211
);
215
);
212
is(
216
is(
213
    $item->{$HomeOrHoldingBranch},
217
    $item->get_column($HomeOrHoldingBranch),
214
    C4::Circulation::_GetCircControlBranch($item, $borrower),
218
    C4::Circulation::_GetCircControlBranch($item, $borrower),
215
    '_GetCircControlBranch returned item branch'
219
    '_GetCircControlBranch returned item branch'
216
);
220
);
Lines 241-247 is( Link Here
241
);
245
);
242
is(
246
is(
243
    C4::Circulation::_GetCircControlBranch($item, $borrower),
247
    C4::Circulation::_GetCircControlBranch($item, $borrower),
244
    $borrower->{branchcode},
248
    $borrower->branchcode,
245
    '_GetCircControlBranch returned borrower branch'
249
    '_GetCircControlBranch returned borrower branch'
246
);
250
);
247
251
Lines 254-260 is( Link Here
254
);
258
);
255
is(
259
is(
256
    C4::Circulation::_GetCircControlBranch($item, $borrower),
260
    C4::Circulation::_GetCircControlBranch($item, $borrower),
257
    $item->{$HomeOrHoldingBranch},
261
    $item->get_column($HomeOrHoldingBranch),
258
    '_GetCircControlBranch returned item branch'
262
    '_GetCircControlBranch returned item branch'
259
);
263
);
260
264
Lines 329-335 subtest "CanBookBeRenewed AllowRenewalIfOtherItemsAvailable multiple borrowers a Link Here
329
        homebranch   => $patron_hold_1->branchcode
333
        homebranch   => $patron_hold_1->branchcode
330
    });
334
    });
331
335
332
    my $issue = AddIssue( $patron->unblessed, $item_1->barcode);
336
    my $issue = AddIssue( $patron, $item_1->barcode);
333
    my $datedue = dt_from_string( $issue->date_due() );
337
    my $datedue = dt_from_string( $issue->date_due() );
334
    is (defined $issue->date_due(), 1, "Item 1 checked out, due date: " . $issue->date_due() );
338
    is (defined $issue->date_due(), 1, "Item 1 checked out, due date: " . $issue->date_due() );
335
339
Lines 512-522 subtest "CanBookBeRenewed tests" => sub { Link Here
512
    my $checkitem      = undef;
516
    my $checkitem      = undef;
513
    my $found          = undef;
517
    my $found          = undef;
514
518
515
    my $issue_1 = AddIssue( $renewing_borrower_obj->unblessed, $item_1->barcode);
519
    my $issue_1 = AddIssue( $renewing_borrower_obj, $item_1->barcode);
516
    my $datedue = dt_from_string( $issue_1->date_due() );
520
    my $datedue = dt_from_string( $issue_1->date_due() );
517
    is (defined $issue_1->date_due(), 1, "Item 1 checked out, due date: " . $issue_1->date_due() );
521
    is (defined $issue_1->date_due(), 1, "Item 1 checked out, due date: " . $issue_1->date_due() );
518
522
519
    my $issue_2 = AddIssue( $renewing_borrower_obj->unblessed, $item_2->barcode);
523
    my $issue_2 = AddIssue( $renewing_borrower_obj, $item_2->barcode);
520
    is (defined $issue_2, 1, "Item 2 checked out, due date: " . $issue_2->date_due());
524
    is (defined $issue_2, 1, "Item 2 checked out, due date: " . $issue_2->date_due());
521
525
522
    my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $item_1->itemnumber } )->borrowernumber;
526
    my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $item_1->itemnumber } )->borrowernumber;
Lines 627-633 subtest "CanBookBeRenewed tests" => sub { Link Here
627
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
631
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
628
632
629
    my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
633
    my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
630
    my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber )->unblessed;
634
    my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber );
631
    AddIssue($reserving_borrower, $item_3->barcode);
635
    AddIssue($reserving_borrower, $item_3->barcode);
632
    my $reserve = $dbh->selectrow_hashref(
636
    my $reserve = $dbh->selectrow_hashref(
633
        'SELECT * FROM old_reserves WHERE reserve_id = ?',
637
        'SELECT * FROM old_reserves WHERE reserve_id = ?',
Lines 675-681 subtest "CanBookBeRenewed tests" => sub { Link Here
675
            itype            => $itemtype,
679
            itype            => $itemtype,
676
        }
680
        }
677
    );
681
    );
678
    my $issue_5 = AddIssue($restricted_borrower_obj->unblessed, $item_5->barcode);
682
    my $issue_5 = AddIssue($restricted_borrower_obj, $item_5->barcode);
679
    is (defined $issue_5, 1, "Item with date due checked out, due date: ". $issue_5->date_due);
683
    is (defined $issue_5, 1, "Item with date due checked out, due date: ". $issue_5->date_due);
680
684
681
    t::lib::Mocks::mock_preference('RestrictionBlockRenewing','1');
685
    t::lib::Mocks::mock_preference('RestrictionBlockRenewing','1');
Lines 704-710 subtest "CanBookBeRenewed tests" => sub { Link Here
704
        }
708
        }
705
    );
709
    );
706
710
707
    my $issue_6 = AddIssue( $renewing_borrower_obj->unblessed, $item_6->barcode);
711
    my $issue_6 = AddIssue( $renewing_borrower_obj, $item_6->barcode);
708
    is (defined $issue_6, 1, "Item 2 checked out, due date: ".$issue_6->date_due);
712
    is (defined $issue_6, 1, "Item 2 checked out, due date: ".$issue_6->date_due);
709
713
710
    my $now = dt_from_string();
714
    my $now = dt_from_string();
Lines 712-718 subtest "CanBookBeRenewed tests" => sub { Link Here
712
    my $five_weeks_ago = $now - $five_weeks;
716
    my $five_weeks_ago = $now - $five_weeks;
713
    t::lib::Mocks::mock_preference('finesMode', 'production');
717
    t::lib::Mocks::mock_preference('finesMode', 'production');
714
718
715
    my $issue_7 = AddIssue($renewing_borrower_obj->unblessed, $item_7->barcode, $five_weeks_ago);
719
    my $issue_7 = AddIssue($renewing_borrower_obj, $item_7->barcode, $five_weeks_ago);
716
    is (defined $issue_7, 1, "Item with passed date due checked out, due date: " . $issue_7->date_due);
720
    is (defined $issue_7, 1, "Item with passed date due checked out, due date: " . $issue_7->date_due);
717
721
718
    t::lib::Mocks::mock_preference('OverduesBlockRenewing','allow');
722
    t::lib::Mocks::mock_preference('OverduesBlockRenewing','allow');
Lines 793-799 subtest "CanBookBeRenewed tests" => sub { Link Here
793
    my $old_issue_log_size = Koha::ActionLogs->count( \%params_issue );
797
    my $old_issue_log_size = Koha::ActionLogs->count( \%params_issue );
794
    my $old_renew_log_size = Koha::ActionLogs->count( \%params_renewal );
798
    my $old_renew_log_size = Koha::ActionLogs->count( \%params_renewal );
795
    AddIssue(
799
    AddIssue(
796
        $renewing_borrower_obj->unblessed,
800
        $renewing_borrower_obj,
797
        $item_7->barcode,
801
        $item_7->barcode,
798
        Koha::DateUtils::output_pref({str=>$issue_6->date_due, dateformat =>'iso'}),
802
        Koha::DateUtils::output_pref({str=>$issue_6->date_due, dateformat =>'iso'}),
799
        0,
803
        0,
Lines 821-827 subtest "CanBookBeRenewed tests" => sub { Link Here
821
        }
825
        }
822
    );
826
    );
823
827
824
    my $issue_4 = AddIssue( $renewing_borrower_obj->unblessed, $item_4->barcode, undef, undef, undef, undef, { auto_renew => 1 } );
828
    my $issue_4 = AddIssue( $renewing_borrower_obj, $item_4->barcode, undef, undef, undef, undef, { auto_renew => 1 } );
825
    my $info;
829
    my $info;
826
    ( $renewokay, $error, $info ) =
830
    ( $renewokay, $error, $info ) =
827
      CanBookBeRenewed( $renewing_borrower_obj, $issue_4 );
831
      CanBookBeRenewed( $renewing_borrower_obj, $issue_4 );
Lines 951-957 subtest "CanBookBeRenewed tests" => sub { Link Here
951
955
952
        my $ten_days_before = dt_from_string->add( days => -10 );
956
        my $ten_days_before = dt_from_string->add( days => -10 );
953
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
957
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
954
        my $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
958
        my $issue = AddIssue( $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
955
959
956
        Koha::CirculationRules->set_rules(
960
        Koha::CirculationRules->set_rules(
957
            {
961
            {
Lines 1080-1086 subtest "CanBookBeRenewed tests" => sub { Link Here
1080
1084
1081
        my $ten_days_before = dt_from_string->add( days => -10 );
1085
        my $ten_days_before = dt_from_string->add( days => -10 );
1082
        my $ten_days_ahead = dt_from_string->add( days => 10 );
1086
        my $ten_days_ahead = dt_from_string->add( days => 10 );
1083
        my $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1087
        my $issue = AddIssue( $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1084
1088
1085
        Koha::CirculationRules->set_rules(
1089
        Koha::CirculationRules->set_rules(
1086
            {
1090
            {
Lines 1190-1196 subtest "CanBookBeRenewed tests" => sub { Link Here
1190
        # Patron is expired and BlockExpiredPatronOpacActions=0
1194
        # Patron is expired and BlockExpiredPatronOpacActions=0
1191
        # => auto renew is allowed
1195
        # => auto renew is allowed
1192
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 0);
1196
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 0);
1193
        my $issue = AddIssue( $expired_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1197
        my $issue = AddIssue( $expired_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1194
        ( $renewokay, $error ) =
1198
        ( $renewokay, $error ) =
1195
          CanBookBeRenewed( $expired_borrower_obj, $issue );
1199
          CanBookBeRenewed( $expired_borrower_obj, $issue );
1196
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1200
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
Lines 1201-1207 subtest "CanBookBeRenewed tests" => sub { Link Here
1201
        # Patron is expired and BlockExpiredPatronOpacActions=1
1205
        # Patron is expired and BlockExpiredPatronOpacActions=1
1202
        # => auto renew is not allowed
1206
        # => auto renew is not allowed
1203
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
1207
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
1204
        $issue = AddIssue( $expired_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1208
        $issue = AddIssue( $expired_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1205
        ( $renewokay, $error ) =
1209
        ( $renewokay, $error ) =
1206
          CanBookBeRenewed( $expired_borrower_obj, $issue );
1210
          CanBookBeRenewed( $expired_borrower_obj, $issue );
1207
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1211
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
Lines 1211-1217 subtest "CanBookBeRenewed tests" => sub { Link Here
1211
        # Patron is not expired and BlockExpiredPatronOpacActions=1
1215
        # Patron is not expired and BlockExpiredPatronOpacActions=1
1212
        # => auto renew is allowed
1216
        # => auto renew is allowed
1213
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
1217
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
1214
        $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1218
        $issue = AddIssue( $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1215
        ( $renewokay, $error ) =
1219
        ( $renewokay, $error ) =
1216
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1220
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1217
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1221
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
Lines 1230-1236 subtest "CanBookBeRenewed tests" => sub { Link Here
1230
1234
1231
        my $ten_days_before = dt_from_string->add( days => -10 );
1235
        my $ten_days_before = dt_from_string->add( days => -10 );
1232
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
1236
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
1233
        my $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1237
        my $issue = AddIssue( $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1234
        Koha::CirculationRules->set_rules(
1238
        Koha::CirculationRules->set_rules(
1235
            {
1239
            {
1236
                categorycode => undef,
1240
                categorycode => undef,
Lines 1482-1488 subtest "CanBookBeRenewed tests" => sub { Link Here
1482
    my $recall_item1 = $builder->build_sample_item({ biblionumber => $recall_biblio->biblionumber });
1486
    my $recall_item1 = $builder->build_sample_item({ biblionumber => $recall_biblio->biblionumber });
1483
    my $recall_item2 = $builder->build_sample_item({ biblionumber => $recall_biblio->biblionumber });
1487
    my $recall_item2 = $builder->build_sample_item({ biblionumber => $recall_biblio->biblionumber });
1484
1488
1485
    my $recall_issue = AddIssue( $renewing_borrower_obj->unblessed, $recall_item1->barcode );
1489
    my $recall_issue = AddIssue( $renewing_borrower_obj, $recall_item1->barcode );
1486
1490
1487
    # item-level and this item: renewal not allowed
1491
    # item-level and this item: renewal not allowed
1488
    my $recall = Koha::Recall->new({
1492
    my $recall = Koha::Recall->new({
Lines 1563-1569 subtest "GetUpcomingDueIssues" => sub { Link Here
1563
    );
1567
    );
1564
1568
1565
    my $a_borrower_borrowernumber = Koha::Patron->new(\%a_borrower_data)->store->borrowernumber;
1569
    my $a_borrower_borrowernumber = Koha::Patron->new(\%a_borrower_data)->store->borrowernumber;
1566
    my $a_borrower = Koha::Patrons->find( $a_borrower_borrowernumber )->unblessed;
1570
    my $a_borrower = Koha::Patrons->find( $a_borrower_borrowernumber );
1567
1571
1568
    my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 );
1572
    my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 );
1569
    my $two_days_ahead = DateTime->today(time_zone => C4::Context->tz())->add( days => 2 );
1573
    my $two_days_ahead = DateTime->today(time_zone => C4::Context->tz())->add( days => 2 );
Lines 1640-1646 subtest "Bug 13841 - Do not create new 0 amount fines" => sub { Link Here
1640
1644
1641
    my $borrowernumber = Koha::Patron->new(\%a_borrower_data)->store->borrowernumber;
1645
    my $borrowernumber = Koha::Patron->new(\%a_borrower_data)->store->borrowernumber;
1642
1646
1643
    my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
1647
    my $borrower = Koha::Patrons->find( $borrowernumber );
1644
    my $issue = AddIssue( $borrower, $item->barcode );
1648
    my $issue = AddIssue( $borrower, $item->barcode );
1645
    UpdateFine(
1649
    UpdateFine(
1646
        {
1650
        {
Lines 1893-1899 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1893
        branchcode => $branch,
1897
        branchcode => $branch,
1894
    })->store;
1898
    })->store;
1895
1899
1896
    my $issue = AddIssue( $borrower->unblessed, $item->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } );
1900
    my $issue = AddIssue( $borrower, $item->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } );
1897
    my ( $renewed, $error ) = CanBookBeRenewed( $borrower, $issue );
1901
    my ( $renewed, $error ) = CanBookBeRenewed( $borrower, $issue );
1898
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew on-site checkout' );
1902
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew on-site checkout' );
1899
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
1903
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
Lines 1913-1919 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1913
    );
1917
    );
1914
    my $patron = $builder->build_object( { class => 'Koha::Patrons',  value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } );
1918
    my $patron = $builder->build_object( { class => 'Koha::Patrons',  value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } );
1915
1919
1916
    my $issue = AddIssue( $patron->unblessed, $item->barcode );
1920
    my $issue = AddIssue( $patron, $item->barcode );
1917
    UpdateFine(
1921
    UpdateFine(
1918
        {
1922
        {
1919
            issue_id       => $issue->id,
1923
            issue_id       => $issue->id,
Lines 1972-1978 subtest 'CanBookBeIssued & AllowReturnToBranch' => sub { Link Here
1972
1976
1973
    set_userenv($holdingbranch);
1977
    set_userenv($holdingbranch);
1974
1978
1975
    my $issue = AddIssue( $patron_1->unblessed, $item->barcode );
1979
    my $issue = AddIssue( $patron_1, $item->barcode );
1976
    is( ref($issue), 'Koha::Checkout', 'AddIssue should return a Koha::Checkout object' );
1980
    is( ref($issue), 'Koha::Checkout', 'AddIssue should return a Koha::Checkout object' );
1977
1981
1978
    my ( $error, $question, $alerts );
1982
    my ( $error, $question, $alerts );
Lines 2047-2054 subtest 'AddIssue & AllowReturnToBranch' => sub { Link Here
2047
    my $homebranch    = $builder->build( { source => 'Branch' } );
2051
    my $homebranch    = $builder->build( { source => 'Branch' } );
2048
    my $holdingbranch = $builder->build( { source => 'Branch' } );
2052
    my $holdingbranch = $builder->build( { source => 'Branch' } );
2049
    my $otherbranch   = $builder->build( { source => 'Branch' } );
2053
    my $otherbranch   = $builder->build( { source => 'Branch' } );
2050
    my $patron_1      = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } );
2054
2051
    my $patron_2      = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } );
2055
    my $patron_1  = $builder->build_object({
2056
        class => 'Koha::Patrons',
2057
        value => { categorycode => $patron_category->{categorycode} }
2058
    });
2059
2060
    my $patron_2  = $builder->build_object({
2061
        class => 'Koha::Patrons',
2062
        value => { categorycode => $patron_category->{categorycode} }
2063
    });
2064
2052
2065
2053
    my $item = $builder->build_sample_item(
2066
    my $item = $builder->build_sample_item(
2054
        {
2067
        {
Lines 4091-4097 subtest 'CanBookBeIssued | is_overdue' => sub { Link Here
4091
        }
4104
        }
4092
    );
4105
    );
4093
4106
4094
    my $issue = AddIssue( $patron->unblessed, $item->barcode, $five_days_go ); # date due was 10d ago
4107
    my $issue = AddIssue( $patron, $item->barcode, $five_days_go ); # date due was 10d ago
4095
    my $actualissue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
4108
    my $actualissue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
4096
    is( output_pref({ str => $actualissue->date_due, dateonly => 1}), output_pref({ str => $five_days_go, dateonly => 1}), "First issue works");
4109
    is( output_pref({ str => $actualissue->date_due, dateonly => 1}), output_pref({ str => $five_days_go, dateonly => 1}), "First issue works");
4097
    my ($issuingimpossible, $needsconfirmation) = CanBookBeIssued($patron, $item->barcode, $ten_days_go, undef, undef, undef);
4110
    my ($issuingimpossible, $needsconfirmation) = CanBookBeIssued($patron, $item->barcode, $ten_days_go, undef, undef, undef);
Lines 4457-4463 subtest 'AddReturn | recalls' => sub { Link Here
4457
    });
4470
    });
4458
4471
4459
    # this item can fill a recall with pickup at this branch
4472
    # this item can fill a recall with pickup at this branch
4460
    AddIssue( $patron1->unblessed, $item1->barcode );
4473
    AddIssue( $patron1, $item1->barcode );
4461
    my $recall1 = Koha::Recall->new(
4474
    my $recall1 = Koha::Recall->new(
4462
        {   patron_id         => $patron2->borrowernumber,
4475
        {   patron_id         => $patron2->borrowernumber,
4463
            biblio_id         => $item1->biblionumber,
4476
            biblio_id         => $item1->biblionumber,
Lines 4471-4477 subtest 'AddReturn | recalls' => sub { Link Here
4471
    $recall1->set_cancelled;
4484
    $recall1->set_cancelled;
4472
4485
4473
    # this item can fill a recall but needs transfer
4486
    # this item can fill a recall but needs transfer
4474
    AddIssue( $patron1->unblessed, $item1->barcode );
4487
    AddIssue( $patron1, $item1->barcode );
4475
    $recall1 = Koha::Recall->new(
4488
    $recall1 = Koha::Recall->new(
4476
        {   patron_id         => $patron2->borrowernumber,
4489
        {   patron_id         => $patron2->borrowernumber,
4477
            biblio_id         => $item1->biblionumber,
4490
            biblio_id         => $item1->biblionumber,
Lines 4485-4491 subtest 'AddReturn | recalls' => sub { Link Here
4485
    $recall1->set_cancelled;
4498
    $recall1->set_cancelled;
4486
4499
4487
    # this item is already in transit, do not ask to transfer
4500
    # this item is already in transit, do not ask to transfer
4488
    AddIssue( $patron1->unblessed, $item1->barcode );
4501
    AddIssue( $patron1, $item1->barcode );
4489
    $recall1 = Koha::Recall->new(
4502
    $recall1 = Koha::Recall->new(
4490
        {   patron_id         => $patron2->borrowernumber,
4503
        {   patron_id         => $patron2->borrowernumber,
4491
            biblio_id         => $item1->biblionumber,
4504
            biblio_id         => $item1->biblionumber,
Lines 4563-4569 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
4563
    $context->mock( userenv => { branch => $library->id } );
4576
    $context->mock( userenv => { branch => $library->id } );
4564
4577
4565
    # Check the item out
4578
    # Check the item out
4566
    AddIssue( $patron->unblessed, $item->barcode );
4579
    AddIssue( $patron, $item->barcode );
4567
4580
4568
    throws_ok {
4581
    throws_ok {
4569
        AddRenewal( $patron->borrowernumber, $item->itemnumber, $library->id, undef, {break=>"the_renewal"} );
4582
        AddRenewal( $patron->borrowernumber, $item->itemnumber, $library->id, undef, {break=>"the_renewal"} );
Lines 4621-4627 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
4621
    is( $new_stats_size, $old_stats_size + 1, 'renew statistic successfully added with passed branch' );
4634
    is( $new_stats_size, $old_stats_size + 1, 'renew statistic successfully added with passed branch' );
4622
4635
4623
    AddReturn( $item->id, $library->id, undef, $date );
4636
    AddReturn( $item->id, $library->id, undef, $date );
4624
    AddIssue( $patron->unblessed, $item->barcode, $now );
4637
    AddIssue( $patron, $item->barcode, $now );
4625
    AddRenewal( $patron->id, $item->id, $library->id, undef, undef, 1 );
4638
    AddRenewal( $patron->id, $item->id, $library->id, undef, undef, 1 );
4626
    my $lines_skipped = Koha::Account::Lines->search({
4639
    my $lines_skipped = Koha::Account::Lines->search({
4627
        borrowernumber => $patron->id,
4640
        borrowernumber => $patron->id,
Lines 4645-4651 subtest 'AddRenewal() adds to renewals' => sub { Link Here
4645
    set_userenv( $library->unblessed );
4658
    set_userenv( $library->unblessed );
4646
4659
4647
    # Check the item out
4660
    # Check the item out
4648
    my $issue = AddIssue( $patron->unblessed, $item->barcode );
4661
    my $issue = AddIssue( $patron, $item->barcode );
4649
    is(ref($issue), 'Koha::Checkout', 'Issue added');
4662
    is(ref($issue), 'Koha::Checkout', 'Issue added');
4650
4663
4651
    # Renew item
4664
    # Renew item
Lines 4729-4735 subtest 'Incremented fee tests' => sub { Link Here
4729
4742
4730
    # Daily Tests
4743
    # Daily Tests
4731
    my $issue =
4744
    my $issue =
4732
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4745
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4733
    my $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4746
    my $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4734
    is(
4747
    is(
4735
        $accountline->amount + 0,
4748
        $accountline->amount + 0,
Lines 4750-4756 subtest 'Incremented fee tests' => sub { Link Here
4750
    t::lib::Mocks::mock_preference( 'finesCalendar', 'noFinesWhenClosed' );
4763
    t::lib::Mocks::mock_preference( 'finesCalendar', 'noFinesWhenClosed' );
4751
    $itemtype->rentalcharge_daily_calendar(1)->store();
4764
    $itemtype->rentalcharge_daily_calendar(1)->store();
4752
    $issue =
4765
    $issue =
4753
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4766
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4754
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4767
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4755
    is(
4768
    is(
4756
        $accountline->amount + 0,
4769
        $accountline->amount + 0,
Lines 4781-4787 subtest 'Incremented fee tests' => sub { Link Here
4781
        description => 'Test holiday'
4794
        description => 'Test holiday'
4782
    );
4795
    );
4783
    $issue =
4796
    $issue =
4784
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4797
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4785
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4798
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4786
    is(
4799
    is(
4787
        $accountline->amount + 0,
4800
        $accountline->amount + 0,
Lines 4802-4808 subtest 'Incremented fee tests' => sub { Link Here
4802
    $itemtype->rentalcharge(2)->store;
4815
    $itemtype->rentalcharge(2)->store;
4803
    is( $itemtype->rentalcharge + 0, 2, 'Rental charge updated and retreived correctly' );
4816
    is( $itemtype->rentalcharge + 0, 2, 'Rental charge updated and retreived correctly' );
4804
    $issue =
4817
    $issue =
4805
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4818
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4806
    my $accountlines =
4819
    my $accountlines =
4807
      Koha::Account::Lines->search( { itemnumber => $item->id } );
4820
      Koha::Account::Lines->search( { itemnumber => $item->id } );
4808
    is( $accountlines->count, '2', "Fixed charge and accrued charge recorded distinctly" );
4821
    is( $accountlines->count, '2', "Fixed charge and accrued charge recorded distinctly" );
Lines 4834-4840 subtest 'Incremented fee tests' => sub { Link Here
4834
4847
4835
    $itemtype->rentalcharge_hourly_calendar(0)->store();
4848
    $itemtype->rentalcharge_hourly_calendar(0)->store();
4836
    $issue =
4849
    $issue =
4837
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4850
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4838
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4851
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4839
    is(
4852
    is(
4840
        $accountline->amount + 0,
4853
        $accountline->amount + 0,
Lines 4854-4860 subtest 'Incremented fee tests' => sub { Link Here
4854
4867
4855
    $itemtype->rentalcharge_hourly_calendar(1)->store();
4868
    $itemtype->rentalcharge_hourly_calendar(1)->store();
4856
    $issue =
4869
    $issue =
4857
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4870
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4858
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4871
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4859
    is(
4872
    is(
4860
        $accountline->amount + 0,
4873
        $accountline->amount + 0,
Lines 4874-4880 subtest 'Incremented fee tests' => sub { Link Here
4874
4887
4875
    $calendar->delete_holiday( weekday => $closed_day );
4888
    $calendar->delete_holiday( weekday => $closed_day );
4876
    $issue =
4889
    $issue =
4877
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4890
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4878
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4891
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4879
    is(
4892
    is(
4880
        $accountline->amount + 0,
4893
        $accountline->amount + 0,
Lines 4988-4994 subtest 'Do not return on renewal (LOST charge)' => sub { Link Here
4988
    );
5001
    );
4989
5002
4990
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
5003
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
4991
    AddIssue( $patron->unblessed, $item->barcode );
5004
    AddIssue( $patron, $item->barcode );
4992
5005
4993
    my $accountline = Koha::Account::Line->new(
5006
    my $accountline = Koha::Account::Line->new(
4994
        {
5007
        {
Lines 5003-5009 subtest 'Do not return on renewal (LOST charge)' => sub { Link Here
5003
    )->store();
5016
    )->store();
5004
5017
5005
    # AddRenewal doesn't call _FixAccountForLostAndFound
5018
    # AddRenewal doesn't call _FixAccountForLostAndFound
5006
    AddIssue( $patron->unblessed, $item->barcode );
5019
    AddIssue( $patron, $item->barcode );
5007
5020
5008
    is( $patron->checkouts->count, 1,
5021
    is( $patron->checkouts->count, 1,
5009
        'Renewal should not return the item even if a LOST payment has been made earlier'
5022
        'Renewal should not return the item even if a LOST payment has been made earlier'
Lines 5109-5115 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddReturn' => sub { Link Here
5109
                replacementprice => '42',
5122
                replacementprice => '42',
5110
            }
5123
            }
5111
        );
5124
        );
5112
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5125
        my $issue = AddIssue( $patron, $item->barcode );
5113
        LostItem( $item->itemnumber, 'cli', 0 );
5126
        LostItem( $item->itemnumber, 'cli', 0 );
5114
        $item->_result->itemlost(1);
5127
        $item->_result->itemlost(1);
5115
        $item->_result->itemlost_on( $lost_on );
5128
        $item->_result->itemlost_on( $lost_on );
Lines 5144-5150 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddReturn' => sub { Link Here
5144
                replacementprice => '42',
5157
                replacementprice => '42',
5145
            }
5158
            }
5146
        );
5159
        );
5147
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5160
        my $issue = AddIssue( $patron, $item->barcode );
5148
        LostItem( $item->itemnumber, 'cli', 0 );
5161
        LostItem( $item->itemnumber, 'cli', 0 );
5149
        $item->_result->itemlost(1);
5162
        $item->_result->itemlost(1);
5150
        $item->_result->itemlost_on( $lost_on );
5163
        $item->_result->itemlost_on( $lost_on );
Lines 5179-5185 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddReturn' => sub { Link Here
5179
                replacementprice => '42',
5192
                replacementprice => '42',
5180
            }
5193
            }
5181
        );
5194
        );
5182
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5195
        my $issue = AddIssue( $patron, $item->barcode );
5183
        LostItem( $item->itemnumber, 'cli', 0 );
5196
        LostItem( $item->itemnumber, 'cli', 0 );
5184
        $item->_result->itemlost(1);
5197
        $item->_result->itemlost(1);
5185
        $item->_result->itemlost_on( $lost_on );
5198
        $item->_result->itemlost_on( $lost_on );
Lines 5214-5220 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddReturn' => sub { Link Here
5214
                replacementprice => '42',
5227
                replacementprice => '42',
5215
            }
5228
            }
5216
        );
5229
        );
5217
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5230
        my $issue = AddIssue( $patron, $item->barcode );
5218
        LostItem( $item->itemnumber, 'cli', 0 );
5231
        LostItem( $item->itemnumber, 'cli', 0 );
5219
        $item->_result->itemlost(1);
5232
        $item->_result->itemlost(1);
5220
        $item->_result->itemlost_on( $lost_on );
5233
        $item->_result->itemlost_on( $lost_on );
Lines 5302-5308 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5302
                replacementprice => '42',
5315
                replacementprice => '42',
5303
            }
5316
            }
5304
        );
5317
        );
5305
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5318
        my $issue = AddIssue( $patron, $item->barcode );
5306
        LostItem( $item->itemnumber, 'cli', 0 );
5319
        LostItem( $item->itemnumber, 'cli', 0 );
5307
        $item->_result->itemlost(1);
5320
        $item->_result->itemlost(1);
5308
        $item->_result->itemlost_on( $lost_on );
5321
        $item->_result->itemlost_on( $lost_on );
Lines 5316-5322 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5316
        )->next;
5329
        )->next;
5317
        ok( $a, "Found accountline for lost fee" );
5330
        ok( $a, "Found accountline for lost fee" );
5318
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5331
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5319
        $issue = AddIssue( $patron2->unblessed, $item->barcode );
5332
        $issue = AddIssue( $patron2, $item->barcode );
5320
        $a = $a->get_from_storage;
5333
        $a = $a->get_from_storage;
5321
        is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" );
5334
        is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" );
5322
        $a->delete;
5335
        $a->delete;
Lines 5338-5344 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5338
                replacementprice => '42',
5351
                replacementprice => '42',
5339
            }
5352
            }
5340
        );
5353
        );
5341
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5354
        my $issue = AddIssue( $patron, $item->barcode );
5342
        LostItem( $item->itemnumber, 'cli', 0 );
5355
        LostItem( $item->itemnumber, 'cli', 0 );
5343
        $item->_result->itemlost(1);
5356
        $item->_result->itemlost(1);
5344
        $item->_result->itemlost_on( $lost_on );
5357
        $item->_result->itemlost_on( $lost_on );
Lines 5352-5358 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5352
        )->next;
5365
        )->next;
5353
        ok( $a, "Found accountline for lost fee" );
5366
        ok( $a, "Found accountline for lost fee" );
5354
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5367
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5355
        $issue = AddIssue( $patron2->unblessed, $item->barcode );
5368
        $issue = AddIssue( $patron2, $item->barcode );
5356
        $a = $a->get_from_storage;
5369
        $a = $a->get_from_storage;
5357
        is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" );
5370
        is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" );
5358
        $a->delete;
5371
        $a->delete;
Lines 5373-5379 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5373
                replacementprice => '42',
5386
                replacementprice => '42',
5374
            }
5387
            }
5375
        );
5388
        );
5376
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5389
        my $issue = AddIssue( $patron, $item->barcode );
5377
        LostItem( $item->itemnumber, 'cli', 0 );
5390
        LostItem( $item->itemnumber, 'cli', 0 );
5378
        $item->_result->itemlost(1);
5391
        $item->_result->itemlost(1);
5379
        $item->_result->itemlost_on( $lost_on );
5392
        $item->_result->itemlost_on( $lost_on );
Lines 5387-5393 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5387
        )->next;
5400
        )->next;
5388
        ok( $a, "Found accountline for lost fee" );
5401
        ok( $a, "Found accountline for lost fee" );
5389
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5402
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5390
        $issue = AddIssue( $patron2->unblessed, $item->barcode );
5403
        $issue = AddIssue( $patron2, $item->barcode );
5391
        $a = $a->get_from_storage;
5404
        $a = $a->get_from_storage;
5392
        is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" );
5405
        is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" );
5393
        $a->delete;
5406
        $a->delete;
Lines 5408-5414 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5408
                replacementprice => '42',
5421
                replacementprice => '42',
5409
            }
5422
            }
5410
        );
5423
        );
5411
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5424
        my $issue = AddIssue( $patron, $item->barcode );
5412
        LostItem( $item->itemnumber, 'cli', 0 );
5425
        LostItem( $item->itemnumber, 'cli', 0 );
5413
        $item->_result->itemlost(1);
5426
        $item->_result->itemlost(1);
5414
        $item->_result->itemlost_on( $lost_on );
5427
        $item->_result->itemlost_on( $lost_on );
Lines 5423-5429 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5423
        $a = $a->next;
5436
        $a = $a->next;
5424
        ok( $a, "Found accountline for lost fee" );
5437
        ok( $a, "Found accountline for lost fee" );
5425
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5438
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5426
        $issue = AddIssue( $patron2->unblessed, $item->barcode );
5439
        $issue = AddIssue( $patron2, $item->barcode );
5427
        $a = $a->get_from_storage;
5440
        $a = $a->get_from_storage;
5428
        is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" );
5441
        is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" );
5429
        $a->delete;
5442
        $a->delete;
Lines 5509-5515 subtest 'Checkout should correctly terminate a transfer' => sub { Link Here
5509
    is( $transfer->reason,     'Reserve' );
5522
    is( $transfer->reason,     'Reserve' );
5510
5523
5511
    t::lib::Mocks::mock_userenv( { branchcode => $library_2->branchcode } );
5524
    t::lib::Mocks::mock_userenv( { branchcode => $library_2->branchcode } );
5512
    AddIssue( $patron_1->unblessed, $item->barcode );
5525
    AddIssue( $patron_1, $item->barcode );
5513
    $transfer = $transfer->get_from_storage;
5526
    $transfer = $transfer->get_from_storage;
5514
    isnt( $transfer->datearrived, undef );
5527
    isnt( $transfer->datearrived, undef );
5515
    $hold = $hold->get_from_storage;
5528
    $hold = $hold->get_from_storage;
Lines 5552-5565 subtest 'AddIssue records staff who checked out item if appropriate' => sub { Link Here
5552
    my $dt_from = dt_from_string();
5565
    my $dt_from = dt_from_string();
5553
    my $dt_to   = dt_from_string()->add( days => 7 );
5566
    my $dt_to   = dt_from_string()->add( days => 7 );
5554
5567
5555
    my $issue_1 = AddIssue( $patron->unblessed, $item_1->barcode, $dt_to, undef, $dt_from );
5568
    my $issue_1 = AddIssue( $patron, $item_1->barcode, $dt_to, undef, $dt_from );
5556
5569
5557
    is( $issue_1->issuer, undef, "Staff who checked out the item not recorded when RecordStaffUserOnCheckout turned off" );
5570
    is( $issue_1->issuer, undef, "Staff who checked out the item not recorded when RecordStaffUserOnCheckout turned off" );
5558
5571
5559
    t::lib::Mocks::mock_preference('RecordStaffUserOnCheckout', 1);
5572
    t::lib::Mocks::mock_preference('RecordStaffUserOnCheckout', 1);
5560
5573
5561
    my $issue_2 =
5574
    my $issue_2 =
5562
      AddIssue( $patron->unblessed, $item_2->barcode, $dt_to, undef, $dt_from );
5575
      AddIssue( $patron, $item_2->barcode, $dt_to, undef, $dt_from );
5563
5576
5564
    is( $issue_2->issuer->borrowernumber, $issuer->borrowernumber, "Staff who checked out the item recorded when RecordStaffUserOnCheckout turned on" );
5577
    is( $issue_2->issuer->borrowernumber, $issuer->borrowernumber, "Staff who checked out the item recorded when RecordStaffUserOnCheckout turned on" );
5565
};
5578
};
Lines 5587-5595 subtest "Item's onloan value should be set if checked out item is checked out to Link Here
5587
        }
5600
        }
5588
    );
5601
    );
5589
5602
5590
    AddIssue( $patron_1->unblessed, $item->barcode );
5603
    AddIssue( $patron_1, $item->barcode );
5591
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after initial checkout" );
5604
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after initial checkout" );
5592
    AddIssue( $patron_2->unblessed, $item->barcode );
5605
    AddIssue( $patron_2, $item->barcode );
5593
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after second checkout" );
5606
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after second checkout" );
5594
};
5607
};
5595
5608
Lines 5666-5672 subtest "SendCirculationAlert" => sub { Link Here
5666
    })->store;
5679
    })->store;
5667
5680
5668
    # Checkout an item, mark it returned, generate a notice
5681
    # Checkout an item, mark it returned, generate a notice
5669
    my $issue_1 = AddIssue( $patron->unblessed, $item->barcode);
5682
    my $issue_1 = AddIssue( $patron, $item->barcode);
5670
    MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0, { skip_record_index => 1} );
5683
    MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0, { skip_record_index => 1} );
5671
    C4::Circulation::SendCirculationAlert({
5684
    C4::Circulation::SendCirculationAlert({
5672
        type => 'CHECKIN',
5685
        type => 'CHECKIN',
Lines 5680-5686 subtest "SendCirculationAlert" => sub { Link Here
5680
    is($notice->to_address, $patron->smsalertnumber, "Letter has the correct to_address set to smsalertnumber for SMS type notices");
5693
    is($notice->to_address, $patron->smsalertnumber, "Letter has the correct to_address set to smsalertnumber for SMS type notices");
5681
5694
5682
    # Checkout an item, mark it returned, generate a notice
5695
    # Checkout an item, mark it returned, generate a notice
5683
    my $issue_2 = AddIssue( $patron->unblessed, $item->barcode);
5696
    my $issue_2 = AddIssue( $patron, $item->barcode);
5684
    MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0, { skip_record_index => 1} );
5697
    MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0, { skip_record_index => 1} );
5685
    C4::Circulation::SendCirculationAlert({
5698
    C4::Circulation::SendCirculationAlert({
5686
        type => 'CHECKIN',
5699
        type => 'CHECKIN',
Lines 5707-5713 subtest "GetSoonestRenewDate tests" => sub { Link Here
5707
    );
5720
    );
5708
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
5721
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
5709
    my $item = $builder->build_sample_item();
5722
    my $item = $builder->build_sample_item();
5710
    my $issue = AddIssue( $patron->unblessed, $item->barcode);
5723
    my $issue = AddIssue( $patron, $item->barcode);
5711
    my $datedue = dt_from_string( $issue->date_due() );
5724
    my $datedue = dt_from_string( $issue->date_due() );
5712
5725
5713
    # Bug 14395
5726
    # Bug 14395
(-)a/t/db_dependent/Circulation/CalcDateDue.t (-17 / +33 lines)
Lines 18-26 my $schema = Koha::Database->new->schema; Link Here
18
$schema->storage->txn_begin;
18
$schema->storage->txn_begin;
19
my $builder = t::lib::TestBuilder->new;
19
my $builder = t::lib::TestBuilder->new;
20
20
21
my $categorycode = 'B';
21
22
my $itemtype = 'MX';
22
my $library = $builder->build_object({ class => 'Koha::Libraries' })->store;
23
my $branchcode = 'FPL';
23
my $dateexpiry = '2013-01-01';
24
my $patron_category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { category_type => 'B' } })->store;
25
my $borrower = $builder->build_object(
26
    {
27
        class  => 'Koha::Patrons',
28
        value  => {
29
            categorycode => $patron_category->categorycode,
30
            dateexpiry => $dateexpiry,
31
        }
32
    }
33
)->store;
34
35
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' })->store->itemtype;
24
my $issuelength = 10;
36
my $issuelength = 10;
25
my $renewalperiod = 5;
37
my $renewalperiod = 5;
26
my $lengthunit = 'days';
38
my $lengthunit = 'days';
Lines 28-36 my $lengthunit = 'days'; Link Here
28
Koha::CirculationRules->search()->delete();
40
Koha::CirculationRules->search()->delete();
29
Koha::CirculationRules->set_rules(
41
Koha::CirculationRules->set_rules(
30
    {
42
    {
31
        categorycode => $categorycode,
43
        categorycode => $patron_category->categorycode,
32
        itemtype     => $itemtype,
44
        itemtype     => $itemtype,
33
        branchcode   => $branchcode,
45
        branchcode   => $library->branchcode,
34
        rules        => {
46
        rules        => {
35
            issuelength   => $issuelength,
47
            issuelength   => $issuelength,
36
            renewalperiod => $renewalperiod,
48
            renewalperiod => $renewalperiod,
Lines 43-55 Koha::CirculationRules->set_rules( Link Here
43
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1);
55
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1);
44
t::lib::Mocks::mock_preference('useDaysMode', 'Days');
56
t::lib::Mocks::mock_preference('useDaysMode', 'Days');
45
57
58
my $branchcode = $library->branchcode;
59
46
my $cache = Koha::Caches->get_instance();
60
my $cache = Koha::Caches->get_instance();
47
my $key   = $branchcode . "_holidays";
61
my $key   = $branchcode . "_holidays";
48
$cache->clear_from_cache($key);
62
$cache->clear_from_cache($key);
49
63
50
my $dateexpiry = '2013-01-01';
51
52
my $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
53
my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
64
my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
54
my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
65
my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
55
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
66
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
Lines 60-66 $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borr Link Here
60
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1);
71
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1);
61
t::lib::Mocks::mock_preference('useDaysMode', 'noDays');
72
t::lib::Mocks::mock_preference('useDaysMode', 'noDays');
62
73
63
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
64
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
74
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
65
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
75
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
66
is($date, $dateexpiry . 'T23:59:00', 'date expiry with useDaysMode to noDays');
76
is($date, $dateexpiry . 'T23:59:00', 'date expiry with useDaysMode to noDays');
Lines 95-101 $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borr Link Here
95
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 0);
105
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 0);
96
t::lib::Mocks::mock_preference('useDaysMode', 'Days');
106
t::lib::Mocks::mock_preference('useDaysMode', 'Days');
97
107
98
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
99
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
108
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
100
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
109
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
101
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
110
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
Lines 158-175 $calendar->delete_holiday( Link Here
158
167
159
# Now we test it does the right thing if the loan and renewal periods
168
# Now we test it does the right thing if the loan and renewal periods
160
# are a multiple of 7 days
169
# are a multiple of 7 days
161
my $dayweek_categorycode = 'K';
162
my $dayweek_itemtype = 'MX';
163
my $dayweek_branchcode = 'FPL';
164
my $dayweek_issuelength = 14;
170
my $dayweek_issuelength = 14;
165
my $dayweek_renewalperiod = 7;
171
my $dayweek_renewalperiod = 7;
166
my $dayweek_lengthunit = 'days';
172
my $dayweek_lengthunit = 'days';
167
173
174
$patron_category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { category_type => 'K' } })->store;
175
168
Koha::CirculationRules->set_rules(
176
Koha::CirculationRules->set_rules(
169
    {
177
    {
170
        categorycode => $dayweek_categorycode,
178
        categorycode => $patron_category->categorycode,
171
        itemtype     => $dayweek_itemtype,
179
        itemtype     => $itemtype,
172
        branchcode   => $dayweek_branchcode,
180
        branchcode   => $branchcode,
173
        rules        => {
181
        rules        => {
174
            issuelength   => $dayweek_issuelength,
182
            issuelength   => $dayweek_issuelength,
175
            renewalperiod => $dayweek_renewalperiod,
183
            renewalperiod => $dayweek_renewalperiod,
Lines 178-184 Koha::CirculationRules->set_rules( Link Here
178
    }
186
    }
179
);
187
);
180
188
181
my $dayweek_borrower = {categorycode => 'K', dateexpiry => $dateexpiry};
189
my $dayweek_borrower = $builder->build_object(
190
    {
191
        class  => 'Koha::Patrons',
192
        value  => {
193
            categorycode => $patron_category->categorycode,
194
            dateexpiry => $dateexpiry,
195
        }
196
    }
197
);
182
198
183
# For issues...
199
# For issues...
184
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
200
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
(-)a/t/db_dependent/Circulation/CheckIfIssuedToPatron.t (-7 / +27 lines)
Lines 66-76 my ($biblionumber2) = AddBiblio(MARC::Record->new, ''); Link Here
66
my $barcode2 = '0202';
66
my $barcode2 = '0202';
67
Koha::Item->new({ barcode => $barcode2, %item_info, biblionumber => $biblionumber2 })->store;
67
Koha::Item->new({ barcode => $barcode2, %item_info, biblionumber => $biblionumber2 })->store;
68
68
69
my $borrowernumber1 = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode})->store->borrowernumber;
69
my $patron1 = $builder->build_object(
70
my $borrowernumber2 = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode})->store->borrowernumber;
70
    {
71
# FIXME following code must be simplified to use the Koha::Patron objects
71
        class => 'Koha::Patrons'
72
my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed;
72
        value => {
73
my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed;
73
            {
74
                categorycode => $categorycode,
75
                branchcode => $branchcode
76
            }
77
        }
78
    }
79
);
80
my $patron2 = $builder->build_object(
81
    {
82
        class => 'Koha::Patrons'
83
        value => {
84
            {
85
                categorycode => $categorycode,
86
                branchcode => $branchcode
87
            }
88
        }
89
    }
90
);
91
92
my $borrowernumber1 = $patron1->borrowernumber;
93
my $borrowernumber2 = $patron2->borrowernumber;
74
94
75
my $module = Test::MockModule->new('C4::Context');
95
my $module = Test::MockModule->new('C4::Context');
76
$module->mock('userenv', sub { { branch => $branchcode } });
96
$module->mock('userenv', sub { { branch => $branchcode } });
Lines 91-97 is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' ); Link Here
91
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2);
111
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2);
92
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
112
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
93
113
94
AddIssue($borrower1, '0101');
114
AddIssue($patron1, '0101');
95
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron();
115
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron();
96
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
116
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
97
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron(undef, $biblionumber1);
117
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron(undef, $biblionumber1);
Lines 107-113 is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' ); Link Here
107
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2);
127
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2);
108
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
128
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
109
129
110
AddIssue($borrower2, '0202');
130
AddIssue($patron2, '0202');
111
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron();
131
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron();
112
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
132
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
113
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron(undef, $biblionumber1);
133
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron(undef, $biblionumber1);
(-)a/t/db_dependent/Circulation/GetPendingOnSiteCheckouts.t (-8 / +6 lines)
Lines 57-82 my ($biblionumber2) = AddBiblio(MARC::Record->new, ''); Link Here
57
my $itemnumber3 = Koha::Item->new({ barcode => '0203', %item_infos, biblionumber => $biblionumber2})->store->itemnumber;
57
my $itemnumber3 = Koha::Item->new({ barcode => '0203', %item_infos, biblionumber => $biblionumber2})->store->itemnumber;
58
58
59
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
59
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
60
my $borrowernumber = $builder->build(
60
my $patron = $builder->build_object(
61
    {   source => 'Borrower',
61
    {   class => 'Koha::Patrons',
62
        value  => { categorycode => $categorycode, branchcode => $branchcode }
62
        value  => { categorycode => $categorycode, branchcode => $branchcode }
63
    }
63
    }
64
)->{borrowernumber};
64
);
65
66
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
67
65
68
# Need to mock userenv for AddIssue
66
# Need to mock userenv for AddIssue
69
my $module = Test::MockModule->new('C4::Context');
67
my $module = Test::MockModule->new('C4::Context');
70
$module->mock('userenv', sub { { branch => $branchcode } });
68
$module->mock('userenv', sub { { branch => $branchcode } });
71
AddIssue($borrower, '0101');
69
AddIssue($patron, '0101');
72
AddIssue($borrower, '0203');
70
AddIssue($patron, '0203');
73
71
74
# Begin tests...
72
# Begin tests...
75
my $onsite_checkouts = GetPendingOnSiteCheckouts;
73
my $onsite_checkouts = GetPendingOnSiteCheckouts;
76
is( scalar @$onsite_checkouts, 0, "No pending on-site checkouts" );
74
is( scalar @$onsite_checkouts, 0, "No pending on-site checkouts" );
77
75
78
my $itemnumber4 = Koha::Item->new({ barcode => '0104', %item_infos, biblionumber => $biblionumber1})->store->itemnumber;
76
my $itemnumber4 = Koha::Item->new({ barcode => '0104', %item_infos, biblionumber => $biblionumber1})->store->itemnumber;
79
AddIssue( $borrower, '0104', undef, undef, undef, undef, { onsite_checkout => 1 } );
77
AddIssue( $patron, '0104', undef, undef, undef, undef, { onsite_checkout => 1 } );
80
$onsite_checkouts = GetPendingOnSiteCheckouts;
78
$onsite_checkouts = GetPendingOnSiteCheckouts;
81
is( scalar @$onsite_checkouts, 1, "There is 1 pending on-site checkout" );
79
is( scalar @$onsite_checkouts, 1, "There is 1 pending on-site checkout" );
82
80
(-)a/t/db_dependent/Circulation/GetTopIssues.t (-1 / +1 lines)
Lines 68-74 my $borrowernumber = Koha::Patron->new({ Link Here
68
    categorycode => $category,
68
    categorycode => $category,
69
    branchcode => $branch_1->{ branchcode }
69
    branchcode => $branch_1->{ branchcode }
70
})->store->borrowernumber;
70
})->store->borrowernumber;
71
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
71
my $borrower = Koha::Patrons->find( $borrowernumber );
72
72
73
AddIssue($borrower, 'GTI_BARCODE_001');
73
AddIssue($borrower, 'GTI_BARCODE_001');
74
AddIssue($borrower, 'GTI_BARCODE_002');
74
AddIssue($borrower, 'GTI_BARCODE_002');
(-)a/t/db_dependent/Circulation/IsItemIssued.t (-3 / +3 lines)
Lines 42-55 my $patron_category = $builder->build({ source => 'Category' }); Link Here
42
42
43
t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
43
t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
44
44
45
my $borrowernumber = Koha::Patron->new({
45
my $borrower = Koha::Patron->new({
46
    firstname =>  'my firstname',
46
    firstname =>  'my firstname',
47
    surname => 'my surname',
47
    surname => 'my surname',
48
    categorycode => $patron_category->{categorycode},
48
    categorycode => $patron_category->{categorycode},
49
    branchcode => $library->{branchcode},
49
    branchcode => $library->{branchcode},
50
})->store->borrowernumber;
50
})->store;
51
51
52
52
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
53
my $record = MARC::Record->new();
53
my $record = MARC::Record->new();
54
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
54
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
55
55
(-)a/t/db_dependent/Circulation/MarkIssueReturned.t (-8 / +8 lines)
Lines 63-69 subtest 'Failure tests' => sub { Link Here
63
    is( $issue_id, undef, 'No issue_id returned' );
63
    is( $issue_id, undef, 'No issue_id returned' );
64
64
65
    # In the next call we return the item and try it another time
65
    # In the next call we return the item and try it another time
66
    $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
66
    $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
67
    eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0 ) };
67
    eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0 ) };
68
    is( $issue_id, $issue->issue_id, "Item has been returned (issue $issue_id)" );
68
    is( $issue_id, $issue->issue_id, "Item has been returned (issue $issue_id)" );
69
    eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0 ) };
69
    eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0 ) };
Lines 98-104 subtest 'Anonymous patron tests' => sub { Link Here
98
    # Anonymous patron not set
98
    # Anonymous patron not set
99
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
99
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
100
100
101
    my $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
101
    my $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
102
102
103
    throws_ok
103
    throws_ok
104
        { C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 2 ); }
104
        { C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 2 ); }
Lines 117-123 subtest 'Anonymous patron tests' => sub { Link Here
117
        }
117
        }
118
    });
118
    });
119
    t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous->borrowernumber);
119
    t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous->borrowernumber);
120
    $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
120
    $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
121
121
122
    eval { C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 2 ) };
122
    eval { C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 2 ) };
123
    is ( $@, q||, 'AnonymousPatron is set correctly - no error expected');
123
    is ( $@, q||, 'AnonymousPatron is set correctly - no error expected');
Lines 148-161 subtest 'Manually pass a return date' => sub { Link Here
148
148
149
    my ( $issue, $issue_id );
149
    my ( $issue, $issue_id );
150
150
151
    $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
151
    $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
152
    $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, '2018-12-25', 0 );
152
    $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, '2018-12-25', 0 );
153
153
154
    is( $issue_id, $issue->issue_id, "Item has been returned" );
154
    is( $issue_id, $issue->issue_id, "Item has been returned" );
155
    my $old_checkout = Koha::Old::Checkouts->find( $issue_id );
155
    my $old_checkout = Koha::Old::Checkouts->find( $issue_id );
156
    is( $old_checkout->returndate, '2018-12-25 00:00:00', 'Manually passed date stored correctly' );
156
    is( $old_checkout->returndate, '2018-12-25 00:00:00', 'Manually passed date stored correctly' );
157
157
158
    $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
158
    $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
159
159
160
    {
160
    {
161
        # Hiding the expected warning displayed by DBI
161
        # Hiding the expected warning displayed by DBI
Lines 185-193 subtest 'AutoRemoveOverduesRestrictions' => sub { Link Here
185
    my $item_2 = $builder->build_sample_item;
185
    my $item_2 = $builder->build_sample_item;
186
    my $item_3 = $builder->build_sample_item;
186
    my $item_3 = $builder->build_sample_item;
187
    my $five_days_ago = dt_from_string->subtract( days => 5 );
187
    my $five_days_ago = dt_from_string->subtract( days => 5 );
188
    my $checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $five_days_ago ); # overdue
188
    my $checkout_1 = AddIssue( $patron, $item_1->barcode, $five_days_ago ); # overdue
189
    my $checkout_2 = AddIssue( $patron->unblessed, $item_2->barcode, $five_days_ago ); # overdue
189
    my $checkout_2 = AddIssue( $patron, $item_2->barcode, $five_days_ago ); # overdue
190
    my $checkout_3 = AddIssue( $patron->unblessed, $item_3->barcode ); # not overdue
190
    my $checkout_3 = AddIssue( $patron, $item_3->barcode ); # not overdue
191
191
192
    Koha::Patron::Debarments::AddUniqueDebarment(
192
    Koha::Patron::Debarments::AddUniqueDebarment(
193
        {
193
        {
(-)a/t/db_dependent/Circulation/ReturnClaims.t (-3 / +3 lines)
Lines 65-71 subtest 'Test Koha::Checkout::claim_returned, do not mark as returned' => sub { Link Here
65
    t::lib::Mocks::mock_preference( 'MarkLostItemsAsReturned', q{} );
65
    t::lib::Mocks::mock_preference( 'MarkLostItemsAsReturned', q{} );
66
    my $item   = $builder->build_sample_item;
66
    my $item   = $builder->build_sample_item;
67
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
67
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
68
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
68
    my $checkout = AddIssue( $patron, $item->barcode );
69
69
70
    my $claim = $checkout->claim_returned(
70
    my $claim = $checkout->claim_returned(
71
        {
71
        {
Lines 91-97 subtest 'Test Koha::Patronn::return_claims' => sub { Link Here
91
    t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', 1 );
91
    t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', 1 );
92
    my $item   = $builder->build_sample_item;
92
    my $item   = $builder->build_sample_item;
93
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
93
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
94
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
94
    my $checkout = AddIssue( $patron, $item->barcode );
95
95
96
    $checkout->claim_returned(
96
    $checkout->claim_returned(
97
        {
97
        {
Lines 121-127 subtest 'Test Koha::Checkout::claim_returned, mark as returned' => sub { Link Here
121
    t::lib::Mocks::mock_preference( 'MarkLostItemsAsReturned', q{claim_returned} );
121
    t::lib::Mocks::mock_preference( 'MarkLostItemsAsReturned', q{claim_returned} );
122
    my $item     = $builder->build_sample_item;
122
    my $item     = $builder->build_sample_item;
123
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
123
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
124
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
124
    my $checkout = AddIssue( $patron, $item->barcode );
125
125
126
    my $claim = $checkout->claim_returned(
126
    my $claim = $checkout->claim_returned(
127
        {
127
        {
(-)a/t/db_dependent/Circulation/Returns.t (-22 / +21 lines)
Lines 86-95 subtest "AddReturn logging on statistics table (item-level_itypes=1)" => sub { Link Here
86
    # Create a branch
86
    # Create a branch
87
    $branch = $builder->build({ source => 'Branch' })->{ branchcode };
87
    $branch = $builder->build({ source => 'Branch' })->{ branchcode };
88
    # Create a borrower
88
    # Create a borrower
89
    my $borrowernumber = $builder->build({
89
    my $patron = $builder->build_object({
90
        source => 'Borrower',
90
        class => 'Koha::Patrons',
91
        value => { branchcode => $branch }
91
        value => { branchcode => $branch }
92
    })->{ borrowernumber };
92
    });
93
    # Look for the defined MARC field for biblio-level itemtype
93
    # Look for the defined MARC field for biblio-level itemtype
94
    my $rs = $schema->resultset('MarcSubfieldStructure')->search({
94
    my $rs = $schema->resultset('MarcSubfieldStructure')->search({
95
        frameworkcode => '',
95
        frameworkcode => '',
Lines 118-125 subtest "AddReturn logging on statistics table (item-level_itypes=1)" => sub { Link Here
118
        }
118
        }
119
    )->_result->update({ itype => undef });
119
    )->_result->update({ itype => undef });
120
120
121
    my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
121
    AddIssue( $patron, $item_with_itemtype->barcode );
122
    AddIssue( $borrower, $item_with_itemtype->barcode );
123
    AddReturn( $item_with_itemtype->barcode, $branch );
122
    AddReturn( $item_with_itemtype->barcode, $branch );
124
    # Test item-level itemtype was recorded on the 'statistics' table
123
    # Test item-level itemtype was recorded on the 'statistics' table
125
    my $stat = $schema->resultset('Statistic')->search({
124
    my $stat = $schema->resultset('Statistic')->search({
Lines 130-137 subtest "AddReturn logging on statistics table (item-level_itypes=1)" => sub { Link Here
130
129
131
    is( $stat->itemtype, $ilevel_itemtype,
130
    is( $stat->itemtype, $ilevel_itemtype,
132
        "item-level itype recorded on statistics for return");
131
        "item-level itype recorded on statistics for return");
133
    warning_like { AddIssue( $borrower, $item_without_itemtype->barcode ) }
132
    warning_like { AddIssue( $patron, $item_without_itemtype->barcode ) }
134
                 [qr/^item-level_itypes set but no itemtype set for item/,
133
                 [qr/^item-level_itypes set but no itemtype set for item/,
134
                 qr/^item-level_itypes set but no itemtype set for item/,
135
                 qr/^item-level_itypes set but no itemtype set for item/],
135
                 qr/^item-level_itypes set but no itemtype set for item/],
136
                 'Item without itemtype set raises warning on AddIssue';
136
                 'Item without itemtype set raises warning on AddIssue';
137
    AddReturn( $item_without_itemtype->barcode, $branch );
137
    AddReturn( $item_without_itemtype->barcode, $branch );
Lines 165-172 subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub { Link Here
165
    # Create a branch
165
    # Create a branch
166
    $branch = $builder->build({ source => 'Branch' })->{ branchcode };
166
    $branch = $builder->build({ source => 'Branch' })->{ branchcode };
167
    # Create a borrower
167
    # Create a borrower
168
    my $borrowernumber = $builder->build({
168
    my $patron = $builder->build_object({
169
        source => 'Borrower',
169
        class => 'Koha::Patrons',
170
        value => { branchcode => $branch }
170
        value => { branchcode => $branch }
171
    })->{ borrowernumber };
171
    })->{ borrowernumber };
172
    # Look for the defined MARC field for biblio-level itemtype
172
    # Look for the defined MARC field for biblio-level itemtype
Lines 198-206 subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub { Link Here
198
        }
198
        }
199
    );
199
    );
200
200
201
    my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
201
    AddIssue( $patron, $item_with_itemtype->barcode );
202
203
    AddIssue( $borrower, $item_with_itemtype->barcode );
204
    AddReturn( $item_with_itemtype->barcode, $branch );
202
    AddReturn( $item_with_itemtype->barcode, $branch );
205
    # Test item-level itemtype was recorded on the 'statistics' table
203
    # Test item-level itemtype was recorded on the 'statistics' table
206
    my $stat = $schema->resultset('Statistic')->search({
204
    my $stat = $schema->resultset('Statistic')->search({
Lines 212-218 subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub { Link Here
212
    is( $stat->itemtype, $blevel_itemtype,
210
    is( $stat->itemtype, $blevel_itemtype,
213
        "biblio-level itype recorded on statistics for return");
211
        "biblio-level itype recorded on statistics for return");
214
212
215
    AddIssue( $borrower, $item_without_itemtype->barcode );
213
    AddIssue( $patron, $item_without_itemtype->barcode );
216
    AddReturn( $item_without_itemtype->barcode, $branch );
214
    AddReturn( $item_without_itemtype->barcode, $branch );
217
    # Test biblio-level itemtype was recorded on the 'statistics' table
215
    # Test biblio-level itemtype was recorded on the 'statistics' table
218
    $stat = $schema->resultset('Statistic')->search({
216
    $stat = $schema->resultset('Statistic')->search({
Lines 250-259 subtest 'Handle ids duplication' => sub { Link Here
250
            itype => $itemtype->{itemtype},
248
            itype => $itemtype->{itemtype},
251
        }
249
        }
252
    );
250
    );
253
    my $patron = $builder->build({source => 'Borrower'});
251
    my $patron = $builder->build_object(
254
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
252
        { class => 'Koha::Patrons'}
253
    );
255
254
256
    my $original_checkout = AddIssue( $patron->unblessed, $item->barcode, dt_from_string->subtract( days => 50 ) );
255
    my $original_checkout = AddIssue( $patron, $item->barcode, dt_from_string->subtract( days => 50 ) );
257
    my $issue_id = $original_checkout->issue_id;
256
    my $issue_id = $original_checkout->issue_id;
258
    my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id });
257
    my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id });
259
    is( $account_lines->count, 1, '1 account line should exist for this issue_id' );
258
    is( $account_lines->count, 1, '1 account line should exist for this issue_id' );
Lines 280-286 subtest 'Handle ids duplication' => sub { Link Here
280
    is( $messages->{WasReturned}, 0, 'messages should have the WasReturned flag set to 0' );
279
    is( $messages->{WasReturned}, 0, 'messages should have the WasReturned flag set to 0' );
281
    is( $messages->{DataCorrupted}, 1, 'messages should have the DataCorrupted flag set to 1' );
280
    is( $messages->{DataCorrupted}, 1, 'messages should have the DataCorrupted flag set to 1' );
282
281
283
    $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id });
282
    $account_lines = Koha::Account::Lines->search({ borrowernumber => $borrower->{borrowernumber}, issue_id => $issue_id });
284
    is( $account_lines->count, 0, 'No account lines should exist for this issue_id, patron should not have been charged' );
283
    is( $account_lines->count, 0, 'No account lines should exist for this issue_id, patron should not have been charged' );
285
284
286
    is( Koha::Checkouts->find( $issue_id )->issue_id, $issue_id, 'The issues entry should not have been removed' );
285
    is( Koha::Checkouts->find( $issue_id )->issue_id, $issue_id, 'The issues entry should not have been removed' );
Lines 289-296 subtest 'Handle ids duplication' => sub { Link Here
289
subtest 'BlockReturnOfLostItems' => sub {
288
subtest 'BlockReturnOfLostItems' => sub {
290
    plan tests => 4;
289
    plan tests => 4;
291
    my $item = $builder->build_sample_item;
290
    my $item = $builder->build_sample_item;
292
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
291
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
293
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
292
    my $checkout = AddIssue( $patron, $item->barcode );
294
293
295
    # Mark the item as lost
294
    # Mark the item as lost
296
    $item->itemlost(1)->store;
295
    $item->itemlost(1)->store;
Lines 314-320 subtest 'Checkin of an item claimed as returned should generate a message' => su Link Here
314
    t::lib::Mocks::mock_preference('ClaimReturnedLostValue', 1);
313
    t::lib::Mocks::mock_preference('ClaimReturnedLostValue', 1);
315
    my $item = $builder->build_sample_item;
314
    my $item = $builder->build_sample_item;
316
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
315
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
317
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
316
    my $checkout = AddIssue( $patron, $item->barcode );
318
317
319
    $checkout->claim_returned({ created_by => $patron->id });
318
    $checkout->claim_returned({ created_by => $patron->id });
320
319
Lines 331-342 subtest 'BranchTransferLimitsType' => sub { Link Here
331
330
332
    my $item = $builder->build_sample_item;
331
    my $item = $builder->build_sample_item;
333
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
332
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
334
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
333
    my $checkout = AddIssue( $patron, $item->barcode );
335
    my ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
334
    my ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
336
    is( $doreturn, 1, 'AddReturn should have checkin the item if BranchTransferLimitsType=ccode');
335
    is( $doreturn, 1, 'AddReturn should have checkin the item if BranchTransferLimitsType=ccode');
337
336
338
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
337
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
339
    $checkout = AddIssue( $patron->unblessed, $item->barcode );
338
    $checkout = AddIssue( $patron, $item->barcode );
340
    ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
339
    ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
341
    is( $doreturn, 1, 'AddReturn should have checkin the item if BranchTransferLimitsType=itemtype');
340
    is( $doreturn, 1, 'AddReturn should have checkin the item if BranchTransferLimitsType=itemtype');
342
};
341
};
Lines 350-356 subtest 'Backdated returns should reduce fine if needed' => sub { Link Here
350
    my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
349
    my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
351
    my $item = $builder->build_sample_item;
350
    my $item = $builder->build_sample_item;
352
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
351
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
353
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
352
    my $checkout = AddIssue( $patron, $item->barcode );
354
    my $fine = Koha::Account::Line->new({
353
    my $fine = Koha::Account::Line->new({
355
        issue_id => $checkout->id,
354
        issue_id => $checkout->id,
356
        borrowernumber => $patron->id,
355
        borrowernumber => $patron->id,
(-)a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t (-4 / +3 lines)
Lines 55-61 my $patron = $builder->build_object({ Link Here
55
        categorycode => $patron_category->{categorycode},
55
        categorycode => $patron_category->{categorycode},
56
    },
56
    },
57
});
57
});
58
my $patron_unblessed = $patron->unblessed;
59
58
60
my $item = $builder->build_sample_item(
59
my $item = $builder->build_sample_item(
61
    {
60
    {
Lines 85-91 t::lib::Mocks::mock_userenv({ patron => $patron }); Link Here
85
t::lib::Mocks::mock_preference('AllowTooManyOverride', 0);
84
t::lib::Mocks::mock_preference('AllowTooManyOverride', 0);
86
85
87
# Add onsite checkout
86
# Add onsite checkout
88
C4::Circulation::AddIssue( $patron_unblessed, $item->barcode, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
87
C4::Circulation::AddIssue( $patron, $item->barcode, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
89
88
90
my ( $impossible, $messages );
89
my ( $impossible, $messages );
91
t::lib::Mocks::mock_preference('SwitchOnSiteCheckouts', 0);
90
t::lib::Mocks::mock_preference('SwitchOnSiteCheckouts', 0);
Lines 96-102 t::lib::Mocks::mock_preference('SwitchOnSiteCheckouts', 1); Link Here
96
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $item->barcode );
95
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $item->barcode );
97
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'If SwitchOnSiteCheckouts, switch the on-site checkout' );
96
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'If SwitchOnSiteCheckouts, switch the on-site checkout' );
98
is( exists $impossible->{TOO_MANY}, '', 'If SwitchOnSiteCheckouts, switch the on-site checkout' );
97
is( exists $impossible->{TOO_MANY}, '', 'If SwitchOnSiteCheckouts, switch the on-site checkout' );
99
C4::Circulation::AddIssue( $patron_unblessed, $item->barcode, undef, undef, undef, undef, { switch_onsite_checkout => 1 } );
98
C4::Circulation::AddIssue( $patron, $item->barcode, undef, undef, undef, undef, { switch_onsite_checkout => 1 } );
100
my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
99
my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
101
is( $issue->onsite_checkout, 0, 'The issue should have been switched to a regular checkout' );
100
is( $issue->onsite_checkout, 0, 'The issue should have been switched to a regular checkout' );
102
my $five_days_after = dt_from_string->add( days => 5 )->set( hour => 23, minute => 59, second => 0 );
101
my $five_days_after = dt_from_string->add( days => 5 )->set( hour => 23, minute => 59, second => 0 );
Lines 111-117 my $another_item = $builder->build_sample_item( Link Here
111
    }
110
    }
112
);
111
);
113
112
114
C4::Circulation::AddIssue( $patron_unblessed, $another_item->barcode, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
113
C4::Circulation::AddIssue( $patron, $another_item->barcode, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
115
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->barcode );
114
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->barcode );
116
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 1 - Switch is allowed' );
115
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 1 - Switch is allowed' );
117
is( exists $impossible->{TOO_MANY}, '', 'Specific case 1 - Switch is allowed' );
116
is( exists $impossible->{TOO_MANY}, '', 'Specific case 1 - Switch is allowed' );
(-)a/t/db_dependent/Circulation/TooMany.t (-9 / +8 lines)
Lines 39-45 our $dbh = C4::Context->dbh; Link Here
39
$dbh->do(q|DELETE FROM issues|);
39
$dbh->do(q|DELETE FROM issues|);
40
$dbh->do(q|DELETE FROM items|);
40
$dbh->do(q|DELETE FROM items|);
41
$dbh->do(q|DELETE FROM borrowers|);
41
$dbh->do(q|DELETE FROM borrowers|);
42
$dbh->do(q|DELETE FROM branches|);
42
#$dbh->do(q|DELETE FROM branches|);
43
$dbh->do(q|DELETE FROM categories|);
43
$dbh->do(q|DELETE FROM categories|);
44
$dbh->do(q|DELETE FROM accountlines|);
44
$dbh->do(q|DELETE FROM accountlines|);
45
$dbh->do(q|DELETE FROM itemtypes|);
45
$dbh->do(q|DELETE FROM itemtypes|);
Lines 56-63 my $category = $builder->build({ Link Here
56
    source => 'Category',
56
    source => 'Category',
57
});
57
});
58
58
59
my $patron = $builder->build({
59
my $patron = $builder->build_object({
60
    source => 'Borrower',
60
    class => 'Koha::Patrons',
61
    value => {
61
    value => {
62
        categorycode => $category->{categorycode},
62
        categorycode => $category->{categorycode},
63
        branchcode => $branch->{branchcode},
63
        branchcode => $branch->{branchcode},
Lines 71-78 my $item = $builder->build_sample_item({ Link Here
71
    holdingbranch => $branch->{branchcode},
71
    holdingbranch => $branch->{branchcode},
72
});
72
});
73
73
74
my $patron_object = Koha::Patrons->find( $patron->{borrowernumber} );
74
t::lib::Mocks::mock_userenv( { patron => $patron });
75
t::lib::Mocks::mock_userenv( { patron => $patron_object });
76
75
77
# TooMany return ($current_loan_count, $max_loans_allowed) or undef
76
# TooMany return ($current_loan_count, $max_loans_allowed) or undef
78
# CO = Checkout
77
# CO = Checkout
Lines 482-489 subtest 'General vs specific rules limit quantity correctly' => sub { Link Here
482
            notforloan => 0,
481
            notforloan => 0,
483
        }
482
        }
484
    });
483
    });
485
    my $patron = $builder->build({
484
    my $patron = $builder->build_object({
486
        source => 'Borrower',
485
        class => 'Koha::Patrons',
487
        value => {
486
        value => {
488
            categorycode => $category->{categorycode},
487
            categorycode => $category->{categorycode},
489
            branchcode => $branch->{branchcode},
488
            branchcode => $branch->{branchcode},
Lines 772-780 subtest 'itemtype group tests' => sub { Link Here
772
771
773
    my $branch   = $builder->build( { source => 'Branch', } );
772
    my $branch   = $builder->build( { source => 'Branch', } );
774
    my $category = $builder->build( { source => 'Category', } );
773
    my $category = $builder->build( { source => 'Category', } );
775
    my $patron   = $builder->build(
774
    my $patron   = $builder->build_object(
776
        {
775
        {
777
            source => 'Borrower',
776
            class => 'Koha::Patrons',
778
            value  => {
777
            value  => {
779
                categorycode => $category->{categorycode},
778
                categorycode => $category->{categorycode},
780
                branchcode   => $branch->{branchcode},
779
                branchcode   => $branch->{branchcode},
(-)a/t/db_dependent/Circulation/dateexpiry.t (-9 / +11 lines)
Lines 91-115 sub calc_date_due { Link Here
91
91
92
    # this triggers the compare between expiry and due date
92
    # this triggers the compare between expiry and due date
93
93
94
    my $patron = $builder->build({
94
    my $patron = $builder->build_object(
95
        source => 'Borrower',
95
        {
96
        value  => {
96
            class  => 'Koha::Patrons',
97
            categorycode => $patron_category->{categorycode},
97
            value  => {
98
                categorycode => $patron_category->{categorycode},
99
            }
98
        }
100
        }
99
    });
101
    );
100
    my $item   = $builder->build_sample_item;
102
    my $item   = $builder->build_sample_item;
101
    my $branch = $builder->build( { source => 'Branch' } );
103
    my $branch = $builder->build( { source => 'Branch' } );
102
    my $today  = dt_from_string();
104
    my $today  = dt_from_string();
103
105
104
    # first test with empty expiry date
106
    # first test with empty expiry date
105
    # note that this expiry date will never lead to an issue btw !!
107
    # note that this expiry date will never lead to an issue btw !!
106
    $patron->{dateexpiry} = undef;
108
    $patron->dateexpiry(undef)->store;
107
    my $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
109
    my $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
108
    is( ref $d eq "DateTime" && $d->mdy() =~ /^\d+/, 1, "CalcDateDue with expiry undef" );
110
    is( ref $d eq "DateTime" && $d->mdy() =~ /^\d+/, 1, "CalcDateDue with expiry undef" );
109
111
110
    # second test expiry date==today
112
    # second test expiry date==today
111
    my $d2 = output_pref( { dt => $today, dateonly => 1, dateformat => 'sql' } );
113
    my $d2 = output_pref( { dt => $today, dateonly => 1, dateformat => 'sql' } );
112
    $patron->{dateexpiry} = $d2;
114
    $patron->dateexpiry($d2)->store;
113
    $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
115
    $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
114
    is( ref $d eq "DateTime" && DateTime->compare( $d->truncate( to => 'day' ), $today->truncate( to => 'day' ) ) == 0, 1, "CalcDateDue with expiry today" );
116
    is( ref $d eq "DateTime" && DateTime->compare( $d->truncate( to => 'day' ), $today->truncate( to => 'day' ) ) == 0, 1, "CalcDateDue with expiry today" );
115
117
Lines 117-128 sub calc_date_due { Link Here
117
    my $dur = DateTime::Duration->new( days => 1 );
119
    my $dur = DateTime::Duration->new( days => 1 );
118
    my $tomorrow = $today->clone->add_duration($dur);
120
    my $tomorrow = $today->clone->add_duration($dur);
119
    $d2 = output_pref( { dt => $tomorrow, dateonly => 1, dateformat => 'sql' } );
121
    $d2 = output_pref( { dt => $tomorrow, dateonly => 1, dateformat => 'sql' } );
120
    $patron->{dateexpiry} = $d2;
122
    $patron->dateexpiry($d2)->store;
121
    $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
123
    $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
122
    is( ref $d eq "DateTime" && $d->mdy() =~ /^\d+/, 1, "CalcDateDue with expiry tomorrow" );
124
    is( ref $d eq "DateTime" && $d->mdy() =~ /^\d+/, 1, "CalcDateDue with expiry tomorrow" );
123
125
124
    # fourth test far future
126
    # fourth test far future
125
    $patron->{dateexpiry} = '9876-12-31';
127
    $patron->dateexpiry('9876-12-31')->store;
126
    my $t1 = time;
128
    my $t1 = time;
127
    $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
129
    $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
128
    my $t2 = time;
130
    my $t2 = time;
(-)a/t/db_dependent/Circulation/issue.t (-13 / +11 lines)
Lines 160-166 my $borrower_id1 = Koha::Patron->new({ Link Here
160
    branchcode   => $branchcode_1
160
    branchcode   => $branchcode_1
161
})->store->borrowernumber;
161
})->store->borrowernumber;
162
my $patron_1 = Koha::Patrons->find( $borrower_id1 );
162
my $patron_1 = Koha::Patrons->find( $borrower_id1 );
163
my $borrower_1 = $patron_1->unblessed;
164
my $borrower_id2 = Koha::Patron->new({
163
my $borrower_id2 = Koha::Patron->new({
165
    firstname    => 'firstname2',
164
    firstname    => 'firstname2',
166
    surname      => 'surname2 ',
165
    surname      => 'surname2 ',
Lines 168-174 my $borrower_id2 = Koha::Patron->new({ Link Here
168
    branchcode   => $branchcode_2,
167
    branchcode   => $branchcode_2,
169
})->store->borrowernumber;
168
})->store->borrowernumber;
170
my $patron_2 = Koha::Patrons->find( $borrower_id2 );
169
my $patron_2 = Koha::Patrons->find( $borrower_id2 );
171
my $borrower_2 = $patron_2->unblessed;
172
170
173
t::lib::Mocks::mock_userenv({ patron => $patron_1 });
171
t::lib::Mocks::mock_userenv({ patron => $patron_1 });
174
172
Lines 178-186 t::lib::Mocks::mock_userenv({ patron => $patron_1 }); Link Here
178
my $query = " SELECT count(*) FROM issues";
176
my $query = " SELECT count(*) FROM issues";
179
my $sth = $dbh->prepare($query);
177
my $sth = $dbh->prepare($query);
180
$sth->execute;
178
$sth->execute;
181
my $countissue = $sth -> fetchrow_array;
179
my $countissue = $sth->fetchrow_array;
182
is ($countissue ,0, "there is no issue");
180
is ($countissue ,0, "there is no issue");
183
my $issue1 = C4::Circulation::AddIssue( $borrower_1, $barcode_1, $daysago10,0, $today, '' );
181
my $issue1 = C4::Circulation::AddIssue( $patron_1, $barcode_1, $daysago10, 0, $today, '' );
184
is( ref $issue1, 'Koha::Checkout',
182
is( ref $issue1, 'Koha::Checkout',
185
       'AddIssue returns a Koha::Checkout object' );
183
       'AddIssue returns a Koha::Checkout object' );
186
my $datedue1 = dt_from_string( $issue1->date_due() );
184
my $datedue1 = dt_from_string( $issue1->date_due() );
Lines 191-201 like( Link Here
191
);
189
);
192
my $issue_id1 = $issue1->issue_id;
190
my $issue_id1 = $issue1->issue_id;
193
191
194
my $issue2 = C4::Circulation::AddIssue( $borrower_1, 'nonexistent_barcode' );
192
my $issue2 = C4::Circulation::AddIssue( $patron_1, 'nonexistent_barcode' );
195
is( $issue2, undef, "AddIssue returns undef if no datedue is specified" );
193
is( $issue2, undef, "AddIssue returns undef if no datedue is specified" );
196
194
197
$sth->execute;
195
$sth->execute;
198
$countissue = $sth -> fetchrow_array;
196
$countissue = $sth->fetchrow_array;
199
is ($countissue,1,"1 issues have been added");
197
is ($countissue,1,"1 issues have been added");
200
198
201
#Test AddIssuingCharge
199
#Test AddIssuingCharge
Lines 263-269 subtest 'Show that AddRenewal respects OpacRenewalBranch and interface' => sub { Link Here
263
            my $item = $builder->build_sample_item(
261
            my $item = $builder->build_sample_item(
264
                { library => $item_library->branchcode, itype => $itemtype } );
262
                { library => $item_library->branchcode, itype => $itemtype } );
265
            my $opac_renew_issue =
263
            my $opac_renew_issue =
266
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
264
              C4::Circulation::AddIssue( $patron, $item->barcode );
267
265
268
            AddRenewal( $patron->borrowernumber, $item->itemnumber,
266
            AddRenewal( $patron->borrowernumber, $item->itemnumber,
269
                "Stavromula", $datedue1, $daysago10 );
267
                "Stavromula", $datedue1, $daysago10 );
Lines 281-287 subtest 'Show that AddRenewal respects OpacRenewalBranch and interface' => sub { Link Here
281
            my $item = $builder->build_sample_item(
279
            my $item = $builder->build_sample_item(
282
                { library => $item_library->branchcode, itype => $itemtype } );
280
                { library => $item_library->branchcode, itype => $itemtype } );
283
            my $opac_renew_issue =
281
            my $opac_renew_issue =
284
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
282
              C4::Circulation::AddIssue( $patron, $item->barcode );
285
283
286
            AddRenewal( $patron->borrowernumber, $item->itemnumber,
284
            AddRenewal( $patron->borrowernumber, $item->itemnumber,
287
                "Stavromula", $datedue1, $daysago10 );
285
                "Stavromula", $datedue1, $daysago10 );
Lines 298-304 subtest 'Show that AddRenewal respects OpacRenewalBranch and interface' => sub { Link Here
298
296
299
my @renewcount;
297
my @renewcount;
300
#Test GetRenewCount
298
#Test GetRenewCount
301
my $issue3 = C4::Circulation::AddIssue( $borrower_1, $barcode_1 );
299
my $issue3 = C4::Circulation::AddIssue( $patron_1, $barcode_1 );
302
#Without anything in DB
300
#Without anything in DB
303
@renewcount = C4::Circulation::GetRenewCount();
301
@renewcount = C4::Circulation::GetRenewCount();
304
is_deeply(
302
is_deeply(
Lines 372-378 my $return = $dbh->selectrow_hashref("SELECT DATE(returndate) AS return_date, CU Link Here
372
ok( $return->{return_date} eq $return->{today}, "Item returned with no return date specified has todays date" );
370
ok( $return->{return_date} eq $return->{today}, "Item returned with no return date specified has todays date" );
373
371
374
$dbh->do("DELETE FROM old_issues");
372
$dbh->do("DELETE FROM old_issues");
375
C4::Circulation::AddIssue( $borrower_1, $barcode_1, $daysago10, 0, $today );
373
C4::Circulation::AddIssue( $patron_1, $barcode_1, $daysago10, 0, $today );
376
AddReturn($barcode_1, undef, undef, dt_from_string('2014-04-01 23:42'));
374
AddReturn($barcode_1, undef, undef, dt_from_string('2014-04-01 23:42'));
377
$return = $dbh->selectrow_hashref("SELECT * FROM old_issues LIMIT 1" );
375
$return = $dbh->selectrow_hashref("SELECT * FROM old_issues LIMIT 1" );
378
ok( $return->{returndate} eq '2014-04-01 23:42:00', "Item returned with a return date of '2014-04-01 23:42' has that return date" );
376
ok( $return->{returndate} eq '2014-04-01 23:42:00', "Item returned with a return date of '2014-04-01 23:42' has that return date" );
Lines 452-458 $item2 = Koha::Items->find( $itemnumber2 ); Link Here
452
ok( $item2->location eq 'CART', q{UpdateItemLocationOnCheckin updates location value from 'GEN' with setting "_ALL_: CART" when transfer filled} );
450
ok( $item2->location eq 'CART', q{UpdateItemLocationOnCheckin updates location value from 'GEN' with setting "_ALL_: CART" when transfer filled} );
453
451
454
ok( $item2->permanent_location eq 'GEN', q{UpdateItemLocationOnCheckin does not update permanent_location value from 'GEN' with setting "_ALL_: CART"} );
452
ok( $item2->permanent_location eq 'GEN', q{UpdateItemLocationOnCheckin does not update permanent_location value from 'GEN' with setting "_ALL_: CART"} );
455
AddIssue( $borrower_1, 'barcode_4', $daysago10,0, $today, '' );
453
AddIssue( $patron_1, 'barcode_4', $daysago10,0, $today, '' );
456
$item2 = Koha::Items->find( $itemnumber2 );
454
$item2 = Koha::Items->find( $itemnumber2 );
457
ok( $item2->location eq 'GEN', q{Location updates from 'CART' to permanent location on issue} );
455
ok( $item2->location eq 'GEN', q{Location updates from 'CART' to permanent location on issue} );
458
456
Lines 501-507 my $reserve_id = AddReserve( Link Here
501
    }
499
    }
502
);
500
);
503
ok( $reserve_id, 'The reserve should have been inserted' );
501
ok( $reserve_id, 'The reserve should have been inserted' );
504
AddIssue( $borrower_2, $barcode_1, dt_from_string, 'cancel' );
502
AddIssue( $patron_2, $barcode_1, dt_from_string, 'cancel' );
505
my $hold = Koha::Holds->find( $reserve_id );
503
my $hold = Koha::Holds->find( $reserve_id );
506
is( $hold, undef, 'The reserve should have been correctly cancelled' );
504
is( $hold, undef, 'The reserve should have been correctly cancelled' );
507
505
Lines 524-530 my $unseen_library = $builder->build_object( { class => 'Koha::Libraries' } ); Link Here
524
my $unseen_patron  = $builder->build_object( { class => 'Koha::Patrons' } );
522
my $unseen_patron  = $builder->build_object( { class => 'Koha::Patrons' } );
525
my $unseen_item = $builder->build_sample_item(
523
my $unseen_item = $builder->build_sample_item(
526
    { library => $unseen_library->branchcode, itype => $itemtype } );
524
    { library => $unseen_library->branchcode, itype => $itemtype } );
527
my $unseen_issue = C4::Circulation::AddIssue( $unseen_patron->unblessed, $unseen_item->barcode );
525
my $unseen_issue = C4::Circulation::AddIssue( $unseen_patron, $unseen_item->barcode );
528
526
529
# Does an unseen renewal increment the issue's count
527
# Does an unseen renewal increment the issue's count
530
my ( $unseen_before ) = ( C4::Circulation::GetRenewCount( $unseen_patron->borrowernumber, $unseen_item->itemnumber ) )[3];
528
my ( $unseen_before ) = ( C4::Circulation::GetRenewCount( $unseen_patron->borrowernumber, $unseen_item->itemnumber ) )[3];
(-)a/t/db_dependent/Circulation/maxsuspensiondays.t (-7 / +6 lines)
Lines 42-54 Koha::CirculationRules->set_rules( Link Here
42
    }
42
    }
43
);
43
);
44
44
45
my $borrowernumber = Koha::Patron->new({
45
my $patron = Koha::Patron->new({
46
    firstname =>  'my firstname',
46
    firstname =>  'my firstname',
47
    surname => 'my surname',
47
    surname => 'my surname',
48
    categorycode => $patron_category->{categorycode},
48
    categorycode => $patron_category->{categorycode},
49
    branchcode => $branchcode,
49
    branchcode => $branchcode,
50
})->store->borrowernumber;
50
})->store;
51
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
52
51
53
my $record = MARC::Record->new();
52
my $record = MARC::Record->new();
54
$record->append_fields(
53
$record->append_fields(
Lines 74-82 $dbh->do('DELETE FROM repeatable_holidays'); Link Here
74
my $daysago20 = dt_from_string->add_duration(DateTime::Duration->new(days => -20));
73
my $daysago20 = dt_from_string->add_duration(DateTime::Duration->new(days => -20));
75
my $daysafter40 = dt_from_string->add_duration(DateTime::Duration->new(days => 40));
74
my $daysafter40 = dt_from_string->add_duration(DateTime::Duration->new(days => 40));
76
75
77
AddIssue( $borrower, $barcode, $daysago20 );
76
AddIssue( $patron, $barcode, $daysago20 );
78
AddReturn( $barcode, $branchcode );
77
AddReturn( $barcode, $branchcode );
79
my $debarments = GetDebarments({borrowernumber => $borrower->{borrowernumber}});
78
my $debarments = GetDebarments({borrowernumber => $patron->borrowernumber});
80
is(
79
is(
81
    $debarments->[0]->{expiration},
80
    $debarments->[0]->{expiration},
82
    output_pref({ dt => $daysafter40, dateformat => 'iso', dateonly => 1 }),
81
    output_pref({ dt => $daysafter40, dateformat => 'iso', dateonly => 1 }),
Lines 97-105 Koha::CirculationRules->set_rules( Link Here
97
);
96
);
98
97
99
my $daysafter10 = dt_from_string->add_duration(DateTime::Duration->new(days => 10));
98
my $daysafter10 = dt_from_string->add_duration(DateTime::Duration->new(days => 10));
100
AddIssue( $borrower, $barcode, $daysago20 );
99
AddIssue( $patron, $barcode, $daysago20 );
101
AddReturn( $barcode, $branchcode );
100
AddReturn( $barcode, $branchcode );
102
$debarments = GetDebarments({borrowernumber => $borrower->{borrowernumber}});
101
$debarments = GetDebarments({borrowernumber => $patron->borrowernumber});
103
is(
102
is(
104
    $debarments->[0]->{expiration},
103
    $debarments->[0]->{expiration},
105
    output_pref({ dt => $daysafter10, dateformat => 'iso', dateonly => 1 }),
104
    output_pref({ dt => $daysafter10, dateformat => 'iso', dateonly => 1 }),
(-)a/t/db_dependent/Circulation/transferbook.t (-3 / +8 lines)
Lines 116-124 subtest 'transfer already at destination' => sub { Link Here
116
        }
116
        }
117
    );
117
    );
118
118
119
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' })->store->itemtype;
119
    my $item = $builder->build_sample_item(
120
    my $item = $builder->build_sample_item(
120
        {
121
        {
121
            library => $library->branchcode,
122
            library => $library->branchcode,
123
            itype => $itemtype
122
        }
124
        }
123
    );
125
    );
124
126
Lines 169-175 subtest 'transfer already at destination' => sub { Link Here
169
    is( $dotransfer, 0, 'Do not transfer recalled item, it has already arrived' );
171
    is( $dotransfer, 0, 'Do not transfer recalled item, it has already arrived' );
170
    is( $messages->{RecallPlacedAtHoldingBranch}, 1, "We found the recall");
172
    is( $messages->{RecallPlacedAtHoldingBranch}, 1, "We found the recall");
171
173
172
    my $item2 = $builder->build_object({ class => 'Koha::Items' }); # this item will have a different holding branch to the pickup branch
174
    $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' })->store->itemtype;
175
    my $item2 = $builder->build_object({ class => 'Koha::Items', value => { itype => $itemtype } }); # this item will have a different holding branch to the pickup branch
173
    $recall = Koha::Recall->new(
176
    $recall = Koha::Recall->new(
174
        {   biblio_id         => $item2->biblionumber,
177
        {   biblio_id         => $item2->biblionumber,
175
            item_id           => $item2->itemnumber,
178
            item_id           => $item2->itemnumber,
Lines 196-209 subtest 'transfer an issued item' => sub { Link Here
196
        }
199
        }
197
    );
200
    );
198
201
202
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' })->store->itemtype;
199
    my $item = $builder->build_sample_item(
203
    my $item = $builder->build_sample_item(
200
        {
204
        {
201
            library => $library->branchcode,
205
            library => $library->branchcode,
206
            itype => $itemtype
202
        }
207
        }
203
    );
208
    );
204
209
205
    my $dt_to = dt_from_string();
210
    my $dt_to = dt_from_string();
206
    my $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to );
211
    my $issue = AddIssue( $patron, $item->barcode, $dt_to );
207
212
208
    # We are making sure there is no regression, feel free to change the behavior if needed.
213
    # We are making sure there is no regression, feel free to change the behavior if needed.
209
    # * WasReturned does not seem like a variable that should contain a borrowernumber
214
    # * WasReturned does not seem like a variable that should contain a borrowernumber
Lines 217-223 subtest 'transfer an issued item' => sub { Link Here
217
    is( $messages->{WasReturned}, $patron->borrowernumber, 'transferbook should have return a WasReturned flag is the item was issued before the transferbook call');
222
    is( $messages->{WasReturned}, $patron->borrowernumber, 'transferbook should have return a WasReturned flag is the item was issued before the transferbook call');
218
223
219
    # Reset issue
224
    # Reset issue
220
    $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to );
225
    $issue = AddIssue( $patron, $item->barcode, $dt_to );
221
226
222
    # We are making sure there is no regression, feel free to change the behavior if needed.
227
    # We are making sure there is no regression, feel free to change the behavior if needed.
223
    # * Contrary to the POD, if ignore_reserves is not passed (or is false), any item reserve
228
    # * Contrary to the POD, if ignore_reserves is not passed (or is false), any item reserve
(-)a/t/db_dependent/Circulation_holdsqueue.t (-2 / +2 lines)
Lines 58-64 subtest 'AddIssue() and AddReturn() real-time holds queue tests' => sub { Link Here
58
    } );
58
    } );
59
59
60
    $action = 'AddIssue';
60
    $action = 'AddIssue';
61
    AddIssue( $patron->unblessed, $item->barcode, );
61
    AddIssue( $patron, $item->barcode, );
62
62
63
    $action = 'AddReturn';
63
    $action = 'AddReturn';
64
    AddReturn( $item->barcode );
64
    AddReturn( $item->barcode );
Lines 66-72 subtest 'AddIssue() and AddReturn() real-time holds queue tests' => sub { Link Here
66
    t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
66
    t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
67
67
68
    $action = 'AddIssue';
68
    $action = 'AddIssue';
69
    AddIssue( $patron->unblessed, $item->barcode, );
69
    AddIssue( $patron, $item->barcode, );
70
70
71
    $action = 'AddReturn';
71
    $action = 'AddReturn';
72
    AddReturn( $item->barcode );
72
    AddReturn( $item->barcode );
(-)a/t/db_dependent/DecreaseLoanHighHolds.t (-1 / +1 lines)
Lines 118-124 my $orig_due = C4::Circulation::CalcDateDue( Link Here
118
    dt_from_string(),
118
    dt_from_string(),
119
    $item->effective_itemtype,
119
    $item->effective_itemtype,
120
    $patron->branchcode,
120
    $patron->branchcode,
121
    $patron->unblessed
121
    $patron
122
);
122
);
123
123
124
t::lib::Mocks::mock_preference( 'decreaseLoanHighHolds',               1 );
124
t::lib::Mocks::mock_preference( 'decreaseLoanHighHolds',               1 );
(-)a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t (-3 / +3 lines)
Lines 104-110 is( $is, 1, "Items availability: both of 2 items are available" ); Link Here
104
$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
104
$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
105
is( $is, 0, "Item cannot be held, 2 items available" );
105
is( $is, 0, "Item cannot be held, 2 items available" );
106
106
107
my $issue1 = AddIssue( $patron2->unblessed, $item1->barcode );
107
my $issue1 = AddIssue( $patron2, $item1->barcode );
108
108
109
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
109
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
110
is( $is, 1, "Items availability: one item is available" );
110
is( $is, 1, "Items availability: one item is available" );
Lines 112-118 is( $is, 1, "Items availability: one item is available" ); Link Here
112
$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
112
$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
113
is( $is, 0, "Item cannot be held, 1 item available" );
113
is( $is, 0, "Item cannot be held, 1 item available" );
114
114
115
AddIssue( $patron2->unblessed, $item2->barcode );
115
AddIssue( $patron2, $item2->barcode );
116
116
117
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
117
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
118
is( $is, 0, "Items availability: none of items are available" );
118
is( $is, 0, "Items availability: none of items are available" );
Lines 379-385 subtest 'Check holds availability with different item types' => sub { Link Here
379
    $is = IsAvailableForItemLevelRequest( $item5, $patron1 );
379
    $is = IsAvailableForItemLevelRequest( $item5, $patron1 );
380
    is( $is, 0, "Item5 cannot be requested to hold: 2 items, Item4 available, Item5 restricted" );
380
    is( $is, 0, "Item5 cannot be requested to hold: 2 items, Item4 available, Item5 restricted" );
381
381
382
    AddIssue( $patron2->unblessed, $item4->barcode );
382
    AddIssue( $patron2, $item4->barcode );
383
383
384
    $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblio2->biblionumber, patron => $patron1 } );
384
    $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblio2->biblionumber, patron => $patron1 } );
385
    is( $is, 0, "Items availability: 2 items, one allowed by smart rule and checked out, another one not allowed to be held by smart rule" );
385
    is( $is, 0, "Items availability: 2 items, one allowed by smart rule and checked out, another one not allowed to be held by smart rule" );
(-)a/t/db_dependent/Holds/RevertWaitingStatus.t (-3 / +2 lines)
Lines 82-90 foreach my $borrowernumber (@borrowernumbers) { Link Here
82
}
82
}
83
83
84
ModReserveAffect( $itemnumber, $borrowernumbers[0] );
84
ModReserveAffect( $itemnumber, $borrowernumbers[0] );
85
my $patron = Koha::Patrons->find( $borrowernumbers[1] )->unblessed;
85
my $patron = Koha::Patrons->find( $borrowernumbers[1] );
86
C4::Circulation::AddIssue( $patron,
86
C4::Circulation::AddIssue( $patron, $item_barcode, undef, 'revert' );
87
    $item_barcode, my $datedue, my $cancelreserve = 'revert' );
88
87
89
my $priorities = $dbh->selectall_arrayref(
88
my $priorities = $dbh->selectall_arrayref(
90
    "SELECT priority FROM reserves ORDER BY priority ASC");
89
    "SELECT priority FROM reserves ORDER BY priority ASC");
(-)a/t/db_dependent/ILSDI_Services.t (-26 / +24 lines)
Lines 325-333 subtest 'Holds test' => sub { Link Here
325
325
326
    t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 );
326
    t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 );
327
327
328
    my $patron = $builder->build({
328
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
329
        source => 'Borrower',
330
    });
331
329
332
    my $item = $builder->build_sample_item(
330
    my $item = $builder->build_sample_item(
333
        {
331
        {
Lines 336-342 subtest 'Holds test' => sub { Link Here
336
    );
334
    );
337
335
338
    my $query = CGI->new;
336
    my $query = CGI->new;
339
    $query->param( 'patron_id', $patron->{borrowernumber});
337
    $query->param( 'patron_id', $patron->borrowernumber);
340
    $query->param( 'bib_id', $item->biblionumber);
338
    $query->param( 'bib_id', $item->biblionumber);
341
339
342
    my $reply = C4::ILSDI::Services::HoldTitle( $query );
340
    my $reply = C4::ILSDI::Services::HoldTitle( $query );
Lines 347-353 subtest 'Holds test' => sub { Link Here
347
    my $hold = $builder->build({
345
    my $hold = $builder->build({
348
        source => 'Reserve',
346
        source => 'Reserve',
349
        value => {
347
        value => {
350
            borrowernumber => $patron->{borrowernumber},
348
            borrowernumber => $patron->borrowernumber,
351
            biblionumber => $item->biblionumber,
349
            biblionumber => $item->biblionumber,
352
            itemnumber => $item->itemnumber
350
            itemnumber => $item->itemnumber
353
        }
351
        }
Lines 359-365 subtest 'Holds test' => sub { Link Here
359
    my $biblio_with_no_item = $builder->build_sample_biblio;
357
    my $biblio_with_no_item = $builder->build_sample_biblio;
360
358
361
    $query = CGI->new;
359
    $query = CGI->new;
362
    $query->param( 'patron_id', $patron->{borrowernumber});
360
    $query->param( 'patron_id', $patron->borrowernumber);
363
    $query->param( 'bib_id', $biblio_with_no_item->biblionumber);
361
    $query->param( 'bib_id', $biblio_with_no_item->biblionumber);
364
362
365
    $reply = C4::ILSDI::Services::HoldTitle( $query );
363
    $reply = C4::ILSDI::Services::HoldTitle( $query );
Lines 374-389 subtest 'Holds test' => sub { Link Here
374
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
372
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
375
    Koha::CirculationRules->set_rule(
373
    Koha::CirculationRules->set_rule(
376
        {
374
        {
377
            categorycode => $patron->{categorycode},
375
            categorycode => $patron->categorycode,
378
            itemtype     => $item2->{itype},
376
            itemtype     => $item2->{itype},
379
            branchcode   => $patron->{branchcode},
377
            branchcode   => $patron->branchcode,
380
            rule_name    => 'reservesallowed',
378
            rule_name    => 'reservesallowed',
381
            rule_value   => 1,
379
            rule_value   => 1,
382
        }
380
        }
383
    );
381
    );
384
382
385
    $query = CGI->new;
383
    $query = CGI->new;
386
    $query->param( 'patron_id', $patron->{borrowernumber});
384
    $query->param( 'patron_id', $patron->borrowernumber);
387
    $query->param( 'bib_id', $item2->biblionumber);
385
    $query->param( 'bib_id', $item2->biblionumber);
388
    $query->param( 'item_id', $item2->itemnumber);
386
    $query->param( 'item_id', $item2->itemnumber);
389
387
Lines 392-407 subtest 'Holds test' => sub { Link Here
392
390
393
    Koha::CirculationRules->set_rule(
391
    Koha::CirculationRules->set_rule(
394
        {
392
        {
395
            categorycode => $patron->{categorycode},
393
            categorycode => $patron->categorycode,
396
            itemtype     => $item2->{itype},
394
            itemtype     => $item2->{itype},
397
            branchcode   => $patron->{branchcode},
395
            branchcode   => $patron->branchcode,
398
            rule_name    => 'reservesallowed',
396
            rule_name    => 'reservesallowed',
399
            rule_value   => 0,
397
            rule_value   => 0,
400
        }
398
        }
401
    );
399
    );
402
400
403
    $query = CGI->new;
401
    $query = CGI->new;
404
    $query->param( 'patron_id', $patron->{borrowernumber});
402
    $query->param( 'patron_id', $patron->borrowernumber);
405
    $query->param( 'bib_id', $item2->biblionumber);
403
    $query->param( 'bib_id', $item2->biblionumber);
406
    $query->param( 'item_id', $item2->itemnumber);
404
    $query->param( 'item_id', $item2->itemnumber);
407
405
Lines 433-448 subtest 'Holds test' => sub { Link Here
433
431
434
    Koha::CirculationRules->set_rule(
432
    Koha::CirculationRules->set_rule(
435
        {
433
        {
436
            categorycode => $patron->{categorycode},
434
            categorycode => $patron->categorycode,
437
            itemtype     => $item3->{itype},
435
            itemtype     => $item3->{itype},
438
            branchcode   => $patron->{branchcode},
436
            branchcode   => $patron->branchcode,
439
            rule_name    => 'reservesallowed',
437
            rule_name    => 'reservesallowed',
440
            rule_value   => 10,
438
            rule_value   => 10,
441
        }
439
        }
442
    );
440
    );
443
441
444
    $query = CGI->new;
442
    $query = CGI->new;
445
    $query->param( 'patron_id', $patron->{borrowernumber});
443
    $query->param( 'patron_id', $patron->borrowernumber);
446
    $query->param( 'bib_id', $item4->biblionumber);
444
    $query->param( 'bib_id', $item4->biblionumber);
447
    $query->param( 'item_id', $item4->itemnumber);
445
    $query->param( 'item_id', $item4->itemnumber);
448
446
Lines 450-461 subtest 'Holds test' => sub { Link Here
450
    is( $reply->{code}, 'damaged', "Item is damaged" );
448
    is( $reply->{code}, 'damaged', "Item is damaged" );
451
449
452
    my $module = Test::MockModule->new('C4::Context');
450
    my $module = Test::MockModule->new('C4::Context');
453
    $module->mock('userenv', sub { { patron => $patron } });
451
    $module->mock('userenv', sub { { patron => $patron->unblessed } });
454
    my $issue = C4::Circulation::AddIssue($patron, $item3->barcode);
452
    my $issue = C4::Circulation::AddIssue($patron, $item3->barcode);
455
    t::lib::Mocks::mock_preference( 'AllowHoldsOnPatronsPossessions', '0' );
453
    t::lib::Mocks::mock_preference( 'AllowHoldsOnPatronsPossessions', '0' );
456
454
457
    $query = CGI->new;
455
    $query = CGI->new;
458
    $query->param( 'patron_id', $patron->{borrowernumber});
456
    $query->param( 'patron_id', $patron->borrowernumber);
459
    $query->param( 'bib_id', $item3->biblionumber);
457
    $query->param( 'bib_id', $item3->biblionumber);
460
    $query->param( 'item_id', $item3->itemnumber);
458
    $query->param( 'item_id', $item3->itemnumber);
461
    $query->param( 'pickup_location', $origin_branch->{branchcode});
459
    $query->param( 'pickup_location', $origin_branch->{branchcode});
Lines 511-518 subtest 'Holds test for branch transfer limits' => sub { Link Here
511
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' );
509
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' );
512
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
510
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
513
511
514
    my $patron = $builder->build({
512
    my $patron = $builder->build_object({
515
        source => 'Borrower',
513
        class => 'Koha::Patrons',
516
    });
514
    });
517
515
518
    my $origin_branch = $builder->build(
516
    my $origin_branch = $builder->build(
Lines 556-562 subtest 'Holds test for branch transfer limits' => sub { Link Here
556
554
557
    my $query = CGI->new;
555
    my $query = CGI->new;
558
    $query->param( 'pickup_location', $pickup_branch->{branchcode} );
556
    $query->param( 'pickup_location', $pickup_branch->{branchcode} );
559
    $query->param( 'patron_id', $patron->{borrowernumber});
557
    $query->param( 'patron_id', $patron->borrowernumber);
560
    $query->param( 'bib_id', $item->biblionumber);
558
    $query->param( 'bib_id', $item->biblionumber);
561
    $query->param( 'item_id', $item->itemnumber);
559
    $query->param( 'item_id', $item->itemnumber);
562
560
Lines 570-583 subtest 'Holds test for branch transfer limits' => sub { Link Here
570
568
571
    $reply = C4::ILSDI::Services::HoldItem( $query );
569
    $reply = C4::ILSDI::Services::HoldItem( $query );
572
    is( $reply->{code}, undef, "Item hold, Item can be transferred" );
570
    is( $reply->{code}, undef, "Item hold, Item can be transferred" );
573
    my $hold = Koha::Holds->search({ itemnumber => $item->itemnumber, borrowernumber => $patron->{borrowernumber} })->next;
571
    my $hold = Koha::Holds->search({ itemnumber => $item->itemnumber, borrowernumber => $patron->borrowernumber })->next;
574
    is( $hold->branchcode, $pickup_branch->{branchcode}, 'The library id is correctly set' );
572
    is( $hold->branchcode, $pickup_branch->{branchcode}, 'The library id is correctly set' );
575
573
576
    Koha::Holds->search()->delete();
574
    Koha::Holds->search()->delete();
577
575
578
    $reply = C4::ILSDI::Services::HoldTitle( $query );
576
    $reply = C4::ILSDI::Services::HoldTitle( $query );
579
    is( $reply->{code}, undef, "Record hold, Item con be transferred" );
577
    is( $reply->{code}, undef, "Record hold, Item con be transferred" );
580
    $hold = Koha::Holds->search({ biblionumber => $item->biblionumber, borrowernumber => $patron->{borrowernumber} })->next;
578
    $hold = Koha::Holds->search({ biblionumber => $item->biblionumber, borrowernumber => $patron->borrowernumber })->next;
581
    is( $hold->branchcode, $pickup_branch->{branchcode}, 'The library id is correctly set' );
579
    is( $hold->branchcode, $pickup_branch->{branchcode}, 'The library id is correctly set' );
582
580
583
    $schema->storage->txn_rollback;
581
    $schema->storage->txn_rollback;
Lines 723-729 subtest 'RenewHold' => sub { Link Here
723
    $cgi->param( item_id   => $item->itemnumber );
721
    $cgi->param( item_id   => $item->itemnumber );
724
722
725
    t::lib::Mocks::mock_userenv( { patron => $patron } );    # For AddIssue
723
    t::lib::Mocks::mock_userenv( { patron => $patron } );    # For AddIssue
726
    my $checkout = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
724
    my $checkout = C4::Circulation::AddIssue( $patron, $item->barcode );
727
725
728
    # Everything is ok
726
    # Everything is ok
729
    my $reply = C4::ILSDI::Services::RenewLoan($cgi);
727
    my $reply = C4::ILSDI::Services::RenewLoan($cgi);
Lines 826-836 subtest 'GetPatronInfo paginated loans' => sub { Link Here
826
    my $module = Test::MockModule->new('C4::Context');
824
    my $module = Test::MockModule->new('C4::Context');
827
    $module->mock('userenv', sub { { branch => $library->branchcode } });
825
    $module->mock('userenv', sub { { branch => $library->branchcode } });
828
    my $date_due = Koha::DateUtils::dt_from_string()->add(weeks => 2);
826
    my $date_due = Koha::DateUtils::dt_from_string()->add(weeks => 2);
829
    my $issue1 = C4::Circulation::AddIssue($patron->unblessed, $item1->barcode, $date_due);
827
    my $issue1 = C4::Circulation::AddIssue($patron, $item1->barcode, $date_due);
830
    my $date_due1 = Koha::DateUtils::dt_from_string( $issue1->date_due );
828
    my $date_due1 = Koha::DateUtils::dt_from_string( $issue1->date_due );
831
    my $issue2 = C4::Circulation::AddIssue($patron->unblessed, $item2->barcode, $date_due);
829
    my $issue2 = C4::Circulation::AddIssue($patron, $item2->barcode, $date_due);
832
    my $date_due2 = Koha::DateUtils::dt_from_string( $issue2->date_due );
830
    my $date_due2 = Koha::DateUtils::dt_from_string( $issue2->date_due );
833
    my $issue3 = C4::Circulation::AddIssue($patron->unblessed, $item3->barcode, $date_due);
831
    my $issue3 = C4::Circulation::AddIssue($patron, $item3->barcode, $date_due);
834
    my $date_due3 = Koha::DateUtils::dt_from_string( $issue3->date_due );
832
    my $date_due3 = Koha::DateUtils::dt_from_string( $issue3->date_due );
835
833
836
    my $cgi = CGI->new;
834
    my $cgi = CGI->new;
(-)a/t/db_dependent/Illrequests.t (-1 / +1 lines)
Lines 1480-1486 subtest 'Checking in hook' => sub { Link Here
1480
    t::lib::Mocks::mock_preference('CirculateILL', 1);
1480
    t::lib::Mocks::mock_preference('CirculateILL', 1);
1481
1481
1482
    # Add an issue
1482
    # Add an issue
1483
    AddIssue( $patron->unblessed, $item->barcode );
1483
    AddIssue( $patron, $item->barcode );
1484
    # Make the item withdrawn so checking-in is rejected
1484
    # Make the item withdrawn so checking-in is rejected
1485
    t::lib::Mocks::mock_preference('BlockReturnOfWithdrawnItems', 1);
1485
    t::lib::Mocks::mock_preference('BlockReturnOfWithdrawnItems', 1);
1486
    $item->set({ withdrawn => 1 })->store;
1486
    $item->set({ withdrawn => 1 })->store;
(-)a/t/db_dependent/Koha/Account/Line.t (-9 / +18 lines)
Lines 511-522 subtest 'Renewal related tests' => sub { Link Here
511
            class => 'Koha::Checkouts',
511
            class => 'Koha::Checkouts',
512
            value => {
512
            value => {
513
                itemnumber      => $item->itemnumber,
513
                itemnumber      => $item->itemnumber,
514
                borrowernumber  => $patron->borrowernumber,
514
                onsite_checkout => 0,
515
                onsite_checkout => 0,
515
                renewals_count  => 99,
516
                renewals_count  => 99,
516
                auto_renew      => 0
517
                auto_renew      => 0
517
            }
518
            }
518
        }
519
        }
519
    );
520
    );
521
520
    my $line = Koha::Account::Line->new(
522
    my $line = Koha::Account::Line->new(
521
    {
523
    {
522
        borrowernumber    => $patron->borrowernumber,
524
        borrowernumber    => $patron->borrowernumber,
Lines 701-707 subtest 'checkout() tests' => sub { Link Here
701
    my $account = $patron->account;
703
    my $account = $patron->account;
702
704
703
    t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode });
705
    t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode });
704
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
706
    my $checkout = AddIssue( $patron, $item->barcode );
705
707
706
    my $line = $account->add_debit({
708
    my $line = $account->add_debit({
707
        amount    => 10,
709
        amount    => 10,
Lines 814-827 subtest "void() tests" => sub { Link Here
814
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
816
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
815
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
817
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
816
818
817
    my $borrower = Koha::Patron->new( {
819
    my $staff = $builder->build_object({ class => 'Koha::Patrons' });
818
        cardnumber => 'dariahall',
820
    t::lib::Mocks::mock_userenv({ patron => $staff });
819
        surname => 'Hall',
821
820
        firstname => 'Daria',
822
    my $borrower = $builder->build_object(
821
    } );
823
        {
822
    $borrower->categorycode( $categorycode );
824
            class => 'Koha::Patrons',
823
    $borrower->branchcode( $branchcode );
825
            value => {
824
    $borrower->store;
826
                cardnumber => 'dariahall',
827
                surname => 'Hall',
828
                firstname => 'Daria',
829
                categorycode => $categorycode,
830
                branchcode => $branchcode,
831
            }
832
        }
833
    );
825
834
826
    my $account = Koha::Account->new({ patron_id => $borrower->id });
835
    my $account = Koha::Account->new({ patron_id => $borrower->id });
827
836
(-)a/t/db_dependent/Koha/Biblio.t (-5 / +5 lines)
Lines 854-861 subtest 'current_checkouts() and old_checkouts() tests' => sub { Link Here
854
854
855
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
855
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
856
856
857
    my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' })->unblessed;
857
    my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' });
858
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' })->unblessed;
858
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
859
859
860
    my $item_1 = $builder->build_sample_item;
860
    my $item_1 = $builder->build_sample_item;
861
    my $item_2 = $builder->build_sample_item({ biblionumber => $item_1->biblionumber });
861
    my $item_2 = $builder->build_sample_item({ biblionumber => $item_1->biblionumber });
Lines 994-1000 subtest 'Recalls tests' => sub { Link Here
994
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has more existing recall(s) than recalls_per_record" );
994
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has more existing recall(s) than recalls_per_record" );
995
995
996
    $recall1->set_cancelled;
996
    $recall1->set_cancelled;
997
    C4::Circulation::AddIssue( $patron1->unblessed, $item2->barcode );
997
    C4::Circulation::AddIssue( $patron1, $item2->barcode );
998
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has already checked out an item attached to this biblio" );
998
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has already checked out an item attached to this biblio" );
999
999
1000
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if on_shelf_recalls = all and items are still available" );
1000
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if on_shelf_recalls = all and items are still available" );
Lines 1013-1020 subtest 'Recalls tests' => sub { Link Here
1013
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if no items are checked out" );
1013
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if no items are checked out" );
1014
1014
1015
    $recall2->set_cancelled;
1015
    $recall2->set_cancelled;
1016
    C4::Circulation::AddIssue( $patron2->unblessed, $item2->barcode );
1016
    C4::Circulation::AddIssue( $patron2, $item2->barcode );
1017
    C4::Circulation::AddIssue( $patron2->unblessed, $item1->barcode );
1017
    C4::Circulation::AddIssue( $patron2, $item1->barcode );
1018
    is( $biblio->can_be_recalled({ patron => $patron1 }), 2, "Can recall two items" );
1018
    is( $biblio->can_be_recalled({ patron => $patron1 }), 2, "Can recall two items" );
1019
1019
1020
    $item1->update({ withdrawn => 1 });
1020
    $item1->update({ withdrawn => 1 });
(-)a/t/db_dependent/Koha/Items.t (-10 / +10 lines)
Lines 298-304 subtest 'store' => sub { Link Here
298
                }
298
                }
299
            );
299
            );
300
300
301
            C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
301
            C4::Circulation::AddIssue( $patron, $item->barcode );
302
302
303
            # Simulate item marked as lost
303
            # Simulate item marked as lost
304
            $item->itemlost(3)->store;
304
            $item->itemlost(3)->store;
Lines 382-388 subtest 'store' => sub { Link Here
382
            );
382
            );
383
383
384
            my $issue =
384
            my $issue =
385
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
385
              C4::Circulation::AddIssue( $patron, $item->barcode );
386
386
387
            # Simulate item marked as lost
387
            # Simulate item marked as lost
388
            $item->itemlost(1)->store;
388
            $item->itemlost(1)->store;
Lines 485-491 subtest 'store' => sub { Link Here
485
            );
485
            );
486
486
487
            my $issue =
487
            my $issue =
488
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
488
              C4::Circulation::AddIssue( $patron, $item->barcode );
489
489
490
            # Simulate item marked as lost
490
            # Simulate item marked as lost
491
            $item->itemlost(3)->store;
491
            $item->itemlost(3)->store;
Lines 576-582 subtest 'store' => sub { Link Here
576
            );
576
            );
577
577
578
            my $issue =
578
            my $issue =
579
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
579
              C4::Circulation::AddIssue( $patron, $item->barcode );
580
580
581
            # Simulate item marked as lost
581
            # Simulate item marked as lost
582
            $item->itemlost(1)->store;
582
            $item->itemlost(1)->store;
Lines 783-789 subtest 'store' => sub { Link Here
783
            )->store;
783
            )->store;
784
784
785
            my $issue =
785
            my $issue =
786
              C4::Circulation::AddIssue( $patron->unblessed, $barcode );
786
              C4::Circulation::AddIssue( $patron, $barcode );
787
787
788
            # Simulate item marked as lost
788
            # Simulate item marked as lost
789
            $item->itemlost(1)->store;
789
            $item->itemlost(1)->store;
Lines 907-913 subtest 'store' => sub { Link Here
907
            )->store;
907
            )->store;
908
908
909
            my $issue =
909
            my $issue =
910
              C4::Circulation::AddIssue( $patron->unblessed, $barcode );
910
              C4::Circulation::AddIssue( $patron, $barcode );
911
911
912
            # Simulate item marked as lost
912
            # Simulate item marked as lost
913
            $item->itemlost(1)->store;
913
            $item->itemlost(1)->store;
Lines 957-963 subtest 'store' => sub { Link Here
957
            );
957
            );
958
958
959
            my $issue =
959
            my $issue =
960
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
960
              C4::Circulation::AddIssue( $patron, $item->barcode );
961
961
962
            # Simulate item marked as lost
962
            # Simulate item marked as lost
963
            $item->itemlost(1)->store;
963
            $item->itemlost(1)->store;
Lines 1048-1054 subtest 'store' => sub { Link Here
1048
            );
1048
            );
1049
1049
1050
            my $issue =
1050
            my $issue =
1051
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
1051
              C4::Circulation::AddIssue( $patron, $item->barcode );
1052
1052
1053
            # Simulate item marked as lost
1053
            # Simulate item marked as lost
1054
            $item->itemlost(1)->store;
1054
            $item->itemlost(1)->store;
Lines 1158-1164 subtest 'store' => sub { Link Here
1158
            );
1158
            );
1159
1159
1160
            my $issue =
1160
            my $issue =
1161
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
1161
              C4::Circulation::AddIssue( $patron, $item->barcode );
1162
1162
1163
            # Simulate item marked as lost
1163
            # Simulate item marked as lost
1164
            $item->itemlost(1)->store;
1164
            $item->itemlost(1)->store;
Lines 1282-1288 subtest 'store' => sub { Link Here
1282
            );
1282
            );
1283
1283
1284
            my $issue =
1284
            my $issue =
1285
              C4::Circulation::AddIssue( $patron->unblessed, $barcode );
1285
              C4::Circulation::AddIssue( $patron, $barcode );
1286
1286
1287
            # Simulate item marked as lost
1287
            # Simulate item marked as lost
1288
            $item->itemlost(1)->store;
1288
            $item->itemlost(1)->store;
(-)a/t/db_dependent/Koha/Object.t (-1 / +3 lines)
Lines 857-862 subtest 'unblessed_all_relateds' => sub { Link Here
857
    my $patron = Koha::Patron->new($patron_data)->store;
857
    my $patron = Koha::Patron->new($patron_data)->store;
858
    my ($biblionumber) = AddBiblio( MARC::Record->new, '' );
858
    my ($biblionumber) = AddBiblio( MARC::Record->new, '' );
859
    my $biblio = Koha::Biblios->find( $biblionumber );
859
    my $biblio = Koha::Biblios->find( $biblionumber );
860
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' })->store->itemtype;
860
    my $item = $builder->build_object(
861
    my $item = $builder->build_object(
861
        {
862
        {
862
            class => 'Koha::Items',
863
            class => 'Koha::Items',
Lines 866-876 subtest 'unblessed_all_relateds' => sub { Link Here
866
                biblionumber  => $biblio->biblionumber,
867
                biblionumber  => $biblio->biblionumber,
867
                itemlost      => 0,
868
                itemlost      => 0,
868
                withdrawn     => 0,
869
                withdrawn     => 0,
870
                itype         => $itemtype,
869
            }
871
            }
870
        }
872
        }
871
    );
873
    );
872
874
873
    my $issue = AddIssue( $patron->unblessed, $item->barcode, DateTime->now->subtract( days => 1 ) );
875
    my $issue = AddIssue( $patron, $item->barcode, DateTime->now->subtract( days => 1 ) );
874
    my $overdues = Koha::Patrons->find( $patron->id )->overdues; # Koha::Patron->overdues prefetches
876
    my $overdues = Koha::Patrons->find( $patron->id )->overdues; # Koha::Patron->overdues prefetches
875
    my $overdue = $overdues->next->unblessed_all_relateds;
877
    my $overdue = $overdues->next->unblessed_all_relateds;
876
    is( $overdue->{issue_id}, $issue->issue_id, 'unblessed_all_relateds has field from the original table (issues)' );
878
    is( $overdue->{issue_id}, $issue->issue_id, 'unblessed_all_relateds has field from the original table (issues)' );
(-)a/t/db_dependent/Koha/Patrons.t (-5 / +2 lines)
Lines 660-675 subtest 'checkouts + pending_checkouts + overdues + old_checkouts' => sub { Link Here
660
    is( $old_checkouts->count, 0, 'old_checkouts should not return any issues for that patron' );
660
    is( $old_checkouts->count, 0, 'old_checkouts should not return any issues for that patron' );
661
    is( ref($old_checkouts), 'Koha::Old::Checkouts', 'old_checkouts should return a Koha::Old::Checkouts object' );
661
    is( ref($old_checkouts), 'Koha::Old::Checkouts', 'old_checkouts should return a Koha::Old::Checkouts object' );
662
662
663
    # Not sure how this is useful, but AddIssue pass this variable to different other subroutines
664
    $patron = Koha::Patrons->find( $patron->borrowernumber )->unblessed;
665
666
    t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
663
    t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
667
664
668
    AddIssue( $patron, $item_1->barcode, DateTime->now->subtract( days => 1 ) );
665
    AddIssue( $patron, $item_1->barcode, DateTime->now->subtract( days => 1 ) );
669
    AddIssue( $patron, $item_2->barcode, DateTime->now->subtract( days => 5 ) );
666
    AddIssue( $patron, $item_2->barcode, DateTime->now->subtract( days => 5 ) );
670
    AddIssue( $patron, $item_3->barcode );
667
    AddIssue( $patron, $item_3->barcode );
671
668
672
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
673
    $checkouts = $patron->checkouts;
669
    $checkouts = $patron->checkouts;
674
    is( $checkouts->count, 3, 'checkouts should return 3 issues for that patron' );
670
    is( $checkouts->count, 3, 'checkouts should return 3 issues for that patron' );
675
    is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' );
671
    is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' );
Lines 1511-1521 subtest 'overdues' => sub { Link Here
1511
1507
1512
    t::lib::Mocks::mock_preference({ branchcode => $library->{branchcode} });
1508
    t::lib::Mocks::mock_preference({ branchcode => $library->{branchcode} });
1513
1509
1510
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
1511
1514
    AddIssue( $patron, $item_1->barcode, DateTime->now->subtract( days => 1 ) );
1512
    AddIssue( $patron, $item_1->barcode, DateTime->now->subtract( days => 1 ) );
1515
    AddIssue( $patron, $item_2->barcode, DateTime->now->subtract( days => 5 ) );
1513
    AddIssue( $patron, $item_2->barcode, DateTime->now->subtract( days => 5 ) );
1516
    AddIssue( $patron, $item_3->barcode );
1514
    AddIssue( $patron, $item_3->barcode );
1517
1515
1518
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
1519
    my $overdues = $patron->overdues;
1516
    my $overdues = $patron->overdues;
1520
    is( $overdues->count, 2, 'Patron should have 2 overdues');
1517
    is( $overdues->count, 2, 'Patron should have 2 overdues');
1521
    is( $overdues->next->itemnumber, $item_1->itemnumber, 'The issue should be returned in the same order as they have been done, first is correct' );
1518
    is( $overdues->next->itemnumber, $item_1->itemnumber, 'The issue should be returned in the same order as they have been done, first is correct' );
(-)a/t/db_dependent/Koha/Plugins/Circulation_hooks.t (-2 / +2 lines)
Lines 75-85 subtest 'after_circ_action() hook tests' => sub { Link Here
75
    subtest 'AddIssue' => sub {
75
    subtest 'AddIssue' => sub {
76
        plan tests => 2;
76
        plan tests => 2;
77
77
78
        warning_like { AddIssue( $patron->unblessed, $item_1->barcode ); }
78
        warning_like { AddIssue( $patron, $item_1->barcode ); }
79
        qr/after_circ_action called with action: checkout, ref: Koha::Checkout type: issue/,
79
        qr/after_circ_action called with action: checkout, ref: Koha::Checkout type: issue/,
80
          'AddIssue calls the after_circ_action hook';
80
          'AddIssue calls the after_circ_action hook';
81
81
82
        warning_like { AddIssue( $patron->unblessed, $item_2->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } ); }
82
        warning_like { AddIssue( $patron, $item_2->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } ); }
83
        qr/after_circ_action called with action: checkout, ref: Koha::Checkout type: onsite_checkout/,
83
        qr/after_circ_action called with action: checkout, ref: Koha::Checkout type: onsite_checkout/,
84
          'AddIssue calls the after_circ_action hook (onsite_checkout case)';
84
          'AddIssue calls the after_circ_action hook (onsite_checkout case)';
85
    };
85
    };
(-)a/t/db_dependent/Koha/Pseudonymization.t (-2 / +2 lines)
Lines 84-90 subtest 'Koha::Anonymized::Transactions tests' => sub { Link Here
84
    t::lib::Mocks::mock_preference( 'Pseudonymization', 0 );
84
    t::lib::Mocks::mock_preference( 'Pseudonymization', 0 );
85
    my $item = $builder->build_sample_item;
85
    my $item = $builder->build_sample_item;
86
    t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch });
86
    t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch });
87
    AddIssue( $patron->unblessed, $item->barcode, dt_from_string );
87
    AddIssue( $patron, $item->barcode, dt_from_string );
88
    AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string );
88
    AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string );
89
    my $pseudonymized= Koha::PseudonymizedTransactions->search(
89
    my $pseudonymized= Koha::PseudonymizedTransactions->search(
90
        { itemnumber => $item->itemnumber } )->next;
90
        { itemnumber => $item->itemnumber } )->next;
Lines 96-102 subtest 'Koha::Anonymized::Transactions tests' => sub { Link Here
96
    );
96
    );
97
    $item = $builder->build_sample_item;
97
    $item = $builder->build_sample_item;
98
    t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch });
98
    t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch });
99
    AddIssue( $patron->unblessed, $item->barcode, dt_from_string );
99
    AddIssue( $patron, $item->barcode, dt_from_string );
100
    AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string );
100
    AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string );
101
    my $statistic = Koha::Statistics->search( { itemnumber => $item->itemnumber } )->next;
101
    my $statistic = Koha::Statistics->search( { itemnumber => $item->itemnumber } )->next;
102
    $pseudonymized = Koha::PseudonymizedTransactions->search( { itemnumber => $item->itemnumber } )->next;
102
    $pseudonymized = Koha::PseudonymizedTransactions->search( { itemnumber => $item->itemnumber } )->next;
(-)a/t/db_dependent/Koha/Template/Plugin/CirculationRules.t (-1 / +1 lines)
Lines 74-80 my $item = $builder->build_sample_item( Link Here
74
    }
74
    }
75
);
75
);
76
76
77
my $issue = AddIssue( $patron->unblessed, $item->barcode );
77
my $issue = AddIssue( $patron, $item->barcode );
78
78
79
my $rules = $plugin->Renewals( $patron->id, $item->id );
79
my $rules = $plugin->Renewals( $patron->id, $item->id );
80
80
(-)a/t/db_dependent/Letters/TemplateToolkit.t (-35 / +59 lines)
Lines 63-69 my $mocked_datetime = Test::MockModule->new('DateTime'); Link Here
63
$mocked_datetime->mock( 'now', sub { return $now_value->clone; } );
63
$mocked_datetime->mock( 'now', sub { return $now_value->clone; } );
64
64
65
my $library = $builder->build( { source => 'Branch' } );
65
my $library = $builder->build( { source => 'Branch' } );
66
my $patron  = $builder->build( { source => 'Borrower' } );
66
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
67
67
my $patron2 = $builder->build( { source => 'Borrower' } );
68
my $patron2 = $builder->build( { source => 'Borrower' } );
68
69
69
my $item = $builder->build_sample_item();
70
my $item = $builder->build_sample_item();
Lines 71-77 my $hold = $builder->build_object( Link Here
71
    {
72
    {
72
        class => 'Koha::Holds',
73
        class => 'Koha::Holds',
73
        value => {
74
        value => {
74
            borrowernumber => $patron->{borrowernumber},
75
            borrowernumber => $patron->borrowernumber,
75
            biblionumber   => $item->biblionumber
76
            biblionumber   => $item->biblionumber
76
        }
77
        }
77
    }
78
    }
Lines 109-155 $prepared_letter = GetPreparedLetter( Link Here
109
        module      => 'test',
110
        module      => 'test',
110
        letter_code => 'TEST_PATRON',
111
        letter_code => 'TEST_PATRON',
111
        tables      => {
112
        tables      => {
112
            borrowers => $patron->{borrowernumber},
113
            borrowers => $patron->borrowernumber,
113
        },
114
        },
114
    )
115
    )
115
);
116
);
116
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with scalar for content' );
117
is( $prepared_letter->{content}, $patron->borrowernumber, 'Patron object used correctly with scalar for content' );
117
is( $prepared_letter->{title}, $patron->{firstname}, 'Patron object used correctly with scalar for title' );
118
is( $prepared_letter->{title}, $patron->firstname, 'Patron object used correctly with scalar for title' );
118
119
119
$prepared_letter = GetPreparedLetter(
120
$prepared_letter = GetPreparedLetter(
120
    (
121
    (
121
        module      => 'test',
122
        module      => 'test',
122
        letter_code => 'TEST_PATRON',
123
        letter_code => 'TEST_PATRON',
123
        tables      => {
124
        tables      => {
124
            borrowers => $patron,
125
            borrowers => $patron->unblessed,
125
        },
126
        },
126
    )
127
    )
127
);
128
);
128
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with hashref for content' );
129
is( $prepared_letter->{content}, $patron->borrowernumber, 'Patron object used correctly with hashref for content' );
129
is( $prepared_letter->{title}, $patron->{firstname}, 'Patron object used correctly with hashref for title' );
130
is( $prepared_letter->{title}, $patron->firstname, 'Patron object used correctly with hashref for title' );
130
131
131
$prepared_letter = GetPreparedLetter(
132
$prepared_letter = GetPreparedLetter(
132
    (
133
    (
133
        module      => 'test',
134
        module      => 'test',
134
        letter_code => 'TEST_PATRON',
135
        letter_code => 'TEST_PATRON',
135
        tables      => {
136
        tables      => {
136
            borrowers => [ $patron->{borrowernumber} ],
137
            borrowers => [ $patron->borrowernumber ],
137
        },
138
        },
138
    )
139
    )
139
);
140
);
140
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with arrayref for content' );
141
is( $prepared_letter->{content}, $patron->borrowernumber, 'Patron object used correctly with arrayref for content' );
141
is( $prepared_letter->{title}, $patron->{firstname}, 'Patron object used correctly with arrayref for title' );
142
is( $prepared_letter->{title}, $patron->firstname, 'Patron object used correctly with arrayref for title' );
142
143
143
$prepared_letter = GetPreparedLetter(
144
$prepared_letter = GetPreparedLetter(
144
    (
145
    (
145
        module      => 'test',
146
        module      => 'test',
146
        letter_code => 'TEST_PATRON',
147
        letter_code => 'TEST_PATRON',
147
        objects      => {
148
        objects      => {
148
            borrower => scalar Koha::Patrons->find( $patron->{borrowernumber} ),
149
            borrower => scalar Koha::Patrons->find( $patron->borrowernumber ),
149
        },
150
        },
150
    )
151
    )
151
);
152
);
152
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly as object' );
153
is( $prepared_letter->{content}, $patron->borrowernumber, 'Patron object used correctly as object' );
153
154
154
$sth->execute( "TEST_BIBLIO", "[% biblio.title %]", "[% biblio.id %]" );
155
$sth->execute( "TEST_BIBLIO", "[% biblio.title %]", "[% biblio.id %]" );
155
$prepared_letter = GetPreparedLetter(
156
$prepared_letter = GetPreparedLetter(
Lines 209-215 $prepared_letter = GetPreparedLetter( Link Here
209
        module      => 'test',
210
        module      => 'test',
210
        letter_code => 'TEST_HOLD',
211
        letter_code => 'TEST_HOLD',
211
        tables      => {
212
        tables      => {
212
            reserves => { borrowernumber => $patron->{borrowernumber}, biblionumber => $item->biblionumber },
213
            reserves => { borrowernumber => $patron->borrowernumber, biblionumber => $item->biblionumber },
213
        },
214
        },
214
    )
215
    )
215
);
216
);
Lines 222-228 eval { Link Here
222
            module      => 'test',
223
            module      => 'test',
223
            letter_code => 'TEST_HOLD',
224
            letter_code => 'TEST_HOLD',
224
            tables      => {
225
            tables      => {
225
                reserves => [ $patron->{borrowernumber}, $item->biblionumber ],
226
                reserves => [ $patron->borrowernumber, $item->biblionumber ],
226
            },
227
            },
227
        )
228
        )
228
    )
229
    )
Lines 237-243 $prepared_letter = GetPreparedLetter( Link Here
237
        letter_code => 'TEST_HOLD',
238
        letter_code => 'TEST_HOLD',
238
        tables      => {
239
        tables      => {
239
            'branches'    => $library,
240
            'branches'    => $library,
240
            'borrowers'   => $patron,
241
            'borrowers'   => $patron->unblessed,
241
            'biblio'      => $item->biblionumber,
242
            'biblio'      => $item->biblionumber,
242
            'biblioitems' => $item->biblioitemnumber,
243
            'biblioitems' => $item->biblioitemnumber,
243
            'reserves'    => $hold->unblessed,
244
            'reserves'    => $hold->unblessed,
Lines 311-322 subtest 'regression tests' => sub { Link Here
311
    plan tests => 8;
312
    plan tests => 8;
312
313
313
    my $library = $builder->build( { source => 'Branch' } );
314
    my $library = $builder->build( { source => 'Branch' } );
314
    my $patron  = $builder->build( { source => 'Borrower' } );
315
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' })->store->itemtype;
316
315
    my $item1 = $builder->build_sample_item(
317
    my $item1 = $builder->build_sample_item(
316
        {
318
        {
317
            barcode        => 'a_t_barcode',
319
            barcode        => 'a_t_barcode',
318
            library        => $library->{branchcode},
320
            library        => $library->{branchcode},
319
            itype          => 'BK',
321
            itype          => $itemtype,
320
            itemcallnumber => 'itemcallnumber1',
322
            itemcallnumber => 'itemcallnumber1',
321
        }
323
        }
322
    );
324
    );
Lines 326-332 subtest 'regression tests' => sub { Link Here
326
        {
328
        {
327
            barcode        => 'another_t_barcode',
329
            barcode        => 'another_t_barcode',
328
            library        => $library->{branchcode},
330
            library        => $library->{branchcode},
329
            itype          => 'BK',
331
            itype          => $itemtype,
330
            itemcallnumber => 'itemcallnumber2',
332
            itemcallnumber => 'itemcallnumber2',
331
        }
333
        }
332
    );
334
    );
Lines 336-342 subtest 'regression tests' => sub { Link Here
336
        {
338
        {
337
            barcode        => 'another_t_barcode_3',
339
            barcode        => 'another_t_barcode_3',
338
            library        => $library->{branchcode},
340
            library        => $library->{branchcode},
339
            itype          => 'BK',
341
            itype          => $itemtype,
340
            itemcallnumber => 'itemcallnumber3',
342
            itemcallnumber => 'itemcallnumber3',
341
        }
343
        }
342
    );
344
    );
Lines 356-362 Dear <<borrowers.firstname>> <<borrowers.surname>>, Link Here
356
The order <<aqorders.ordernumber>> (<<biblio.title>>) has been received.
358
The order <<aqorders.ordernumber>> (<<biblio.title>>) has been received.
357
Your library.
359
Your library.
358
        |;
360
        |;
359
        my $params = { code => $code, branchcode => $branchcode, tables => { branches => $library, borrowers => $patron, biblio => $biblio1, aqorders => $order } };
361
        my $params = { code => $code, branchcode => $branchcode, tables => { branches => $library, borrowers => $patron->unblessed, biblio => $biblio1, aqorders => $order } };
360
        my $letter = process_letter( { template => $template, %$params });
362
        my $letter = process_letter( { template => $template, %$params });
361
        my $tt_template = q|
363
        my $tt_template = q|
362
Dear [% borrower.firstname %] [% borrower.surname %],
364
Dear [% borrower.firstname %] [% borrower.surname %],
Lines 430-445 Notes: [% article_request.patron_notes %] Link Here
430
        my $checkout_code = 'CHECKOUT';
432
        my $checkout_code = 'CHECKOUT';
431
        my $checkin_code = 'CHECKIN';
433
        my $checkin_code = 'CHECKIN';
432
434
435
#        my $message_attr_1 = $builder->build_object(
436
#            {
437
#                class => 'Koha::MessageAttribute',
438
#                value => { message_name => "Item_Checkout", takes_days => 0 }
439
#            }
440
#        )->store;
441
#
442
#        my $message_attr_2 = $builder->build_object(
443
#            {
444
#                class => 'Koha::MessageAttribute',
445
#                value => { message_name => "Item_Check_in", takes_days => 0 }
446
#            }
447
#        )->store;
448
433
        my $dbh = C4::Context->dbh;
449
        my $dbh = C4::Context->dbh;
434
        # Enable notification for CHECKOUT - Things are hardcoded here but should work with default data
450
        # Enable notification for CHECKOUT - Things are hardcoded here but should work with default data
435
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 6 );
451
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|,
452
            undef, $patron->borrowernumber, 6 );
436
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
453
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
437
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
454
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
455
438
        # Enable notification for CHECKIN - Things are hardcoded here but should work with default data
456
        # Enable notification for CHECKIN - Things are hardcoded here but should work with default data
439
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 5 );
457
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|,
458
            undef, $patron->borrowernumber, 5);
440
        $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
459
        $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
441
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
460
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
442
461
462
443
        # historic syntax
463
        # historic syntax
444
        my $checkout_template = q|
464
        my $checkout_template = q|
445
The following items have been checked out:
465
The following items have been checked out:
Lines 460-470 Thank you for visiting <<branches.branchname>>. Link Here
460
480
461
        C4::Circulation::AddIssue( $patron, $item1->{barcode} );
481
        C4::Circulation::AddIssue( $patron, $item1->{barcode} );
462
        my $first_checkout_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
482
        my $first_checkout_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
483
463
        C4::Circulation::AddIssue( $patron, $item2->{barcode} );
484
        C4::Circulation::AddIssue( $patron, $item2->{barcode} );
464
        my $second_checkout_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
485
        my $second_checkout_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
465
486
466
        AddReturn( $item1->{barcode} );
487
        AddReturn( $item1->{barcode} );
467
        my $first_checkin_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
488
        my $first_checkin_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
489
468
        AddReturn( $item2->{barcode} );
490
        AddReturn( $item2->{barcode} );
469
        my $second_checkin_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
491
        my $second_checkin_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
470
492
Lines 490-500 Thank you for visiting [% branch.branchname %]. Link Here
490
512
491
        C4::Circulation::AddIssue( $patron, $item1->{barcode} );
513
        C4::Circulation::AddIssue( $patron, $item1->{barcode} );
492
        my $first_checkout_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
514
        my $first_checkout_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
515
493
        C4::Circulation::AddIssue( $patron, $item2->{barcode} );
516
        C4::Circulation::AddIssue( $patron, $item2->{barcode} );
494
        my $second_checkout_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
517
        my $second_checkout_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
495
518
496
        AddReturn( $item1->{barcode} );
519
        AddReturn( $item1->{barcode} );
497
        my $first_checkin_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
520
        my $first_checkin_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
521
498
        AddReturn( $item2->{barcode} );
522
        AddReturn( $item2->{barcode} );
499
        my $second_checkin_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
523
        my $second_checkin_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
500
524
Lines 512-518 Thank you for visiting [% branch.branchname %]. Link Here
512
536
513
        my $dbh = C4::Context->dbh;
537
        my $dbh = C4::Context->dbh;
514
        # Enable notification for DUEDGST - Things are hardcoded here but should work with default data
538
        # Enable notification for DUEDGST - Things are hardcoded here but should work with default data
515
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 1 );
539
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->borrowernumber, 1 );
516
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
540
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
517
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
541
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
518
542
Lines 541-547 You have [% count %] items due Link Here
541
        my $reserve_id1 = C4::Reserves::AddReserve(
565
        my $reserve_id1 = C4::Reserves::AddReserve(
542
            {
566
            {
543
                branchcode     => $library->{branchcode},
567
                branchcode     => $library->{branchcode},
544
                borrowernumber => $patron->{borrowernumber},
568
                borrowernumber => $patron->borrowernumber,
545
                biblionumber   => $biblio1->{biblionumber},
569
                biblionumber   => $biblio1->{biblionumber},
546
                notes          => "a note",
570
                notes          => "a note",
547
                itemnumber     => $item1->{itemnumber},
571
                itemnumber     => $item1->{itemnumber},
Lines 550-556 You have [% count %] items due Link Here
550
        my $reserve_id2 = C4::Reserves::AddReserve(
574
        my $reserve_id2 = C4::Reserves::AddReserve(
551
            {
575
            {
552
                branchcode     => $library->{branchcode},
576
                branchcode     => $library->{branchcode},
553
                borrowernumber => $patron->{borrowernumber},
577
                borrowernumber => $patron->borrowernumber,
554
                biblionumber   => $biblio1->{biblionumber},
578
                biblionumber   => $biblio1->{biblionumber},
555
                notes          => "a note",
579
                notes          => "a note",
556
                itemnumber     => $item1->{itemnumber},
580
                itemnumber     => $item1->{itemnumber},
Lines 559-565 You have [% count %] items due Link Here
559
        my $reserve_id3 = C4::Reserves::AddReserve(
583
        my $reserve_id3 = C4::Reserves::AddReserve(
560
            {
584
            {
561
                branchcode     => $library->{branchcode},
585
                branchcode     => $library->{branchcode},
562
                borrowernumber => $patron->{borrowernumber},
586
                borrowernumber => $patron->borrowernumber,
563
                biblionumber   => $biblio2->{biblionumber},
587
                biblionumber   => $biblio2->{biblionumber},
564
                notes          => "another note",
588
                notes          => "another note",
565
                itemnumber     => $item2->{itemnumber},
589
                itemnumber     => $item2->{itemnumber},
Lines 707-719 EOF Link Here
707
731
708
        my $checkout = C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
732
        my $checkout = C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
709
        $checkout->set( { timestamp => $now, issuedate => $one_minute_ago } )->store;
733
        $checkout->set( { timestamp => $now, issuedate => $one_minute_ago } )->store;
710
        my $first_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
734
        my $first_slip = C4::Members::IssueSlip( $branchcode, $patron->borrowernumber );
711
735
712
        $checkout = C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
736
        $checkout = C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
713
        $checkout->set( { timestamp => $now, issuedate => $now } )->store;
737
        $checkout->set( { timestamp => $now, issuedate => $now } )->store;
714
        my $yesterday = dt_from_string->subtract( days => 1 );
738
        my $yesterday = dt_from_string->subtract( days => 1 );
715
        C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue
739
        C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue
716
        my $second_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
740
        my $second_slip = C4::Members::IssueSlip( $branchcode, $patron->borrowernumber );
717
741
718
        # Cleanup
742
        # Cleanup
719
        AddReturn( $item1->{barcode} );
743
        AddReturn( $item1->{barcode} );
Lines 767-778 EOF Link Here
767
791
768
        $checkout = C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
792
        $checkout = C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
769
        $checkout->set( { timestamp => $now, issuedate => $one_minute_ago } )->store;
793
        $checkout->set( { timestamp => $now, issuedate => $one_minute_ago } )->store;
770
        my $first_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
794
        my $first_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->borrowernumber );
771
795
772
        $checkout = C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
796
        $checkout = C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
773
        $checkout->set( { timestamp => $now, issuedate => $now } )->store;
797
        $checkout->set( { timestamp => $now, issuedate => $now } )->store;
774
        C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue
798
        C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue
775
        my $second_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
799
        my $second_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->borrowernumber );
776
800
777
        # There is too many line breaks generated by the historic syntax
801
        # There is too many line breaks generated by the historic syntax
778
        $second_slip->{content} =~ s|</p>\n\n\n<p>|</p>\n\n<p>|s;
802
        $second_slip->{content} =~ s|</p>\n\n\n<p>|</p>\n\n<p>|s;
Lines 845-851 EOF Link Here
845
        my $letter = C4::Overdues::parse_overdues_letter(
869
        my $letter = C4::Overdues::parse_overdues_letter(
846
            {
870
            {
847
                letter_code => $code,
871
                letter_code => $code,
848
                borrowernumber => $patron->{borrowernumber},
872
                borrowernumber => $patron->borrowernumber,
849
                branchcode  => $library->{branchcode},
873
                branchcode  => $library->{branchcode},
850
                items       => \@items,
874
                items       => \@items,
851
                substitute  => {
875
                substitute  => {
Lines 903-909 EOF Link Here
903
        my $tt_letter = C4::Overdues::parse_overdues_letter(
927
        my $tt_letter = C4::Overdues::parse_overdues_letter(
904
            {
928
            {
905
                letter_code => $code,
929
                letter_code => $code,
906
                borrowernumber => $patron->{borrowernumber},
930
                borrowernumber => $patron->borrowernumber,
907
                branchcode  => $library->{branchcode},
931
                branchcode  => $library->{branchcode},
908
                items       => \@items,
932
                items       => \@items,
909
                substitute  => {
933
                substitute  => {
Lines 930-940 EOF Link Here
930
        $dbh->do("DELETE FROM message_queue");
954
        $dbh->do("DELETE FROM message_queue");
931
955
932
        # Enable notification for CHECKOUT - Things are hardcoded here but should work with default data
956
        # Enable notification for CHECKOUT - Things are hardcoded here but should work with default data
933
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 6 );
957
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->borrowernumber, 6 );
934
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
958
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
935
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
959
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
936
        # Enable notification for CHECKIN - Things are hardcoded here but should work with default data
960
        # Enable notification for CHECKIN - Things are hardcoded here but should work with default data
937
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 5 );
961
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->borrowernumber, 5 );
938
        $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
962
        $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
939
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
963
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
940
964
(-)a/t/db_dependent/Members/GetAllIssues.t (-2 / +2 lines)
Lines 66-73 my $borrowernumber1 = Link Here
66
  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
66
  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
67
my $borrowernumber2 =
67
my $borrowernumber2 =
68
  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
68
  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
69
my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed;
69
my $borrower1 = Koha::Patrons->find( $borrowernumber1 );
70
my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed;
70
my $borrower2 = Koha::Patrons->find( $borrowernumber2 );
71
71
72
my $module = Test::MockModule->new('C4::Context');
72
my $module = Test::MockModule->new('C4::Context');
73
$module->mock( 'userenv', sub { { branch => $branchcode } } );
73
$module->mock( 'userenv', sub { { branch => $branchcode } } );
(-)a/t/db_dependent/Members/IssueSlip.t (-3 / +3 lines)
Lines 118-124 my $itemnumber2 = $builder->build_sample_item({ biblionumber => $biblionumber2, Link Here
118
118
119
my $borrowernumber =
119
my $borrowernumber =
120
  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
120
  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
121
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
121
my $borrower = Koha::Patrons->find( $borrowernumber );
122
122
123
my $module = Test::MockModule->new('C4::Context');
123
my $module = Test::MockModule->new('C4::Context');
124
$module->mock( 'userenv', sub { { branch => $branchcode } } );
124
$module->mock( 'userenv', sub { { branch => $branchcode } } );
Lines 164-170 EOS Link Here
164
164
165
        # Set timestamps to the same value to avoid a different order
165
        # Set timestamps to the same value to avoid a different order
166
        Koha::Checkouts->search(
166
        Koha::Checkouts->search(
167
            { borrowernumber => $borrower->{borrowernumber} }
167
            { borrowernumber => $borrower->borrowernumber }
168
        )->update( { timestamp => dt_from_string } );
168
        )->update( { timestamp => dt_from_string } );
169
169
170
        $expected_slip = <<EOS;
170
        $expected_slip = <<EOS;
Lines 237-243 EOS Link Here
237
237
238
        # Set timestamps to the same value to avoid a different order
238
        # Set timestamps to the same value to avoid a different order
239
        Koha::Checkouts->search(
239
        Koha::Checkouts->search(
240
            { borrowernumber => $borrower->{borrowernumber} }
240
            { borrowernumber => $borrower->borrowernumber }
241
        )->update( { timestamp => dt_from_string } );
241
        )->update( { timestamp => dt_from_string } );
242
242
243
        $expected_slip = <<EOS;
243
        $expected_slip = <<EOS;
(-)a/t/db_dependent/Patron/Borrower_Discharge.t (-34 / +32 lines)
Lines 43-72 my $another_library = $builder->build({ source => 'Branch' }); Link Here
43
my $itemtype        = $builder->build({ source => 'Itemtype' })->{itemtype};
43
my $itemtype        = $builder->build({ source => 'Itemtype' })->{itemtype};
44
44
45
C4::Context->_new_userenv('xxx');
45
C4::Context->_new_userenv('xxx');
46
my $patron = $builder->build({
46
my $patron = $builder->build_object({
47
    source => 'Borrower',
47
    class => 'Koha::Patrons',
48
    value => {
48
    value => {
49
        branchcode => $library->{branchcode},
49
        branchcode => $library->{branchcode},
50
        flags      => 1, # superlibrarian
50
        flags      => 1, # superlibrarian
51
    }
51
    }
52
});
52
});
53
my $p = Koha::Patrons->find( $patron->{borrowernumber} );
53
t::lib::Mocks::mock_userenv({ patron => $patron });
54
t::lib::Mocks::mock_userenv({ patron => $p });
55
54
56
my $patron2 = $builder->build({
55
my $patron2 = $builder->build_object({
57
    source => 'Borrower',
56
    class => 'Koha::Patrons',
58
    value => {
57
    value => {
59
        branchcode => $library->{branchcode},
58
        branchcode => $library->{branchcode},
60
    }
59
    }
61
});
60
});
62
my $patron3 = $builder->build({
61
my $patron3 = $builder->build_object({
63
    source => 'Borrower',
62
    class => 'Koha::Patrons',
64
    value => {
63
    value => {
65
        branchcode => $another_library->{branchcode},
64
        branchcode => $another_library->{branchcode},
66
        flags => undef,
65
        flags => undef,
67
    }
66
    }
68
});
67
});
69
my $p3 = Koha::Patrons->find( $patron3->{borrowernumber} );
70
68
71
# Discharge not possible with issues
69
# Discharge not possible with issues
72
my ( $biblionumber ) = AddBiblio( MARC::Record->new, '');
70
my ( $biblionumber ) = AddBiblio( MARC::Record->new, '');
Lines 81-117 $builder->build_sample_item( Link Here
81
);
79
);
82
80
83
AddIssue( $patron, $barcode );
81
AddIssue( $patron, $barcode );
84
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->{borrowernumber} }), 0, 'A patron with issues cannot be discharged' );
82
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 0, 'A patron with issues cannot be discharged' );
85
83
86
is( Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} }), undef, 'No request done if patron has issues' );
84
is( Koha::Patron::Discharge::request({ borrowernumber => $patron->borrowernumber }), undef, 'No request done if patron has issues' );
87
is( Koha::Patron::Discharge::discharge({ borrowernumber => $patron->{borrowernumber} }), undef, 'No discharge done if patron has issues' );
85
is( Koha::Patron::Discharge::discharge({ borrowernumber => $patron->borrowernumber }), undef, 'No discharge done if patron has issues' );
88
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request' );
86
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request' );
89
is_deeply( [ Koha::Patron::Discharge::get_validated ], [], 'There is no validated discharge' );
87
is_deeply( [ Koha::Patron::Discharge::get_validated ], [], 'There is no validated discharge' );
90
88
91
AddReturn( $barcode );
89
AddReturn( $barcode );
92
90
93
# Discharge possible without issue
91
# Discharge possible without issue
94
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->{borrowernumber} }), 1, 'A patron without issues can be discharged' );
92
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 1, 'A patron without issues can be discharged' );
95
93
96
is(Koha::Patron::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
94
is(Koha::Patron::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
97
95
98
# Verify that the user is not discharged anymore if the restriction has been lifted
96
# Verify that the user is not discharged anymore if the restriction has been lifted
99
Koha::Patron::Discharge::discharge( { borrowernumber => $patron->{borrowernumber} } );
97
Koha::Patron::Discharge::discharge( { borrowernumber => $patron->borrowernumber } );
100
Koha::Patron::Discharge::discharge( { borrowernumber => $patron2->{borrowernumber} } );
98
Koha::Patron::Discharge::discharge( { borrowernumber => $patron2->borrowernumber } );
101
Koha::Patron::Discharge::discharge( { borrowernumber => $patron3->{borrowernumber} } );
99
Koha::Patron::Discharge::discharge( { borrowernumber => $patron3->borrowernumber } );
102
is( Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->{borrowernumber} } ), 1, 'The patron has been discharged' );
100
is( Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->borrowernumber } ), 1, 'The patron has been discharged' );
103
is( Koha::Patrons->find( $patron->{borrowernumber} )->is_debarred, '9999-12-31', 'The patron has been debarred after discharge' );
101
is( Koha::Patrons->find( $patron->borrowernumber )->is_debarred, '9999-12-31', 'The patron has been debarred after discharge' );
104
is( scalar( Koha::Patron::Discharge::get_validated ),             3,            'There are 3 validated discharges' );
102
is( scalar( Koha::Patron::Discharge::get_validated ),             3,            'There are 3 validated discharges' );
105
is( scalar( Koha::Patron::Discharge::get_validated( { borrowernumber => $patron->{borrowernumber} } ) ), 1, 'There is 1 validated discharge for a given patron' );
103
is( scalar( Koha::Patron::Discharge::get_validated( { borrowernumber => $patron->borrowernumber } ) ), 1, 'There is 1 validated discharge for a given patron' );
106
is( scalar( Koha::Patron::Discharge::get_validated( { branchcode => $library->{branchcode} } ) ), 2, 'There is 2 validated discharges for a given branchcode' );    # This is not used in the code yet
104
is( scalar( Koha::Patron::Discharge::get_validated( { branchcode => $library->{branchcode} } ) ), 2, 'There is 2 validated discharges for a given branchcode' );    # This is not used in the code yet
107
Koha::Patron::Debarments::DelUniqueDebarment( { 'borrowernumber' => $patron->{borrowernumber}, 'type' => 'DISCHARGE' } );
105
Koha::Patron::Debarments::DelUniqueDebarment( { 'borrowernumber' => $patron->borrowernumber, 'type' => 'DISCHARGE' } );
108
ok( !Koha::Patrons->find( $patron->{borrowernumber} )->is_debarred, 'The debarment has been lifted' );
106
ok( !Koha::Patrons->find( $patron->borrowernumber )->is_debarred, 'The debarment has been lifted' );
109
ok( !Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->{borrowernumber} } ), 'The patron is not discharged after the restriction has been lifted' );
107
ok( !Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->borrowernumber } ), 'The patron is not discharged after the restriction has been lifted' );
110
108
111
# Verify that the discharge works multiple times
109
# Verify that the discharge works multiple times
112
Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} });
110
Koha::Patron::Discharge::request({ borrowernumber => $patron->borrowernumber });
113
is(scalar( Koha::Patron::Discharge::get_pendings ), 1, 'There is a pending discharge request (second time)');
111
is(scalar( Koha::Patron::Discharge::get_pendings ), 1, 'There is a pending discharge request (second time)');
114
Koha::Patron::Discharge::discharge( { borrowernumber => $patron->{borrowernumber} } );
112
Koha::Patron::Discharge::discharge( { borrowernumber => $patron->borrowernumber } );
115
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request (second time)');
113
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request (second time)');
116
114
117
# Check if PDF::FromHTML is installed.
115
# Check if PDF::FromHTML is installed.
Lines 119-135 my $check = eval { require PDF::FromHTML; }; Link Here
119
117
120
# Tests for if PDF::FromHTML is installed
118
# Tests for if PDF::FromHTML is installed
121
if ($check) {
119
if ($check) {
122
    isnt( Koha::Patron::Discharge::generate_as_pdf({ borrowernumber => $patron->{borrowernumber} }), undef, "Temporary PDF generated." );
120
    isnt( Koha::Patron::Discharge::generate_as_pdf({ borrowernumber => $patron->borrowernumber }), undef, "Temporary PDF generated." );
123
}
121
}
124
# Tests for if PDF::FromHTML is not installed
122
# Tests for if PDF::FromHTML is not installed
125
else {
123
else {
126
    warning_like { Koha::Patron::Discharge::generate_as_pdf({ borrowernumber => $patron->{borrowernumber}, testing => 1 }) }
124
    warning_like { Koha::Patron::Discharge::generate_as_pdf({ borrowernumber => $patron->borrowernumber, testing => 1 }) }
127
          [ qr/Can't locate PDF\/FromHTML.pm in \@INC/ ],
125
          [ qr/Can't locate PDF\/FromHTML.pm in \@INC/ ],
128
          "Expected failure because of missing PDF::FromHTML.";
126
          "Expected failure because of missing PDF::FromHTML.";
129
}
127
}
130
128
131
# FIXME Should be a Koha::Object object
129
# FIXME Should be a Koha::Object object
132
is( ref(Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} })), 'Koha::Schema::Result::Discharge', 'Discharge request sent' );
130
is( ref(Koha::Patron::Discharge::request({ borrowernumber => $patron->borrowernumber })), 'Koha::Schema::Result::Discharge', 'Discharge request sent' );
133
131
134
subtest 'search_limited' => sub {
132
subtest 'search_limited' => sub {
135
    plan tests => 4;
133
    plan tests => 4;
Lines 138-154 subtest 'search_limited' => sub { Link Here
138
    my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2' } )->store;
136
    my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2' } )->store;
139
    # $patron and $patron2 are from the same library, $patron3 from another one
137
    # $patron and $patron2 are from the same library, $patron3 from another one
140
    # Logged in user is $patron, superlibrarian
138
    # Logged in user is $patron, superlibrarian
141
    t::lib::Mocks::mock_userenv({ patron => $p });
139
    t::lib::Mocks::mock_userenv({ patron => $patron });
142
    Koha::Library::Group->new({ parent_id => $group_1->id,  branchcode => $patron->{branchcode} })->store();
140
    Koha::Library::Group->new({ parent_id => $group_1->id,  branchcode => $patron->branchcode })->store();
143
    Koha::Library::Group->new({ parent_id => $group_2->id,  branchcode => $patron3->{branchcode} })->store();
141
    Koha::Library::Group->new({ parent_id => $group_2->id,  branchcode => $patron3->branchcode })->store();
144
    Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} });
142
    Koha::Patron::Discharge::request({ borrowernumber => $patron->borrowernumber });
145
    Koha::Patron::Discharge::request({ borrowernumber => $patron2->{borrowernumber} });
143
    Koha::Patron::Discharge::request({ borrowernumber => $patron2->borrowernumber });
146
    Koha::Patron::Discharge::request({ borrowernumber => $patron3->{borrowernumber} });
144
    Koha::Patron::Discharge::request({ borrowernumber => $patron3->borrowernumber });
147
    is( scalar( Koha::Patron::Discharge::get_pendings), 3, 'With permission, all discharges are visible' );
145
    is( scalar( Koha::Patron::Discharge::get_pendings), 3, 'With permission, all discharges are visible' );
148
    is( Koha::Patron::Discharge::count({pending => 1}), 3, 'With permission, all discharges are visible' );
146
    is( Koha::Patron::Discharge::count({pending => 1}), 3, 'With permission, all discharges are visible' );
149
147
150
    # With patron 3 logged in, only discharges from their group are visible
148
    # With patron 3 logged in, only discharges from their group are visible
151
    t::lib::Mocks::mock_userenv({ patron => $p3 });
149
    t::lib::Mocks::mock_userenv({ patron => $patron3 });
152
    is( scalar( Koha::Patron::Discharge::get_pendings), 1, 'Without permission, only discharge from our group are visible' );
150
    is( scalar( Koha::Patron::Discharge::get_pendings), 1, 'Without permission, only discharge from our group are visible' );
153
    is( Koha::Patron::Discharge::count({pending => 1}), 1, 'Without permission, only discharge from our group are visible' );
151
    is( Koha::Patron::Discharge::count({pending => 1}), 1, 'Without permission, only discharge from our group are visible' );
154
};
152
};
(-)a/t/db_dependent/Patron/Borrower_PrevCheckout.t (-3 / +3 lines)
Lines 297-303 my $cpvmappings = [ Link Here
297
test_it($cpvmappings, "PreIssue");
297
test_it($cpvmappings, "PreIssue");
298
298
299
# Issue item_1 to $patron:
299
# Issue item_1 to $patron:
300
my $patron_get_mem = Koha::Patrons->find( $patron->{borrowernumber} )->unblessed;
300
my $patron_get_mem = Koha::Patrons->find( $patron->{borrowernumber} );
301
BAIL_OUT("Issue failed")
301
BAIL_OUT("Issue failed")
302
    unless AddIssue($patron_get_mem, $item_1->{barcode});
302
    unless AddIssue($patron_get_mem, $item_1->{barcode});
303
303
Lines 382-388 my $new_item = $builder->build_sample_item->unblessed; Link Here
382
my $prev_item = $builder->build_sample_item->unblessed;
382
my $prev_item = $builder->build_sample_item->unblessed;
383
# Second is Checked Out
383
# Second is Checked Out
384
BAIL_OUT("CanBookBeIssued Issue failed")
384
BAIL_OUT("CanBookBeIssued Issue failed")
385
    unless AddIssue($patron->unblessed, $prev_item->{barcode});
385
    unless AddIssue($patron, $prev_item->{barcode});
386
386
387
# Mappings
387
# Mappings
388
my $CBBI_mappings = [
388
my $CBBI_mappings = [
Lines 445-451 subtest 'Check previous checkouts for serial' => sub { Link Here
445
    my $item1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
445
    my $item1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
446
    my $item2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
446
    my $item2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
447
447
448
    AddIssue($patron->unblessed, $item1->barcode);
448
    AddIssue($patron, $item1->barcode);
449
449
450
    is($patron->do_check_for_previous_checkout($item1->unblessed), 1, 'Check only one item if bibliographic record is serial');
450
    is($patron->do_check_for_previous_checkout($item1->unblessed), 1, 'Check only one item if bibliographic record is serial');
451
    is($patron->do_check_for_previous_checkout($item2->unblessed), 0, 'Check only one item if bibliographic record is serial');
451
    is($patron->do_check_for_previous_checkout($item2->unblessed), 0, 'Check only one item if bibliographic record is serial');
(-)a/t/db_dependent/SIP/ILS.t (-4 / +4 lines)
Lines 260-266 subtest checkout => sub { Link Here
260
    t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode, flags => 1 });
260
    t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode, flags => 1 });
261
261
262
    my $item = $builder->build_sample_item({
262
    my $item = $builder->build_sample_item({
263
        library       => $library->branchcode,
263
        library => $library->branchcode,
264
    });
264
    });
265
265
266
    Koha::CirculationRules->set_rules(
266
    Koha::CirculationRules->set_rules(
Lines 279-294 subtest checkout => sub { Link Here
279
        }
279
        }
280
    );
280
    );
281
281
282
    AddIssue( $patron->unblessed, $item->barcode, undef, 0 );
282
    AddIssue( $patron, $item->barcode, undef, 0 );
283
    my $checkout = $item->checkout;
283
    my $checkout = $item->checkout;
284
    ok( defined($checkout), "Checkout added");
284
    ok( defined($checkout), "Checkout added");
285
    is( $checkout->renewals_count, 0, "Correct renewals");
285
    is( $checkout->renewals_count, 0, "Correct renewals");
286
286
287
    my $ils = C4::SIP::ILS->new({ id => $library->branchcode });
287
    my $ils = C4::SIP::ILS->new({ id => $library->branchcode });
288
    my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
288
    my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
289
    my $transaction = $ils->checkout($patron->cardnumber,$item->barcode,undef,undef);
289
    my $transaction = $ils->checkout($patron->cardnumber, $item->barcode);
290
290
291
    is( $transaction->{screen_msg},"Item already checked out to you: renewing item.","We get a success message when issue is renewed");
291
    is( $transaction->{screen_msg},"Item already checked out to you: renewing item.", "We get a success message when issue is renewed");
292
292
293
    $checkout->discard_changes();
293
    $checkout->discard_changes();
294
    is( $checkout->renewals_count, 1, "Renewals has been reduced");
294
    is( $checkout->renewals_count, 1, "Renewals has been reduced");
(-)a/t/db_dependent/rollingloans.t (-5 / +5 lines)
Lines 62-77 SKIP: { Link Here
62
}
62
}
63
63
64
sub try_issue {
64
sub try_issue {
65
    my ($cardnumber, $item ) = @_;
65
    my ($cardnumber, $item_barcode ) = @_;
66
    my $issuedate = '2011-05-16';
66
    my $issuedate = '2011-05-16';
67
    my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } );
67
    my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } );
68
    my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued( $patron, $item );
68
    my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued( $patron, $item_barcode );
69
    my $issue = AddIssue($patron->unblessed, $item, undef, 0, $issuedate);
69
    my $issue = AddIssue($patron, $item_barcode, undef, 0, $issuedate);
70
    return dt_from_string( $issue->date_due );
70
    return dt_from_string( $issue->date_due );
71
}
71
}
72
72
73
sub try_return {
73
sub try_return {
74
    my $barcode = shift;
74
    my $item_barcode = shift;
75
    my ($ret, $messages, $iteminformation, $borrower) = AddReturn($barcode);
75
    my ($ret, $messages, $iteminformation, $borrower) = AddReturn($item_barcode);
76
    return $ret;
76
    return $ret;
77
}
77
}
(-)a/t/db_dependent/selenium/regressions.t (-2 / +1 lines)
Lines 176-182 subtest 'Display circulation table correctly' => sub { Link Here
176
        }
176
        }
177
    );
177
    );
178
178
179
    C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
179
    C4::Circulation::AddIssue( $patron, $item->barcode );
180
180
181
    my $mainpage = $s->base_url . q|mainpage.pl|;
181
    my $mainpage = $s->base_url . q|mainpage.pl|;
182
    $driver->get($mainpage . q|?logout.x=1|);
182
    $driver->get($mainpage . q|?logout.x=1|);
183
- 

Return to bug 31735