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

(-)a/C4/Circulation.pm (-79 / +70 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 795-804 sub CanBookBeIssued { Link Here
795
    my $dbh             = C4::Context->dbh;
791
    my $dbh             = C4::Context->dbh;
796
    my $patron_unblessed = $patron->unblessed;
792
    my $patron_unblessed = $patron->unblessed;
797
793
798
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_unblessed, $patron_unblessed) );
794
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_object, $patron) );
799
795
800
    my $now = dt_from_string();
796
    my $now = dt_from_string();
801
    $duedate ||= CalcDateDue( $now, $effective_itemtype, $circ_library->branchcode, $patron_unblessed );
797
    $duedate ||= CalcDateDue( $now, $effective_itemtype, $circ_library->branchcode, $patron );
802
    if (DateTime->compare($duedate,$now) == -1 ) { # duedate cannot be before now
798
    if (DateTime->compare($duedate,$now) == -1 ) { # duedate cannot be before now
803
         $needsconfirmation{INVALID_DATE} = $duedate;
799
         $needsconfirmation{INVALID_DATE} = $duedate;
804
    }
800
    }
Lines 1007-1013 sub CanBookBeIssued { Link Here
1007
      and $issue
1003
      and $issue
1008
      and $issue->onsite_checkout
1004
      and $issue->onsite_checkout
1009
      and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
1005
      and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
1010
    my $toomany = TooMany( $patron_unblessed, $item_object, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
1006
    my $toomany = TooMany( $patron, $item_object, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
1011
    # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
1007
    # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
1012
    if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) {
1008
    if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) {
1013
        if ( $toomany->{max_allowed} == 0 ) {
1009
        if ( $toomany->{max_allowed} == 0 ) {
Lines 1347-1353 sub CanBookBeReturned { Link Here
1347
1343
1348
sub checkHighHolds {
1344
sub checkHighHolds {
1349
    my ( $item, $patron ) = @_;
1345
    my ( $item, $patron ) = @_;
1350
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
1346
    my $branchcode = _GetCircControlBranch( $item, $patron );
1351
1347
1352
    my $return_data = {
1348
    my $return_data = {
1353
        exceeded    => 0,
1349
        exceeded    => 0,
Lines 1421-1427 sub checkHighHolds { Link Here
1421
        );
1417
        );
1422
        my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
1418
        my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
1423
1419
1424
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron->unblessed );
1420
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron );
1425
1421
1426
        my $rule = Koha::CirculationRules->get_effective_rule_value(
1422
        my $rule = Koha::CirculationRules->get_effective_rule_value(
1427
            {
1423
            {
Lines 1456-1468 sub checkHighHolds { Link Here
1456
1452
1457
=head2 AddIssue
1453
=head2 AddIssue
1458
1454
1459
  &AddIssue($borrower, $barcode, [$datedue], [$cancelreserve], [$issuedate])
1455
  &AddIssue($patron, $barcode, [$datedue], [$cancelreserve], [$issuedate])
1460
1456
1461
Issue a book. Does no check, they are done in CanBookBeIssued. If we reach this sub, it means the user confirmed if needed.
1457
Issue a book. Does no check, they are done in CanBookBeIssued. If we reach this sub, it means the user confirmed if needed.
1462
1458
1463
=over 4
1459
=over 4
1464
1460
1465
=item C<$borrower> is a hash with borrower informations (from Koha::Patron->unblessed).
1461
=item C<$patron> is a patron object.
1466
1462
1467
=item C<$barcode> is the barcode of the item being issued.
1463
=item C<$barcode> is the barcode of the item being issued.
1468
1464
Lines 1497-1503 AddIssue does the following things : Link Here
1497
=cut
1493
=cut
1498
1494
1499
sub AddIssue {
1495
sub AddIssue {
1500
    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode, $params ) = @_;
1496
    my ( $patron, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode, $params ) = @_;
1501
1497
1502
    my $onsite_checkout = $params && $params->{onsite_checkout} ? 1 : 0;
1498
    my $onsite_checkout = $params && $params->{onsite_checkout} ? 1 : 0;
1503
    my $switch_onsite_checkout = $params && $params->{switch_onsite_checkout};
1499
    my $switch_onsite_checkout = $params && $params->{switch_onsite_checkout};
Lines 1525-1547 sub AddIssue { Link Here
1525
    }
1521
    }
1526
1522
1527
    # Stop here if the patron or barcode doesn't exist
1523
    # Stop here if the patron or barcode doesn't exist
1528
    if ( $borrower && $barcode && $barcodecheck ) {
1524
    if ( $patron && $barcode && $barcodecheck ) {
1529
        # find which item we issue
1525
        # find which item we issue
1530
        my $item_object = Koha::Items->find({ barcode => $barcode })
1526
        my $item_object = Koha::Items->find({ barcode => $barcode })
1531
          or return;    # if we don't get an Item, abort.
1527
          or return;    # if we don't get an Item, abort.
1532
        my $item_unblessed = $item_object->unblessed;
1528
        my $item_unblessed = $item_object->unblessed;
1533
1529
1534
        my $branchcode = _GetCircControlBranch( $item_unblessed, $borrower );
1530
        my $branchcode = _GetCircControlBranch( $item_object, $patron );
1535
1531
1536
        # get actual issuing if there is one
1532
        # get actual issuing if there is one
1537
        my $actualissue = $item_object->checkout;
1533
        my $actualissue = $item_object->checkout;
1538
1534
1539
        # check if we just renew the issue.
1535
        # check if we just renew the issue.
1540
        if ( $actualissue and $actualissue->borrowernumber eq $borrower->{'borrowernumber'}
1536
        if ( $actualissue and $actualissue->borrowernumber eq $patron->borrowernumber
1541
                and not $switch_onsite_checkout ) {
1537
                and not $switch_onsite_checkout ) {
1542
            $datedue = AddRenewal(
1538
            $datedue = AddRenewal(
1543
                {
1539
                {
1544
                    borrowernumber => $borrower->{'borrowernumber'},
1540
                    borrowernumber => $patron->borrowernumber,
1545
                    itemnumber     => $item_object->itemnumber,
1541
                    itemnumber     => $item_object->itemnumber,
1546
                    branch         => $branchcode,
1542
                    branch         => $branchcode,
1547
                    datedue        => $datedue,
1543
                    datedue        => $datedue,
Lines 1555-1561 sub AddIssue { Link Here
1555
1551
1556
            unless ($datedue) {
1552
            unless ($datedue) {
1557
                my $itype = $item_object->effective_itemtype;
1553
                my $itype = $item_object->effective_itemtype;
1558
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1554
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $patron );
1559
1555
1560
            }
1556
            }
1561
1557
Lines 1564-1570 sub AddIssue { Link Here
1564
                # Check if there is an ILL connected with the biblio of the item we are issuing
1560
                # Check if there is an ILL connected with the biblio of the item we are issuing
1565
                my $ill_request = Koha::Illrequests->search({
1561
                my $ill_request = Koha::Illrequests->search({
1566
                    biblio_id => $item_object->biblionumber,
1562
                    biblio_id => $item_object->biblionumber,
1567
                    borrowernumber => $borrower->{'borrowernumber'},
1563
                    borrowernumber => $patron->borrowernumber,
1568
                    completed => undef,
1564
                    completed => undef,
1569
                    due_date => { '!=', undef },
1565
                    due_date => { '!=', undef },
1570
                })->next;
1566
                })->next;
Lines 1579-1585 sub AddIssue { Link Here
1579
1575
1580
            $datedue->truncate( to => 'minute' );
1576
            $datedue->truncate( to => 'minute' );
1581
1577
1582
            my $patron = Koha::Patrons->find( $borrower );
1583
            my $library = Koha::Libraries->find( $branchcode );
1578
            my $library = Koha::Libraries->find( $branchcode );
1584
            my $fees = Koha::Charges::Fees->new(
1579
            my $fees = Koha::Charges::Fees->new(
1585
                {
1580
                {
Lines 1607-1618 sub AddIssue { Link Here
1607
                        action         => $cancel_recall,
1602
                        action         => $cancel_recall,
1608
                        recall_id      => $recall_id,
1603
                        recall_id      => $recall_id,
1609
                        item           => $item_object,
1604
                        item           => $item_object,
1610
                        borrowernumber => $borrower->{borrowernumber},
1605
                        borrowernumber => $patron->borrowernumber,
1611
                    }
1606
                    }
1612
                );
1607
                );
1613
            }
1608
            }
1614
1609
1615
            C4::Reserves::MoveReserve( $item_object->itemnumber, $borrower->{'borrowernumber'}, $cancelreserve );
1610
            C4::Reserves::MoveReserve( $item_object->itemnumber, $patron->borrowernumber, $cancelreserve );
1616
1611
1617
            # Starting process for transfer job (checking transfert and validate it if we have one)
1612
            # Starting process for transfer job (checking transfert and validate it if we have one)
1618
            if ( my $transfer = $item_object->get_transfer ) {
1613
            if ( my $transfer = $item_object->get_transfer ) {
Lines 1637-1643 sub AddIssue { Link Here
1637
            unless ($auto_renew) {
1632
            unless ($auto_renew) {
1638
                my $rule = Koha::CirculationRules->get_effective_rule_value(
1633
                my $rule = Koha::CirculationRules->get_effective_rule_value(
1639
                    {
1634
                    {
1640
                        categorycode => $borrower->{categorycode},
1635
                        categorycode => $patron->categorycode,
1641
                        itemtype     => $item_object->effective_itemtype,
1636
                        itemtype     => $item_object->effective_itemtype,
1642
                        branchcode   => $branchcode,
1637
                        branchcode   => $branchcode,
1643
                        rule_name    => 'auto_renew'
1638
                        rule_name    => 'auto_renew'
Lines 1648-1654 sub AddIssue { Link Here
1648
            }
1643
            }
1649
1644
1650
            my $issue_attributes = {
1645
            my $issue_attributes = {
1651
                borrowernumber  => $borrower->{'borrowernumber'},
1646
                borrowernumber  => $patron->borrowernumber,
1652
                issuedate       => $issuedate,
1647
                issuedate       => $issuedate,
1653
                date_due        => $datedue,
1648
                date_due        => $datedue,
1654
                branchcode      => C4::Context->userenv->{'branch'},
1649
                branchcode      => C4::Context->userenv->{'branch'},
Lines 1682-1688 sub AddIssue { Link Here
1682
                )->store;
1677
                )->store;
1683
            }
1678
            }
1684
            $issue->discard_changes;
1679
            $issue->discard_changes;
1685
            C4::Auth::track_login_daily( $borrower->{userid} );
1680
            C4::Auth::track_login_daily( $patron->userid );
1686
            if ( $item_object->location && $item_object->location eq 'CART'
1681
            if ( $item_object->location && $item_object->location eq 'CART'
1687
                && ( !$item_object->permanent_location || $item_object->permanent_location ne 'CART' ) ) {
1682
                && ( !$item_object->permanent_location || $item_object->permanent_location ne 'CART' ) ) {
1688
            ## Item was moved to cart via UpdateItemLocationOnCheckin, anything issued should be taken off the cart.
1683
            ## Item was moved to cart via UpdateItemLocationOnCheckin, anything issued should be taken off the cart.
Lines 1708-1738 sub AddIssue { Link Here
1708
            if ($was_lost) {
1703
            if ($was_lost) {
1709
                if ( $item_object->{_charge} ) {
1704
                if ( $item_object->{_charge} ) {
1710
                    $actualissue //= Koha::Old::Checkouts->search(
1705
                    $actualissue //= Koha::Old::Checkouts->search(
1711
                        { itemnumber => $item_unblessed->{itemnumber} },
1706
                        { itemnumber => $item_object->itemnumber },
1712
                        {
1707
                        {
1713
                            order_by => { '-desc' => 'returndate' },
1708
                            order_by => { '-desc' => 'returndate' },
1714
                            rows     => 1
1709
                            rows     => 1
1715
                        }
1710
                        }
1716
                    )->single;
1711
                    )->single;
1717
                    unless ( exists( $borrower->{branchcode} ) ) {
1712
                    unless ( $patron->branchcode ) {
1718
                        my $patron = $actualissue->patron;
1713
                        $patron = $actualissue->patron;
1719
                        $borrower = $patron->unblessed;
1720
                    }
1714
                    }
1721
                    _CalculateAndUpdateFine(
1715
                    _CalculateAndUpdateFine(
1722
                        {
1716
                        {
1723
                            issue       => $actualissue,
1717
                            issue       => $actualissue,
1724
                            item        => $item_unblessed,
1718
                            item        => $item_unblessed,
1725
                            borrower    => $borrower,
1719
                            borrower    => $patron->unblessed,
1726
                            return_date => $issuedate
1720
                            return_date => $issuedate
1727
                        }
1721
                        }
1728
                    );
1722
                    );
1729
                    _FixOverduesOnReturn( $borrower->{borrowernumber},
1723
                    _FixOverduesOnReturn( $patron->borrowernumber,
1730
                        $item_object->itemnumber, undef, 'RENEWED' );
1724
                        $item_object->itemnumber, undef, 'RENEWED' );
1731
                }
1725
                }
1732
            }
1726
            }
1733
1727
1734
            # If it costs to borrow this book, charge it to the patron's account.
1728
            # If it costs to borrow this book, charge it to the patron's account.
1735
            my ( $charge, $itemtype ) = GetIssuingCharges( $item_object->itemnumber, $borrower->{'borrowernumber'} );
1729
            my ( $charge, $itemtype ) = GetIssuingCharges( $item_object->itemnumber, $patron->borrowernumber );
1736
            if ( $charge && $charge > 0 ) {
1730
            if ( $charge && $charge > 0 ) {
1737
                AddIssuingCharge( $issue, $charge, 'RENT' );
1731
                AddIssuingCharge( $issue, $charge, 'RENT' );
1738
            }
1732
            }
Lines 1776-1785 sub AddIssue { Link Here
1776
                    itemnumber     => $item_object->itemnumber,
1770
                    itemnumber     => $item_object->itemnumber,
1777
                    itemtype       => $item_object->effective_itemtype,
1771
                    itemtype       => $item_object->effective_itemtype,
1778
                    location       => $item_object->location,
1772
                    location       => $item_object->location,
1779
                    borrowernumber => $borrower->{'borrowernumber'},
1773
                    borrowernumber => $patron->borrowernumber,
1780
                    ccode          => $item_object->ccode,
1774
                    ccode          => $item_object->ccode,
1781
                    categorycode   => $borrower->{'categorycode'},
1775
                    categorycode   => $patron->categorycode
1782
                    interface      => C4::Context->interface,
1783
                }
1776
                }
1784
            );
1777
            );
1785
1778
Lines 1787-1793 sub AddIssue { Link Here
1787
            my $circulation_alert = 'C4::ItemCirculationAlertPreference';
1780
            my $circulation_alert = 'C4::ItemCirculationAlertPreference';
1788
            my %conditions        = (
1781
            my %conditions        = (
1789
                branchcode   => $branchcode,
1782
                branchcode   => $branchcode,
1790
                categorycode => $borrower->{categorycode},
1783
                categorycode => $patron->categorycode,
1791
                item_type    => $item_object->effective_itemtype,
1784
                item_type    => $item_object->effective_itemtype,
1792
                notification => 'CHECKOUT',
1785
                notification => 'CHECKOUT',
1793
            );
1786
            );
Lines 1796-1809 sub AddIssue { Link Here
1796
                    {
1789
                    {
1797
                        type     => 'CHECKOUT',
1790
                        type     => 'CHECKOUT',
1798
                        item     => $item_object->unblessed,
1791
                        item     => $item_object->unblessed,
1799
                        borrower => $borrower,
1792
                        borrower => $patron->unblessed,
1800
                        branch   => $branchcode,
1793
                        branch   => $branchcode,
1801
                    }
1794
                    }
1802
                );
1795
                );
1803
            }
1796
            }
1804
            logaction(
1797
            logaction(
1805
                "CIRCULATION", "ISSUE",
1798
                "CIRCULATION", "ISSUE",
1806
                $borrower->{'borrowernumber'},
1799
                $patron->borrowernumber,
1807
                $item_object->itemnumber,
1800
                $item_object->itemnumber,
1808
            ) if C4::Context->preference("IssueLog");
1801
            ) if C4::Context->preference("IssueLog");
1809
1802
Lines 2377-2383 sub AddReturn { Link Here
2377
2370
2378
        if ( $issue and $issue->is_overdue($return_date) ) {
2371
        if ( $issue and $issue->is_overdue($return_date) ) {
2379
        # fix fine days
2372
        # fix fine days
2380
            my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item->unblessed, dt_from_string($issue->date_due), $return_date );
2373
            my ($debardate,$reminder) = _debar_user_on_return( $patron, $item, dt_from_string($issue->date_due), $return_date );
2381
            if ($debardate and $debardate ne "9999-12-31") {
2374
            if ($debardate and $debardate ne "9999-12-31") {
2382
                if ($reminder){
2375
                if ($reminder){
2383
                    $messages->{'PrevDebarred'} = $debardate;
2376
                    $messages->{'PrevDebarred'} = $debardate;
Lines 2647-2657 sub MarkIssueReturned { Link Here
2647
2640
2648
=head2 _debar_user_on_return
2641
=head2 _debar_user_on_return
2649
2642
2650
    _debar_user_on_return($borrower, $item, $datedue, $returndate);
2643
    _debar_user_on_return($patron, $item, $datedue, $returndate);
2651
2644
2652
C<$borrower> borrower hashref
2645
C<$patron> patron object
2653
2646
2654
C<$item> item hashref
2647
C<$item> patron object
2655
2648
2656
C<$datedue> date due DateTime object
2649
C<$datedue> date due DateTime object
2657
2650
Lines 2668-2680 to ease testing. Link Here
2668
=cut
2661
=cut
2669
2662
2670
sub _calculate_new_debar_dt {
2663
sub _calculate_new_debar_dt {
2671
    my ( $borrower, $item, $dt_due, $return_date ) = @_;
2664
    my ( $patron, $item, $dt_due, $return_date ) = @_;
2672
2665
2673
    my $branchcode = _GetCircControlBranch( $item, $borrower );
2666
    my $branchcode = _GetCircControlBranch( $item, $patron );
2674
    my $circcontrol = C4::Context->preference('CircControl');
2667
    my $circcontrol = C4::Context->preference('CircControl');
2675
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2668
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2676
        {   categorycode => $borrower->{categorycode},
2669
        {   categorycode => $patron->categorycode,
2677
            itemtype     => $item->{itype},
2670
            itemtype     => $item->effective_itemtype,
2678
            branchcode   => $branchcode,
2671
            branchcode   => $branchcode,
2679
            rules => [
2672
            rules => [
2680
                'finedays',
2673
                'finedays',
Lines 2723-2730 sub _calculate_new_debar_dt { Link Here
2723
        }
2716
        }
2724
2717
2725
        my ( $has_been_extended );
2718
        my ( $has_been_extended );
2726
        if ( C4::Context->preference('CumulativeRestrictionPeriods') and $borrower->{debarred} ) {
2719
        if ( C4::Context->preference('CumulativeRestrictionPeriods') and $patron->is_debarred ) {
2727
            my $patron = Koha::Patrons->find($borrower->{borrowernumber});
2728
            my $debarment = $patron->restrictions->search({type => 'SUSPENSION' },{rows => 1})->single;
2720
            my $debarment = $patron->restrictions->search({type => 'SUSPENSION' },{rows => 1})->single;
2729
            if ( $debarment ) {
2721
            if ( $debarment ) {
2730
                $return_date = dt_from_string( $debarment->expiration, 'sql' );
2722
                $return_date = dt_from_string( $debarment->expiration, 'sql' );
Lines 2750-2774 sub _calculate_new_debar_dt { Link Here
2750
}
2742
}
2751
2743
2752
sub _debar_user_on_return {
2744
sub _debar_user_on_return {
2753
    my ( $borrower, $item, $dt_due, $return_date ) = @_;
2745
    my ( $patron, $item, $dt_due, $return_date ) = @_;
2754
2746
2755
    $return_date //= dt_from_string();
2747
    $return_date //= dt_from_string();
2756
2748
2757
    my $new_debar_dt = _calculate_new_debar_dt ($borrower, $item, $dt_due, $return_date);
2749
    my $new_debar_dt = _calculate_new_debar_dt($patron, $item, $dt_due, $return_date);
2758
2750
2759
    return unless $new_debar_dt;
2751
    return unless $new_debar_dt;
2760
2752
2761
    Koha::Patron::Debarments::AddUniqueDebarment({
2753
    Koha::Patron::Debarments::AddUniqueDebarment({
2762
        borrowernumber => $borrower->{borrowernumber},
2754
        borrowernumber => $patron->borrowernumber,
2763
        expiration     => $new_debar_dt->ymd(),
2755
        expiration     => $new_debar_dt->ymd(),
2764
        type           => 'SUSPENSION',
2756
        type           => 'SUSPENSION',
2765
    });
2757
    });
2766
    # if borrower was already debarred but does not get an extra debarment
2758
    # if borrower was already debarred but does not get an extra debarment
2767
    my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
2768
    my ($new_debarment_str, $is_a_reminder);
2759
    my ($new_debarment_str, $is_a_reminder);
2769
    if ( $borrower->{debarred} && $borrower->{debarred} eq $patron->is_debarred ) {
2760
    if ( $patron->is_debarred ) {
2770
        $is_a_reminder = 1;
2761
        $is_a_reminder = 1;
2771
        $new_debarment_str = $borrower->{debarred};
2762
        $new_debarment_str = $patron->debarred;
2772
    } else {
2763
    } else {
2773
        $new_debarment_str = $new_debar_dt->ymd();
2764
        $new_debarment_str = $new_debar_dt->ymd();
2774
    }
2765
    }
Lines 2859-2894 sub _FixOverduesOnReturn { Link Here
2859
2850
2860
=head2 _GetCircControlBranch
2851
=head2 _GetCircControlBranch
2861
2852
2862
   my $circ_control_branch = _GetCircControlBranch($iteminfos, $borrower);
2853
   my $circ_control_branch = _GetCircControlBranch($item, $patron);
2863
2854
2864
Internal function : 
2855
Internal function :
2865
2856
2866
Return the library code to be used to determine which circulation
2857
Return the library code to be used to determine which circulation
2867
policy applies to a transaction.  Looks up the CircControl and
2858
policy applies to a transaction.  Looks up the CircControl and
2868
HomeOrHoldingBranch system preferences.
2859
HomeOrHoldingBranch system preferences.
2869
2860
2870
C<$iteminfos> is a hashref to iteminfo. Only {homebranch or holdingbranch} is used.
2861
C<$item> is an item object.
2871
2862
2872
C<$borrower> is a hashref to borrower. Only {branchcode} is used.
2863
C<$patron> is a patron object.
2873
2864
2874
=cut
2865
=cut
2875
2866
2876
sub _GetCircControlBranch {
2867
sub _GetCircControlBranch {
2877
    my ($item, $borrower) = @_;
2868
    my ($item, $patron) = @_;
2878
    my $circcontrol = C4::Context->preference('CircControl');
2869
    my $circcontrol = C4::Context->preference('CircControl');
2879
    my $branch;
2870
    my $branch;
2880
2871
2881
    if ($circcontrol eq 'PickupLibrary' and (C4::Context->userenv and C4::Context->userenv->{'branch'}) ) {
2872
    if ($circcontrol eq 'PickupLibrary' and (C4::Context->userenv and C4::Context->userenv->{'branch'}) ) {
2882
        $branch= C4::Context->userenv->{'branch'};
2873
        $branch = C4::Context->userenv->{'branch'};
2883
    } elsif ($circcontrol eq 'PatronLibrary') {
2874
    } elsif ($circcontrol eq 'PatronLibrary') {
2884
        $branch=$borrower->{branchcode};
2875
        $branch = $patron->branchcode;
2885
    } else {
2876
    } else {
2886
        my $branchfield = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch';
2877
        my $branchfield = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch';
2887
        $branch = $item->{$branchfield};
2878
        $branch = $item->get_column($branchfield);
2888
        # default to item home branch if holdingbranch is used
2879
        # default to item home branch if holdingbranch is used
2889
        # and is not defined
2880
        # and is not defined
2890
        if (!defined($branch) && $branchfield eq 'holdingbranch') {
2881
        if (!defined($branch) && $branchfield eq 'holdingbranch') {
2891
            $branch = $item->{homebranch};
2882
            $branch = $item->homebranch;
2892
        }
2883
        }
2893
    }
2884
    }
2894
    return $branch;
2885
    return $branch;
Lines 2964-2970 sub CanBookBeRenewed { Link Here
2964
2955
2965
       # override_limit will override anything else except on_reserve
2956
       # override_limit will override anything else except on_reserve
2966
    unless ( $override_limit ){
2957
    unless ( $override_limit ){
2967
        my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
2958
        my $branchcode = _GetCircControlBranch( $item, $patron );
2968
        my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2959
        my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2969
            {
2960
            {
2970
                categorycode => $patron->categorycode,
2961
                categorycode => $patron->categorycode,
Lines 3177-3183 sub AddRenewal { Link Here
3177
    my $patron = Koha::Patrons->find( $borrowernumber ) or return; # FIXME Should do more than just return
3168
    my $patron = Koha::Patrons->find( $borrowernumber ) or return; # FIXME Should do more than just return
3178
    my $patron_unblessed = $patron->unblessed;
3169
    my $patron_unblessed = $patron->unblessed;
3179
3170
3180
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_unblessed, $patron_unblessed) );
3171
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_object, $patron) );
3181
3172
3182
    my $schema = Koha::Database->schema;
3173
    my $schema = Koha::Database->schema;
3183
    $schema->txn_do(sub{
3174
    $schema->txn_do(sub{
Lines 3196-3202 sub AddRenewal { Link Here
3196
            $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
3187
            $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
3197
                                            dt_from_string( $issue->date_due, 'sql' ) :
3188
                                            dt_from_string( $issue->date_due, 'sql' ) :
3198
                                            dt_from_string();
3189
                                            dt_from_string();
3199
            $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, 'is a renewal');
3190
            $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron, 'is a renewal');
3200
        }
3191
        }
3201
3192
3202
        my $fees = Koha::Charges::Fees->new(
3193
        my $fees = Koha::Charges::Fees->new(
Lines 3375-3381 sub GetRenewCount { Link Here
3375
    $renewcount = $data->{'renewals_count'} if $data->{'renewals_count'};
3366
    $renewcount = $data->{'renewals_count'} if $data->{'renewals_count'};
3376
    $unseencount = $data->{'unseen_renewals'} if $data->{'unseen_renewals'};
3367
    $unseencount = $data->{'unseen_renewals'} if $data->{'unseen_renewals'};
3377
    # $item and $borrower should be calculated
3368
    # $item and $borrower should be calculated
3378
    my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed);
3369
    my $branchcode = _GetCircControlBranch($item, $patron);
3379
3370
3380
    my $rules = Koha::CirculationRules->get_effective_rules(
3371
    my $rules = Koha::CirculationRules->get_effective_rules(
3381
        {
3372
        {
Lines 3431-3437 sub GetSoonestRenewDate { Link Here
3431
3422
3432
    my $dbh = C4::Context->dbh;
3423
    my $dbh = C4::Context->dbh;
3433
3424
3434
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
3425
    my $branchcode = _GetCircControlBranch( $item, $patron );
3435
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
3426
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
3436
        {   categorycode => $patron->categorycode,
3427
        {   categorycode => $patron->categorycode,
3437
            itemtype     => $item->effective_itemtype,
3428
            itemtype     => $item->effective_itemtype,
Lines 3498-3505 sub GetLatestAutoRenewDate { Link Here
3498
    return unless $item;
3489
    return unless $item;
3499
3490
3500
    my $dbh = C4::Context->dbh;
3491
    my $dbh = C4::Context->dbh;
3492
    my $branchcode = _GetCircControlBranch( $item, $patron );
3501
3493
3502
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
3503
    my $circulation_rules = Koha::CirculationRules->get_effective_rules(
3494
    my $circulation_rules = Koha::CirculationRules->get_effective_rules(
3504
        {
3495
        {
3505
            categorycode => $patron->categorycode,
3496
            categorycode => $patron->categorycode,
Lines 3796-3814 checking against the holidays calendar as per the daysmode circulation rule. Link Here
3796
C<$startdate>   = DateTime object representing start date of loan period (assumed to be today)
3787
C<$startdate>   = DateTime object representing start date of loan period (assumed to be today)
3797
C<$itemtype>  = itemtype code of item in question
3788
C<$itemtype>  = itemtype code of item in question
3798
C<$branch>  = location whose calendar to use
3789
C<$branch>  = location whose calendar to use
3799
C<$borrower> = Borrower object
3790
C<$patron> = Patron object
3800
C<$isrenewal> = Boolean: is true if we want to calculate the date due for a renewal. Else is false.
3791
C<$isrenewal> = Boolean: is true if we want to calculate the date due for a renewal. Else is false.
3801
3792
3802
=cut
3793
=cut
3803
3794
3804
sub CalcDateDue {
3795
sub CalcDateDue {
3805
    my ( $startdate, $itemtype, $branch, $borrower, $isrenewal ) = @_;
3796
    my ( $startdate, $itemtype, $branch, $patron, $isrenewal ) = @_;
3806
3797
3807
    $isrenewal ||= 0;
3798
    $isrenewal ||= 0;
3808
3799
3809
    # loanlength now a href
3800
    # loanlength now a href
3810
    my $loanlength =
3801
    my $loanlength =
3811
            GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch );
3802
            GetLoanLength( $patron->categorycode, $itemtype, $branch );
3812
3803
3813
    my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} and $loanlength->{renewalperiod} ne q{} )
3804
    my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} and $loanlength->{renewalperiod} ne q{} )
3814
            ? qq{renewalperiod}
3805
            ? qq{renewalperiod}
Lines 3828-3834 sub CalcDateDue { Link Here
3828
3819
3829
    my $daysmode = Koha::CirculationRules->get_effective_daysmode(
3820
    my $daysmode = Koha::CirculationRules->get_effective_daysmode(
3830
        {
3821
        {
3831
            categorycode => $borrower->{categorycode},
3822
            categorycode => $patron->categorycode,
3832
            itemtype     => $itemtype,
3823
            itemtype     => $itemtype,
3833
            branchcode   => $branch,
3824
            branchcode   => $branch,
3834
        }
3825
        }
Lines 3862-3868 sub CalcDateDue { Link Here
3862
3853
3863
    # if Hard Due Dates are used, retrieve them and apply as necessary
3854
    # if Hard Due Dates are used, retrieve them and apply as necessary
3864
    my ( $hardduedate, $hardduedatecompare ) =
3855
    my ( $hardduedate, $hardduedatecompare ) =
3865
      GetHardDueDate( $borrower->{'categorycode'}, $itemtype, $branch );
3856
      GetHardDueDate( $patron->categorycode, $itemtype, $branch );
3866
    if ($hardduedate) {    # hardduedates are currently dates
3857
    if ($hardduedate) {    # hardduedates are currently dates
3867
        $hardduedate->truncate( to => 'minute' );
3858
        $hardduedate->truncate( to => 'minute' );
3868
        $hardduedate->set_hour(23);
3859
        $hardduedate->set_hour(23);
Lines 3882-3888 sub CalcDateDue { Link Here
3882
3873
3883
    # if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate
3874
    # if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate
3884
    if ( C4::Context->preference('ReturnBeforeExpiry') ) {
3875
    if ( C4::Context->preference('ReturnBeforeExpiry') ) {
3885
        my $expiry_dt = dt_from_string( $borrower->{dateexpiry}, 'iso', 'floating');
3876
        my $expiry_dt = dt_from_string( $patron->dateexpiry, 'iso', 'floating');
3886
        if( $expiry_dt ) { #skip empty expiry date..
3877
        if( $expiry_dt ) { #skip empty expiry date..
3887
            $expiry_dt->set( hour => 23, minute => 59);
3878
            $expiry_dt->set( hour => 23, minute => 59);
3888
            my $d1= $datedue->clone->set_time_zone('floating');
3879
            my $d1= $datedue->clone->set_time_zone('floating');
Lines 4165-4171 sub ProcessOfflineIssue { Link Here
4165
            );
4156
            );
4166
        }
4157
        }
4167
        AddIssue(
4158
        AddIssue(
4168
            $patron->unblessed,
4159
            $patron,
4169
            $operation->{'barcode'},
4160
            $operation->{'barcode'},
4170
            undef,
4161
            undef,
4171
            undef,
4162
            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/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 1369-1376 sub check_out { Link Here
1369
        }
1369
        }
1370
1370
1371
        # We can allegedly check out, so make it so
1371
        # We can allegedly check out, so make it so
1372
        # For some reason, AddIssue requires an unblessed Patron
1373
        $issue_args[0] = $patron->unblessed;
1374
        my $issue = C4::Circulation::AddIssue(@issue_args);
1372
        my $issue = C4::Circulation::AddIssue(@issue_args);
1375
1373
1376
        if ($issue) {
1374
        if ($issue) {
(-)a/Koha/Item.pm (-1 / +1 lines)
Lines 1877-1883 sub can_be_recalled { Link Here
1877
1877
1878
    my $branchcode = C4::Context->userenv->{'branch'};
1878
    my $branchcode = C4::Context->userenv->{'branch'};
1879
    if ( $patron ) {
1879
    if ( $patron ) {
1880
        $branchcode = C4::Circulation::_GetCircControlBranch( $self->unblessed, $patron->unblessed );
1880
        $branchcode = C4::Circulation::_GetCircControlBranch( $self, $patron );
1881
    }
1881
    }
1882
1882
1883
    # Check the circulation rule for each relevant itemtype for this item
1883
    # 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 399-405 if (@$barcodes) { Link Here
399
                );
399
                );
400
                $recall_id = ( $recall and $recall->id ) ? $recall->id : undef;
400
                $recall_id = ( $recall and $recall->id ) ? $recall->id : undef;
401
            }
401
            }
402
            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, } );
402
            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, } );
403
            $template_params->{issue} = $issue;
403
            $template_params->{issue} = $issue;
404
            $session->clear('auto_renew');
404
            $session->clear('auto_renew');
405
            $inprocess = 1;
405
            $inprocess = 1;
(-)a/offline_circ/process_koc.pl (-19 / +18 lines)
Lines 190-196 sub kocIssueItem { Link Here
190
190
191
    my $branchcode = C4::Context->userenv->{branch};
191
    my $branchcode = C4::Context->userenv->{branch};
192
    my $patron = Koha::Patrons->find( { cardnumber => $circ->{cardnumber} } );
192
    my $patron = Koha::Patrons->find( { cardnumber => $circ->{cardnumber} } );
193
    my $borrower = $patron->unblessed;
194
    my $item = Koha::Items->find({ barcode => $circ->{barcode} });
193
    my $item = Koha::Items->find({ barcode => $circ->{barcode} });
195
    my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
194
    my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
196
    my $biblio = $item->biblio;
195
    my $biblio = $item->biblio;
Lines 198-204 sub kocIssueItem { Link Here
198
    if ( $issue ) { ## Item is currently checked out to another person.
197
    if ( $issue ) { ## Item is currently checked out to another person.
199
        #warn "Item Currently Issued.";
198
        #warn "Item Currently Issued.";
200
199
201
        if ( $issue->borrowernumber eq $borrower->{'borrowernumber'} ) { ## Issued to this person already, renew it.
200
        if ( $issue->borrowernumber eq $patron->borrowernumber ) { ## Issued to this person already, renew it.
202
            #warn "Item issued to this member already, renewing.";
201
            #warn "Item issued to this member already, renewing.";
203
202
204
            C4::Circulation::AddRenewal(
203
            C4::Circulation::AddRenewal(
Lines 214-224 sub kocIssueItem { Link Here
214
                title => $biblio->title,
213
                title => $biblio->title,
215
                biblionumber => $biblio->biblionumber,
214
                biblionumber => $biblio->biblionumber,
216
                barcode => $item->barcode,
215
                barcode => $item->barcode,
217
                firstname => $borrower->{ 'firstname' },
216
                firstname => $patron->firstname,
218
                surname => $borrower->{ 'surname' },
217
                surname => $patron->surname,
219
                borrowernumber => $borrower->{'borrowernumber'},
218
                borrowernumber => $patron->borrowernumber,
220
                cardnumber => $borrower->{'cardnumber'},
219
                cardnumber => $patron->cardnumber,
221
                datetime => $circ->{ 'datetime' }
220
                datetime => $circ->datetime
222
            };
221
            };
223
222
224
        } else {
223
        } else {
Lines 229-245 sub kocIssueItem { Link Here
229
            my ( $c_y, $c_m, $c_d ) = split( /-/, $circ->{'date'} );
228
            my ( $c_y, $c_m, $c_d ) = split( /-/, $circ->{'date'} );
230
229
231
            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.
230
            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.
232
                C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
231
                C4::Circulation::AddIssue( $patron, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
233
                push @output, {
232
                push @output, {
234
                    issue => 1,
233
                    issue => 1,
235
                    title => $biblio->title,
234
                    title => $biblio->title,
236
                    biblionumber => $biblio->biblionumber,
235
                    biblionumber => $biblio->biblionumber,
237
                    barcode => $item->barcode,
236
                    barcode => $item->barcode,
238
                    firstname => $borrower->{ 'firstname' },
237
                    firstname => $patron->firstname,
239
                    surname => $borrower->{ 'surname' },
238
                    surname => $patron->surname,
240
                    borrowernumber => $borrower->{'borrowernumber'},
239
                    borrowernumber => $patron->borrowernumber,
241
                    cardnumber => $borrower->{'cardnumber'},
240
                    cardnumber => $patron->cardnumber,
242
                    datetime => $circ->{ 'datetime' }
241
                    datetime => $circ->datetime
243
                };
242
                };
244
243
245
            } 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.
244
            } 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 249-265 sub kocIssueItem { Link Here
249
            }
248
            }
250
        }
249
        }
251
    } else { ## Item is not checked out to anyone at the moment, go ahead and issue it
250
    } else { ## Item is not checked out to anyone at the moment, go ahead and issue it
252
        C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
251
        C4::Circulation::AddIssue( $patron, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
253
        push @output, {
252
        push @output, {
254
            issue => 1,
253
            issue => 1,
255
            title => $biblio->title,
254
            title => $biblio->title,
256
            biblionumber => $biblio->biblionumber,
255
            biblionumber => $biblio->biblionumber,
257
            barcode => $item->barcode,
256
            barcode => $item->barcode,
258
            firstname => $borrower->{ 'firstname' },
257
            firstname => $patron->firstname,
259
            surname => $borrower->{ 'surname' },
258
            surname => $patron->surname,
260
            borrowernumber => $borrower->{'borrowernumber'},
259
            borrowernumber => $patron->borrowernumber,
261
            cardnumber => $borrower->{'cardnumber'},
260
            cardnumber => $patron->cardnumber,
262
            datetime =>$circ->{ 'datetime' }
261
            datetime =>$circ->datetime
263
        };
262
        };
264
    }
263
    }
265
}
264
}
(-)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 476-483 if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold ) Link Here
476
                }
476
                }
477
477
478
                if ( $patron ) {
478
                if ( $patron ) {
479
                    my $patron_unblessed = $patron->unblessed;
479
                    my $branch = _GetCircControlBranch($item_object, $patron);
480
                    my $branch = C4::Circulation::_GetCircControlBranch($item, $patron_unblessed);
481
480
482
                    my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
481
                    my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
483
482
(-)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 (-105 / +119 lines)
Lines 90-96 sub test_debarment_on_checkout { Link Here
90
    );
90
    );
91
    my @caller      = caller;
91
    my @caller      = caller;
92
    my $line_number = $caller[2];
92
    my $line_number = $caller[2];
93
    AddIssue( $patron->unblessed, $item->barcode, $due_date );
93
    AddIssue( $patron, $item->barcode, $due_date );
94
94
95
    my ( undef, $message ) = AddReturn( $item->barcode, $library->{branchcode}, undef, $return_date );
95
    my ( undef, $message ) = AddReturn( $item->barcode, $library->{branchcode}, undef, $return_date );
96
    is( $message->{WasReturned} && exists $message->{Debarred}, 1, 'AddReturn must have debarred the patron' )
96
    is( $message->{WasReturned} && exists $message->{Debarred}, 1, 'AddReturn must have debarred the patron' )
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 519-529 subtest "CanBookBeRenewed tests" => sub { Link Here
519
    my $checkitem      = undef;
523
    my $checkitem      = undef;
520
    my $found          = undef;
524
    my $found          = undef;
521
525
522
    my $issue_1 = AddIssue( $renewing_borrower_obj->unblessed, $item_1->barcode);
526
    my $issue_1 = AddIssue( $renewing_borrower_obj, $item_1->barcode);
523
    my $datedue = dt_from_string( $issue_1->date_due() );
527
    my $datedue = dt_from_string( $issue_1->date_due() );
524
    is (defined $issue_1->date_due(), 1, "Item 1 checked out, due date: " . $issue_1->date_due() );
528
    is (defined $issue_1->date_due(), 1, "Item 1 checked out, due date: " . $issue_1->date_due() );
525
529
526
    my $issue_2 = AddIssue( $renewing_borrower_obj->unblessed, $item_2->barcode);
530
    my $issue_2 = AddIssue( $renewing_borrower_obj, $item_2->barcode);
527
    is (defined $issue_2, 1, "Item 2 checked out, due date: " . $issue_2->date_due());
531
    is (defined $issue_2, 1, "Item 2 checked out, due date: " . $issue_2->date_due());
528
532
529
    my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $item_1->itemnumber } )->borrowernumber;
533
    my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $item_1->itemnumber } )->borrowernumber;
Lines 634-640 subtest "CanBookBeRenewed tests" => sub { Link Here
634
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
638
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
635
639
636
    my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
640
    my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
637
    my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber )->unblessed;
641
    my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber );
638
    AddIssue($reserving_borrower, $item_3->barcode);
642
    AddIssue($reserving_borrower, $item_3->barcode);
639
    my $reserve = $dbh->selectrow_hashref(
643
    my $reserve = $dbh->selectrow_hashref(
640
        'SELECT * FROM old_reserves WHERE reserve_id = ?',
644
        'SELECT * FROM old_reserves WHERE reserve_id = ?',
Lines 682-688 subtest "CanBookBeRenewed tests" => sub { Link Here
682
            itype            => $itemtype,
686
            itype            => $itemtype,
683
        }
687
        }
684
    );
688
    );
685
    my $issue_5 = AddIssue($restricted_borrower_obj->unblessed, $item_5->barcode);
689
    my $issue_5 = AddIssue($restricted_borrower_obj, $item_5->barcode);
686
    is (defined $issue_5, 1, "Item with date due checked out, due date: ". $issue_5->date_due);
690
    is (defined $issue_5, 1, "Item with date due checked out, due date: ". $issue_5->date_due);
687
691
688
    t::lib::Mocks::mock_preference('RestrictionBlockRenewing','1');
692
    t::lib::Mocks::mock_preference('RestrictionBlockRenewing','1');
Lines 711-717 subtest "CanBookBeRenewed tests" => sub { Link Here
711
        }
715
        }
712
    );
716
    );
713
717
714
    my $issue_6 = AddIssue( $renewing_borrower_obj->unblessed, $item_6->barcode);
718
    my $issue_6 = AddIssue( $renewing_borrower_obj, $item_6->barcode);
715
    is (defined $issue_6, 1, "Item 2 checked out, due date: ".$issue_6->date_due);
719
    is (defined $issue_6, 1, "Item 2 checked out, due date: ".$issue_6->date_due);
716
720
717
    my $now = dt_from_string();
721
    my $now = dt_from_string();
Lines 719-725 subtest "CanBookBeRenewed tests" => sub { Link Here
719
    my $five_weeks_ago = $now - $five_weeks;
723
    my $five_weeks_ago = $now - $five_weeks;
720
    t::lib::Mocks::mock_preference('finesMode', 'production');
724
    t::lib::Mocks::mock_preference('finesMode', 'production');
721
725
722
    my $issue_7 = AddIssue($renewing_borrower_obj->unblessed, $item_7->barcode, $five_weeks_ago);
726
    my $issue_7 = AddIssue($renewing_borrower_obj, $item_7->barcode, $five_weeks_ago);
723
    is (defined $issue_7, 1, "Item with passed date due checked out, due date: " . $issue_7->date_due);
727
    is (defined $issue_7, 1, "Item with passed date due checked out, due date: " . $issue_7->date_due);
724
728
725
    t::lib::Mocks::mock_preference('OverduesBlockRenewing','allow');
729
    t::lib::Mocks::mock_preference('OverduesBlockRenewing','allow');
Lines 812-818 subtest "CanBookBeRenewed tests" => sub { Link Here
812
    my $old_issue_log_size = Koha::ActionLogs->count( \%params_issue );
816
    my $old_issue_log_size = Koha::ActionLogs->count( \%params_issue );
813
    my $old_renew_log_size = Koha::ActionLogs->count( \%params_renewal );
817
    my $old_renew_log_size = Koha::ActionLogs->count( \%params_renewal );
814
    AddIssue(
818
    AddIssue(
815
        $renewing_borrower_obj->unblessed,
819
        $renewing_borrower_obj,
816
        $item_7->barcode,
820
        $item_7->barcode,
817
        Koha::DateUtils::output_pref({str=>$issue_6->date_due, dateformat =>'iso'}),
821
        Koha::DateUtils::output_pref({str=>$issue_6->date_due, dateformat =>'iso'}),
818
        0,
822
        0,
Lines 840-846 subtest "CanBookBeRenewed tests" => sub { Link Here
840
        }
844
        }
841
    );
845
    );
842
846
843
    my $issue_4 = AddIssue( $renewing_borrower_obj->unblessed, $item_4->barcode, undef, undef, undef, undef, { auto_renew => 1 } );
847
    my $issue_4 = AddIssue( $renewing_borrower_obj, $item_4->barcode, undef, undef, undef, undef, { auto_renew => 1 } );
844
    my $info;
848
    my $info;
845
    ( $renewokay, $error, $info ) =
849
    ( $renewokay, $error, $info ) =
846
      CanBookBeRenewed( $renewing_borrower_obj, $issue_4 );
850
      CanBookBeRenewed( $renewing_borrower_obj, $issue_4 );
Lines 970-976 subtest "CanBookBeRenewed tests" => sub { Link Here
970
974
971
        my $ten_days_before = dt_from_string->add( days => -10 );
975
        my $ten_days_before = dt_from_string->add( days => -10 );
972
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
976
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
973
        my $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
977
        my $issue = AddIssue( $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
974
978
975
        Koha::CirculationRules->set_rules(
979
        Koha::CirculationRules->set_rules(
976
            {
980
            {
Lines 1099-1105 subtest "CanBookBeRenewed tests" => sub { Link Here
1099
1103
1100
        my $ten_days_before = dt_from_string->add( days => -10 );
1104
        my $ten_days_before = dt_from_string->add( days => -10 );
1101
        my $ten_days_ahead = dt_from_string->add( days => 10 );
1105
        my $ten_days_ahead = dt_from_string->add( days => 10 );
1102
        my $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1106
        my $issue = AddIssue( $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1103
1107
1104
        Koha::CirculationRules->set_rules(
1108
        Koha::CirculationRules->set_rules(
1105
            {
1109
            {
Lines 1209-1215 subtest "CanBookBeRenewed tests" => sub { Link Here
1209
        # Patron is expired and BlockExpiredPatronOpacActions=0
1213
        # Patron is expired and BlockExpiredPatronOpacActions=0
1210
        # => auto renew is allowed
1214
        # => auto renew is allowed
1211
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 0);
1215
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 0);
1212
        my $issue = AddIssue( $expired_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1216
        my $issue = AddIssue( $expired_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1213
        ( $renewokay, $error ) =
1217
        ( $renewokay, $error ) =
1214
          CanBookBeRenewed( $expired_borrower_obj, $issue );
1218
          CanBookBeRenewed( $expired_borrower_obj, $issue );
1215
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1219
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
Lines 1220-1226 subtest "CanBookBeRenewed tests" => sub { Link Here
1220
        # Patron is expired and BlockExpiredPatronOpacActions=1
1224
        # Patron is expired and BlockExpiredPatronOpacActions=1
1221
        # => auto renew is not allowed
1225
        # => auto renew is not allowed
1222
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
1226
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
1223
        $issue = AddIssue( $expired_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1227
        $issue = AddIssue( $expired_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1224
        ( $renewokay, $error ) =
1228
        ( $renewokay, $error ) =
1225
          CanBookBeRenewed( $expired_borrower_obj, $issue );
1229
          CanBookBeRenewed( $expired_borrower_obj, $issue );
1226
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1230
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
Lines 1230-1236 subtest "CanBookBeRenewed tests" => sub { Link Here
1230
        # Patron is not expired and BlockExpiredPatronOpacActions=1
1234
        # Patron is not expired and BlockExpiredPatronOpacActions=1
1231
        # => auto renew is allowed
1235
        # => auto renew is allowed
1232
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
1236
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
1233
        $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1237
        $issue = AddIssue( $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1234
        ( $renewokay, $error ) =
1238
        ( $renewokay, $error ) =
1235
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1239
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1236
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1240
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
Lines 1249-1255 subtest "CanBookBeRenewed tests" => sub { Link Here
1249
1253
1250
        my $ten_days_before = dt_from_string->add( days => -10 );
1254
        my $ten_days_before = dt_from_string->add( days => -10 );
1251
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
1255
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
1252
        my $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1256
        my $issue = AddIssue( $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1253
        Koha::CirculationRules->set_rules(
1257
        Koha::CirculationRules->set_rules(
1254
            {
1258
            {
1255
                categorycode => undef,
1259
                categorycode => undef,
Lines 1501-1507 subtest "CanBookBeRenewed tests" => sub { Link Here
1501
    my $recall_item1 = $builder->build_sample_item({ biblionumber => $recall_biblio->biblionumber });
1505
    my $recall_item1 = $builder->build_sample_item({ biblionumber => $recall_biblio->biblionumber });
1502
    my $recall_item2 = $builder->build_sample_item({ biblionumber => $recall_biblio->biblionumber });
1506
    my $recall_item2 = $builder->build_sample_item({ biblionumber => $recall_biblio->biblionumber });
1503
1507
1504
    my $recall_issue = AddIssue( $renewing_borrower_obj->unblessed, $recall_item1->barcode );
1508
    my $recall_issue = AddIssue( $renewing_borrower_obj, $recall_item1->barcode );
1505
1509
1506
    # item-level and this item: renewal not allowed
1510
    # item-level and this item: renewal not allowed
1507
    my $recall = Koha::Recall->new({
1511
    my $recall = Koha::Recall->new({
Lines 1582-1588 subtest "GetUpcomingDueIssues" => sub { Link Here
1582
    );
1586
    );
1583
1587
1584
    my $a_borrower_borrowernumber = Koha::Patron->new(\%a_borrower_data)->store->borrowernumber;
1588
    my $a_borrower_borrowernumber = Koha::Patron->new(\%a_borrower_data)->store->borrowernumber;
1585
    my $a_borrower = Koha::Patrons->find( $a_borrower_borrowernumber )->unblessed;
1589
    my $a_borrower = Koha::Patrons->find( $a_borrower_borrowernumber );
1586
1590
1587
    my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 );
1591
    my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 );
1588
    my $two_days_ahead = DateTime->today(time_zone => C4::Context->tz())->add( days => 2 );
1592
    my $two_days_ahead = DateTime->today(time_zone => C4::Context->tz())->add( days => 2 );
Lines 1659-1665 subtest "Bug 13841 - Do not create new 0 amount fines" => sub { Link Here
1659
1663
1660
    my $borrowernumber = Koha::Patron->new(\%a_borrower_data)->store->borrowernumber;
1664
    my $borrowernumber = Koha::Patron->new(\%a_borrower_data)->store->borrowernumber;
1661
1665
1662
    my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
1666
    my $borrower = Koha::Patrons->find( $borrowernumber );
1663
    my $issue = AddIssue( $borrower, $item->barcode );
1667
    my $issue = AddIssue( $borrower, $item->barcode );
1664
    UpdateFine(
1668
    UpdateFine(
1665
        {
1669
        {
Lines 1745-1751 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1745
        branchcode   => $library2->{branchcode},
1749
        branchcode   => $library2->{branchcode},
1746
    })->store->borrowernumber;
1750
    })->store->borrowernumber;
1747
1751
1748
    my $issue = AddIssue( $borrower1->unblessed, $item_1->barcode );
1752
    my $issue = AddIssue( $borrower1, $item_1->barcode );
1749
1753
1750
    my ( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue );
1754
    my ( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue );
1751
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' );
1755
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' );
Lines 1912-1918 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1912
        branchcode => $branch,
1916
        branchcode => $branch,
1913
    })->store;
1917
    })->store;
1914
1918
1915
    my $issue = AddIssue( $borrower->unblessed, $item->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } );
1919
    my $issue = AddIssue( $borrower, $item->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } );
1916
    my ( $renewed, $error ) = CanBookBeRenewed( $borrower, $issue );
1920
    my ( $renewed, $error ) = CanBookBeRenewed( $borrower, $issue );
1917
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew on-site checkout' );
1921
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew on-site checkout' );
1918
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
1922
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
Lines 1932-1938 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1932
    );
1936
    );
1933
    my $patron = $builder->build_object( { class => 'Koha::Patrons',  value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } );
1937
    my $patron = $builder->build_object( { class => 'Koha::Patrons',  value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } );
1934
1938
1935
    my $issue = AddIssue( $patron->unblessed, $item->barcode );
1939
    my $issue = AddIssue( $patron, $item->barcode );
1936
    UpdateFine(
1940
    UpdateFine(
1937
        {
1941
        {
1938
            issue_id       => $issue->id,
1942
            issue_id       => $issue->id,
Lines 1991-1997 subtest 'CanBookBeIssued & AllowReturnToBranch' => sub { Link Here
1991
1995
1992
    set_userenv($holdingbranch);
1996
    set_userenv($holdingbranch);
1993
1997
1994
    my $issue = AddIssue( $patron_1->unblessed, $item->barcode );
1998
    my $issue = AddIssue( $patron_1, $item->barcode );
1995
    is( ref($issue), 'Koha::Checkout', 'AddIssue should return a Koha::Checkout object' );
1999
    is( ref($issue), 'Koha::Checkout', 'AddIssue should return a Koha::Checkout object' );
1996
2000
1997
    my ( $error, $question, $alerts );
2001
    my ( $error, $question, $alerts );
Lines 2066-2073 subtest 'AddIssue & AllowReturnToBranch' => sub { Link Here
2066
    my $homebranch    = $builder->build( { source => 'Branch' } );
2070
    my $homebranch    = $builder->build( { source => 'Branch' } );
2067
    my $holdingbranch = $builder->build( { source => 'Branch' } );
2071
    my $holdingbranch = $builder->build( { source => 'Branch' } );
2068
    my $otherbranch   = $builder->build( { source => 'Branch' } );
2072
    my $otherbranch   = $builder->build( { source => 'Branch' } );
2069
    my $patron_1      = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } );
2073
2070
    my $patron_2      = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } );
2074
    my $patron_1  = $builder->build_object({
2075
        class => 'Koha::Patrons',
2076
        value => { categorycode => $patron_category->{categorycode} }
2077
    });
2078
2079
    my $patron_2  = $builder->build_object({
2080
        class => 'Koha::Patrons',
2081
        value => { categorycode => $patron_category->{categorycode} }
2082
    });
2083
2071
2084
2072
    my $item = $builder->build_sample_item(
2085
    my $item = $builder->build_sample_item(
2073
        {
2086
        {
Lines 2152-2158 subtest 'AddIssue | recalls' => sub { Link Here
2152
            pickup_library_id => $patron1->branchcode,
2165
            pickup_library_id => $patron1->branchcode,
2153
        }
2166
        }
2154
    )->store;
2167
    )->store;
2155
    AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall1->id } );
2168
    AddIssue( $patron1, $item->barcode, undef, undef, undef, undef, { recall_id => $recall1->id } );
2156
    $recall1 = Koha::Recalls->find( $recall1->id );
2169
    $recall1 = Koha::Recalls->find( $recall1->id );
2157
    is( $recall1->fulfilled, 1, 'Recall was fulfilled when patron checked out item' );
2170
    is( $recall1->fulfilled, 1, 'Recall was fulfilled when patron checked out item' );
2158
    AddReturn( $item->barcode, $item->homebranch );
2171
    AddReturn( $item->barcode, $item->homebranch );
Lines 2166-2172 subtest 'AddIssue | recalls' => sub { Link Here
2166
            pickup_library_id => $patron2->branchcode,
2179
            pickup_library_id => $patron2->branchcode,
2167
        }
2180
        }
2168
    )->store;
2181
    )->store;
2169
    AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall2->id, cancel_recall => 'cancel' } );
2182
    AddIssue( $patron1, $item->barcode, undef, undef, undef, undef, { recall_id => $recall2->id, cancel_recall => 'cancel' } );
2170
    $recall2 = Koha::Recalls->find( $recall2->id );
2183
    $recall2 = Koha::Recalls->find( $recall2->id );
2171
    is( $recall2->cancelled, 1, 'Recall was cancelled when patron checked out item' );
2184
    is( $recall2->cancelled, 1, 'Recall was cancelled when patron checked out item' );
2172
    AddReturn( $item->barcode, $item->homebranch );
2185
    AddReturn( $item->barcode, $item->homebranch );
Lines 2181-2187 subtest 'AddIssue | recalls' => sub { Link Here
2181
        }
2194
        }
2182
    )->store;
2195
    )->store;
2183
    $recall3->set_waiting;
2196
    $recall3->set_waiting;
2184
    AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall3->id, cancel_recall => 'revert' } );
2197
    AddIssue( $patron1, $item->barcode, undef, undef, undef, undef, { recall_id => $recall3->id, cancel_recall => 'revert' } );
2185
    $recall3 = Koha::Recalls->find( $recall3->id );
2198
    $recall3 = Koha::Recalls->find( $recall3->id );
2186
    is( $recall3->requested, 1, 'Recall was reverted from waiting when patron checked out item' );
2199
    is( $recall3->requested, 1, 'Recall was reverted from waiting when patron checked out item' );
2187
    AddReturn( $item->barcode, $item->homebranch );
2200
    AddReturn( $item->barcode, $item->homebranch );
Lines 2206-2212 subtest 'AddIssue & illrequests.due_date' => sub { Link Here
2206
        due_date => $custom_date_due,
2219
        due_date => $custom_date_due,
2207
    })->store;
2220
    })->store;
2208
2221
2209
    my $issue = AddIssue( $patron->unblessed, $item->barcode );
2222
    my $issue = AddIssue( $patron, $item->barcode );
2210
    is( $issue->date_due, $expected_date_due, 'Custom illrequest date due has been set for this issue');
2223
    is( $issue->date_due, $expected_date_due, 'Custom illrequest date due has been set for this issue');
2211
2224
2212
    $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2225
    $patron = $builder->build_object( { class => 'Koha::Patrons' } );
Lines 2220-2226 subtest 'AddIssue & illrequests.due_date' => sub { Link Here
2220
        due_date => $custom_date_due,
2233
        due_date => $custom_date_due,
2221
    })->store;
2234
    })->store;
2222
2235
2223
    $issue = AddIssue( $patron->unblessed, $item->barcode );
2236
    $issue = AddIssue( $patron, $item->barcode );
2224
    is( $issue->date_due, $expected_date_due, 'Custom illrequest date due has been set for this issue');
2237
    is( $issue->date_due, $expected_date_due, 'Custom illrequest date due has been set for this issue');
2225
};
2238
};
2226
2239
Lines 2263-2269 subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { Link Here
2263
2276
2264
    # Patron cannot issue item_1, they have overdues
2277
    # Patron cannot issue item_1, they have overdues
2265
    my $yesterday = DateTime->today( time_zone => C4::Context->tz() )->add( days => -1 );
2278
    my $yesterday = DateTime->today( time_zone => C4::Context->tz() )->add( days => -1 );
2266
    my $issue = AddIssue( $patron->unblessed, $item_1->barcode, $yesterday );    # Add an overdue
2279
    my $issue = AddIssue( $patron, $item_1->barcode, $yesterday );    # Add an overdue
2267
2280
2268
    t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'confirmation' );
2281
    t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'confirmation' );
2269
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->barcode );
2282
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->barcode );
Lines 2372-2378 subtest 'MultipleReserves' => sub { Link Here
2372
        branchcode => $branch,
2385
        branchcode => $branch,
2373
    );
2386
    );
2374
    my $patron = Koha::Patron->new(\%renewing_borrower_data)->store;
2387
    my $patron = Koha::Patron->new(\%renewing_borrower_data)->store;
2375
    my $issue = AddIssue( $patron->unblessed, $item_1->barcode);
2388
    my $issue = AddIssue( $patron, $item_1->barcode);
2376
    my $datedue = dt_from_string( $issue->date_due() );
2389
    my $datedue = dt_from_string( $issue->date_due() );
2377
    is (defined $issue->date_due(), 1, "item 1 checked out");
2390
    is (defined $issue->date_due(), 1, "item 1 checked out");
2378
    my $borrowing_borrowernumber = Koha::Checkouts->find({ itemnumber => $item_1->itemnumber })->borrowernumber;
2391
    my $borrowing_borrowernumber = Koha::Checkouts->find({ itemnumber => $item_1->itemnumber })->borrowernumber;
Lines 2485-2491 subtest 'CanBookBeIssued + AllowMultipleIssuesOnABiblio' => sub { Link Here
2485
    );
2498
    );
2486
2499
2487
    my ( $error, $question, $alerts );
2500
    my ( $error, $question, $alerts );
2488
    my $issue = AddIssue( $patron->unblessed, $item_1->barcode, dt_from_string->add( days => 1 ) );
2501
    my $issue = AddIssue( $patron, $item_1->barcode, dt_from_string->add( days => 1 ) );
2489
2502
2490
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
2503
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
2491
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->barcode );
2504
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->barcode );
Lines 2569-2576 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
2569
    my $now = dt_from_string;
2582
    my $now = dt_from_string;
2570
    my $five_days_ago = $now->clone->subtract( days => 5 );
2583
    my $five_days_ago = $now->clone->subtract( days => 5 );
2571
    my $ten_days_ago  = $now->clone->subtract( days => 10 );
2584
    my $ten_days_ago  = $now->clone->subtract( days => 10 );
2572
    AddIssue( $patron->unblessed, $item_1->barcode, $five_days_ago );    # Add an overdue
2585
    AddIssue( $patron, $item_1->barcode, $five_days_ago );    # Add an overdue
2573
    AddIssue( $patron->unblessed, $item_2->barcode, $ten_days_ago )
2586
    AddIssue( $patron, $item_2->barcode, $ten_days_ago )
2574
      ;    # Add another overdue
2587
      ;    # Add another overdue
2575
2588
2576
    t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' );
2589
    t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' );
Lines 2608-2615 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
2608
        { borrowernumber => $patron->borrowernumber, type => 'SUSPENSION' } );
2621
        { borrowernumber => $patron->borrowernumber, type => 'SUSPENSION' } );
2609
2622
2610
    t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '1' );
2623
    t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '1' );
2611
    AddIssue( $patron->unblessed, $item_1->barcode, $five_days_ago );    # Add an overdue
2624
    AddIssue( $patron, $item_1->barcode, $five_days_ago );    # Add an overdue
2612
    AddIssue( $patron->unblessed, $item_2->barcode, $ten_days_ago )
2625
    AddIssue( $patron, $item_2->barcode, $ten_days_ago )
2613
      ;    # Add another overdue
2626
      ;    # Add another overdue
2614
    AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now );
2627
    AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now );
2615
    $suspensions = $patron->restrictions->search( { type => 'SUSPENSION' } );
2628
    $suspensions = $patron->restrictions->search( { type => 'SUSPENSION' } );
Lines 2892-2898 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
2892
        }
2905
        }
2893
    );
2906
    );
2894
2907
2895
    AddIssue( $patron->unblessed, $item_1->barcode, $now->clone->subtract( days => 1 ) );
2908
    AddIssue( $patron, $item_1->barcode, $now->clone->subtract( days => 1 ) );
2896
    my ( undef, $message ) = AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now );
2909
    my ( undef, $message ) = AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now );
2897
    is( $message->{WasReturned} && exists $message->{ForeverDebarred}, 1, 'Forever debarred message for Addreturn when overdue');
2910
    is( $message->{WasReturned} && exists $message->{ForeverDebarred}, 1, 'Forever debarred message for Addreturn when overdue');
2898
2911
Lines 2910-2916 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
2910
        }
2923
        }
2911
    );
2924
    );
2912
2925
2913
    AddIssue( $patron->unblessed, $item_1->barcode, $now->clone->subtract( days => 1 ) );
2926
    AddIssue( $patron, $item_1->barcode, $now->clone->subtract( days => 1 ) );
2914
    (undef, $message) = AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now );
2927
    (undef, $message) = AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now );
2915
    is( $message->{WasReturned} && exists $message->{PrevDebarred}, 1, 'Previously debarred message for Addreturn when overdue');
2928
    is( $message->{WasReturned} && exists $message->{PrevDebarred}, 1, 'Previously debarred message for Addreturn when overdue');
2916
};
2929
};
Lines 2947-2953 subtest 'CanBookBeIssued + AutoReturnCheckedOutItems' => sub { Link Here
2947
    );
2960
    );
2948
2961
2949
    my ( $error, $question, $alerts );
2962
    my ( $error, $question, $alerts );
2950
    my $issue = AddIssue( $patron1->unblessed, $item->barcode );
2963
    my $issue = AddIssue( $patron1, $item->barcode );
2951
2964
2952
    t::lib::Mocks::mock_preference('AutoReturnCheckedOutItems', 0);
2965
    t::lib::Mocks::mock_preference('AutoReturnCheckedOutItems', 0);
2953
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron2, $item->barcode );
2966
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron2, $item->barcode );
Lines 3008-3032 subtest 'AddReturn | is_overdue' => sub { Link Here
3008
    my $ten_days_ago  = $now->clone->subtract( days => 10 );
3021
    my $ten_days_ago  = $now->clone->subtract( days => 10 );
3009
3022
3010
    # No return date specified, today will be used => 10 days overdue charged
3023
    # No return date specified, today will be used => 10 days overdue charged
3011
    AddIssue( $patron->unblessed, $item->barcode, $ten_days_ago ); # date due was 10d ago
3024
    AddIssue( $patron, $item->barcode, $ten_days_ago ); # date due was 10d ago
3012
    AddReturn( $item->barcode, $library->{branchcode} );
3025
    AddReturn( $item->barcode, $library->{branchcode} );
3013
    is( int($patron->account->balance()), 10, 'Patron should have a charge of 10 (10 days x 1)' );
3026
    is( int($patron->account->balance()), 10, 'Patron should have a charge of 10 (10 days x 1)' );
3014
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
3027
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
3015
3028
3016
    # specify return date 5 days before => no overdue charged
3029
    # specify return date 5 days before => no overdue charged
3017
    AddIssue( $patron->unblessed, $item->barcode, $five_days_ago ); # date due was 5d ago
3030
    AddIssue( $patron, $item->barcode, $five_days_ago ); # date due was 5d ago
3018
    AddReturn( $item->barcode, $library->{branchcode}, undef, $ten_days_ago );
3031
    AddReturn( $item->barcode, $library->{branchcode}, undef, $ten_days_ago );
3019
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
3032
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
3020
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
3033
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
3021
3034
3022
    # specify return date 5 days later => 5 days overdue charged
3035
    # specify return date 5 days later => 5 days overdue charged
3023
    AddIssue( $patron->unblessed, $item->barcode, $ten_days_ago ); # date due was 10d ago
3036
    AddIssue( $patron, $item->barcode, $ten_days_ago ); # date due was 10d ago
3024
    AddReturn( $item->barcode, $library->{branchcode}, undef, $five_days_ago );
3037
    AddReturn( $item->barcode, $library->{branchcode}, undef, $five_days_ago );
3025
    is( int($patron->account->balance()), 5, 'AddReturn: pass return_date => overdue' );
3038
    is( int($patron->account->balance()), 5, 'AddReturn: pass return_date => overdue' );
3026
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
3039
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
3027
3040
3028
    # specify return date 5 days later, specify exemptfine => no overdue charge
3041
    # specify return date 5 days later, specify exemptfine => no overdue charge
3029
    AddIssue( $patron->unblessed, $item->barcode, $ten_days_ago ); # date due was 10d ago
3042
    AddIssue( $patron, $item->barcode, $ten_days_ago ); # date due was 10d ago
3030
    AddReturn( $item->barcode, $library->{branchcode}, 1, $five_days_ago );
3043
    AddReturn( $item->barcode, $library->{branchcode}, 1, $five_days_ago );
3031
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
3044
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
3032
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
3045
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
Lines 3035-3041 subtest 'AddReturn | is_overdue' => sub { Link Here
3035
3048
3036
        plan tests => 3;
3049
        plan tests => 3;
3037
3050
3038
        my $issue = AddIssue( $patron->unblessed, $item->barcode, $ten_days_ago );    # date due was 10d ago
3051
        my $issue = AddIssue( $patron, $item->barcode, $ten_days_ago );    # date due was 10d ago
3039
3052
3040
        # Fake fines cronjob on this checkout
3053
        # Fake fines cronjob on this checkout
3041
        my ($fine) =
3054
        my ($fine) =
Lines 3073-3079 subtest 'AddReturn | is_overdue' => sub { Link Here
3073
3086
3074
        t::lib::Mocks::mock_preference('CalculateFinesOnBackdate', 1);
3087
        t::lib::Mocks::mock_preference('CalculateFinesOnBackdate', 1);
3075
3088
3076
        my $issue = AddIssue( $patron->unblessed, $item->barcode, $one_day_ago );    # date due was 1d ago
3089
        my $issue = AddIssue( $patron, $item->barcode, $one_day_ago );    # date due was 1d ago
3077
3090
3078
        # Fake fines cronjob on this checkout
3091
        # Fake fines cronjob on this checkout
3079
        my ($fine) =
3092
        my ($fine) =
Lines 3098-3104 subtest 'AddReturn | is_overdue' => sub { Link Here
3098
        my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber });
3111
        my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber });
3099
        is( $lines->count, 0, "Overdue fine accountline has been removed");
3112
        is( $lines->count, 0, "Overdue fine accountline has been removed");
3100
3113
3101
        $issue = AddIssue( $patron->unblessed, $item->barcode, $two_days_ago );    # date due was 2d ago
3114
        $issue = AddIssue( $patron, $item->barcode, $two_days_ago );    # date due was 2d ago
3102
3115
3103
        # Fake fines cronjob on this checkout
3116
        # Fake fines cronjob on this checkout
3104
        ($fine) =
3117
        ($fine) =
Lines 3164-3170 subtest 'AddReturn | is_overdue' => sub { Link Here
3164
3177
3165
        t::lib::Mocks::mock_preference('CalculateFinesOnBackdate', 1);
3178
        t::lib::Mocks::mock_preference('CalculateFinesOnBackdate', 1);
3166
3179
3167
        my $issue = AddIssue( $patron->unblessed, $item->barcode, $one_day_ago );    # date due was 1d ago
3180
        my $issue = AddIssue( $patron, $item->barcode, $one_day_ago );    # date due was 1d ago
3168
3181
3169
        # Fake fines cronjob on this checkout
3182
        # Fake fines cronjob on this checkout
3170
        my ($fine) =
3183
        my ($fine) =
Lines 3197-3203 subtest 'AddReturn | is_overdue' => sub { Link Here
3197
        t::lib::Mocks::mock_preference( 'CalculateFinesOnBackdate', 1 );
3210
        t::lib::Mocks::mock_preference( 'CalculateFinesOnBackdate', 1 );
3198
3211
3199
        my $due_date = dt_from_string;
3212
        my $due_date = dt_from_string;
3200
        my $issue = AddIssue( $patron->unblessed, $item->barcode, $due_date );
3213
        my $issue = AddIssue( $patron, $item->barcode, $due_date );
3201
3214
3202
        # Add fine
3215
        # Add fine
3203
        UpdateFine(
3216
        UpdateFine(
Lines 3222-3228 subtest 'AddReturn | is_overdue' => sub { Link Here
3222
        ok( !$accountline, 'accountline removed as expected' );
3235
        ok( !$accountline, 'accountline removed as expected' );
3223
3236
3224
        # Re-issue
3237
        # Re-issue
3225
        $issue = AddIssue( $patron->unblessed, $item->barcode, $due_date );
3238
        $issue = AddIssue( $patron, $item->barcode, $due_date );
3226
3239
3227
        # Add fine
3240
        # Add fine
3228
        UpdateFine(
3241
        UpdateFine(
Lines 3378-3384 subtest 'AddReturn | is_overdue' => sub { Link Here
3378
            );
3391
            );
3379
3392
3380
            # Issue the item
3393
            # Issue the item
3381
            my $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
3394
            my $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
3382
3395
3383
            # Mark item as lost
3396
            # Mark item as lost
3384
            $item->itemlost(3)->store;
3397
            $item->itemlost(3)->store;
Lines 3428-3434 subtest 'AddReturn | is_overdue' => sub { Link Here
3428
            );
3441
            );
3429
3442
3430
            # Issue the item
3443
            # Issue the item
3431
            $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
3444
            $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
3432
3445
3433
            # Mark item as lost
3446
            # Mark item as lost
3434
            $item->itemlost(3)->store;
3447
            $item->itemlost(3)->store;
Lines 3488-3494 subtest 'AddReturn | is_overdue' => sub { Link Here
3488
            );
3501
            );
3489
3502
3490
            # Issue the item
3503
            # Issue the item
3491
            $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
3504
            $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
3492
3505
3493
            # Mark item as lost
3506
            # Mark item as lost
3494
            $item->itemlost(3)->store;
3507
            $item->itemlost(3)->store;
Lines 3553-3559 subtest 'AddReturn | is_overdue' => sub { Link Here
3553
            );
3566
            );
3554
3567
3555
            # Issue the item
3568
            # Issue the item
3556
            my $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode, $ten_days_ago );
3569
            my $issue = C4::Circulation::AddIssue( $patron, $item->barcode, $ten_days_ago );
3557
3570
3558
            # Fake fines cronjob on this checkout
3571
            # Fake fines cronjob on this checkout
3559
            my ($fine) =
3572
            my ($fine) =
Lines 3636-3642 subtest 'AddReturn | is_overdue' => sub { Link Here
3636
            );
3649
            );
3637
3650
3638
            # Issue the item
3651
            # Issue the item
3639
            my $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode, $ten_days_ago );
3652
            my $issue = C4::Circulation::AddIssue( $patron, $item->barcode, $ten_days_ago );
3640
3653
3641
            # Fake fines cronjob on this checkout
3654
            # Fake fines cronjob on this checkout
3642
            my ($fine) =
3655
            my ($fine) =
Lines 3718-3724 subtest 'AddReturn | is_overdue' => sub { Link Here
3718
            );
3731
            );
3719
3732
3720
            # Issue the item
3733
            # Issue the item
3721
            my $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode , $ten_days_ago);
3734
            my $issue = C4::Circulation::AddIssue( $patron, $item->barcode , $ten_days_ago);
3722
3735
3723
            # Fake fines cronjob on this checkout
3736
            # Fake fines cronjob on this checkout
3724
            my ($fine) =
3737
            my ($fine) =
Lines 3815-3821 subtest 'AddReturn | is_overdue' => sub { Link Here
3815
            );
3828
            );
3816
3829
3817
            # Issue the item
3830
            # Issue the item
3818
            my $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode, $ten_days_ago );
3831
            my $issue = C4::Circulation::AddIssue( $patron, $item->barcode, $ten_days_ago );
3819
3832
3820
            # Fake fines cronjob on this checkout
3833
            # Fake fines cronjob on this checkout
3821
            my ($fine) =
3834
            my ($fine) =
Lines 4168-4174 subtest 'CanBookBeIssued | is_overdue' => sub { Link Here
4168
        }
4181
        }
4169
    );
4182
    );
4170
4183
4171
    my $issue = AddIssue( $patron->unblessed, $item->barcode, $five_days_go ); # date due was 10d ago
4184
    my $issue = AddIssue( $patron, $item->barcode, $five_days_go ); # date due was 10d ago
4172
    my $actualissue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
4185
    my $actualissue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
4173
    is( output_pref({ str => $actualissue->date_due, dateonly => 1}), output_pref({ str => $five_days_go, dateonly => 1}), "First issue works");
4186
    is( output_pref({ str => $actualissue->date_due, dateonly => 1}), output_pref({ str => $five_days_go, dateonly => 1}), "First issue works");
4174
    my ($issuingimpossible, $needsconfirmation) = CanBookBeIssued($patron, $item->barcode, $ten_days_go, undef, undef, undef);
4187
    my ($issuingimpossible, $needsconfirmation) = CanBookBeIssued($patron, $item->barcode, $ten_days_go, undef, undef, undef);
Lines 4460-4466 subtest 'AddReturn | recalls' => sub { Link Here
4460
    });
4473
    });
4461
4474
4462
    # this item can fill a recall with pickup at this branch
4475
    # this item can fill a recall with pickup at this branch
4463
    AddIssue( $patron1->unblessed, $item1->barcode );
4476
    AddIssue( $patron1, $item1->barcode );
4464
    my $recall1 = Koha::Recall->new(
4477
    my $recall1 = Koha::Recall->new(
4465
        {   patron_id         => $patron2->borrowernumber,
4478
        {   patron_id         => $patron2->borrowernumber,
4466
            biblio_id         => $item1->biblionumber,
4479
            biblio_id         => $item1->biblionumber,
Lines 4474-4480 subtest 'AddReturn | recalls' => sub { Link Here
4474
    $recall1->set_cancelled;
4487
    $recall1->set_cancelled;
4475
4488
4476
    # this item can fill a recall but needs transfer
4489
    # this item can fill a recall but needs transfer
4477
    AddIssue( $patron1->unblessed, $item1->barcode );
4490
    AddIssue( $patron1, $item1->barcode );
4478
    $recall1 = Koha::Recall->new(
4491
    $recall1 = Koha::Recall->new(
4479
        {   patron_id         => $patron2->borrowernumber,
4492
        {   patron_id         => $patron2->borrowernumber,
4480
            biblio_id         => $item1->biblionumber,
4493
            biblio_id         => $item1->biblionumber,
Lines 4488-4494 subtest 'AddReturn | recalls' => sub { Link Here
4488
    $recall1->set_cancelled;
4501
    $recall1->set_cancelled;
4489
4502
4490
    # this item is already in transit, do not ask to transfer
4503
    # this item is already in transit, do not ask to transfer
4491
    AddIssue( $patron1->unblessed, $item1->barcode );
4504
    AddIssue( $patron1, $item1->barcode );
4492
    $recall1 = Koha::Recall->new(
4505
    $recall1 = Koha::Recall->new(
4493
        {   patron_id         => $patron2->borrowernumber,
4506
        {   patron_id         => $patron2->borrowernumber,
4494
            biblio_id         => $item1->biblionumber,
4507
            biblio_id         => $item1->biblionumber,
Lines 4566-4572 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
4566
    $context->mock( userenv => { branch => $library->id } );
4579
    $context->mock( userenv => { branch => $library->id } );
4567
4580
4568
    # Check the item out
4581
    # Check the item out
4569
    AddIssue( $patron->unblessed, $item->barcode );
4582
    AddIssue( $patron, $item->barcode );
4570
4583
4571
    throws_ok {
4584
    throws_ok {
4572
        AddRenewal(
4585
        AddRenewal(
Lines 4643-4649 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
4643
    is( $new_stats_size, $old_stats_size + 1, 'renew statistic successfully added with passed branch' );
4656
    is( $new_stats_size, $old_stats_size + 1, 'renew statistic successfully added with passed branch' );
4644
4657
4645
    AddReturn( $item->id, $library->id, undef, $date );
4658
    AddReturn( $item->id, $library->id, undef, $date );
4646
    AddIssue( $patron->unblessed, $item->barcode, $now );
4659
    AddIssue( $patron, $item->barcode, $now );
4647
    AddRenewal(
4660
    AddRenewal(
4648
        {
4661
        {
4649
            borrowernumber => $patron->id,
4662
            borrowernumber => $patron->id,
Lines 4674-4680 subtest 'AddRenewal() adds to renewals' => sub { Link Here
4674
    set_userenv( $library->unblessed );
4687
    set_userenv( $library->unblessed );
4675
4688
4676
    # Check the item out
4689
    # Check the item out
4677
    my $issue = AddIssue( $patron->unblessed, $item->barcode );
4690
    my $issue = AddIssue( $patron, $item->barcode );
4678
    is(ref($issue), 'Koha::Checkout', 'Issue added');
4691
    is(ref($issue), 'Koha::Checkout', 'Issue added');
4679
4692
4680
    # Renew item
4693
    # Renew item
Lines 4766-4772 subtest 'Incremented fee tests' => sub { Link Here
4766
4779
4767
    # Daily Tests
4780
    # Daily Tests
4768
    my $issue =
4781
    my $issue =
4769
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4782
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4770
    my $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4783
    my $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4771
    is(
4784
    is(
4772
        $accountline->amount + 0,
4785
        $accountline->amount + 0,
Lines 4795-4801 subtest 'Incremented fee tests' => sub { Link Here
4795
    t::lib::Mocks::mock_preference( 'finesCalendar', 'noFinesWhenClosed' );
4808
    t::lib::Mocks::mock_preference( 'finesCalendar', 'noFinesWhenClosed' );
4796
    $itemtype->rentalcharge_daily_calendar(1)->store();
4809
    $itemtype->rentalcharge_daily_calendar(1)->store();
4797
    $issue =
4810
    $issue =
4798
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4811
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4799
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4812
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4800
    is(
4813
    is(
4801
        $accountline->amount + 0,
4814
        $accountline->amount + 0,
Lines 4834-4840 subtest 'Incremented fee tests' => sub { Link Here
4834
        description => 'Test holiday'
4847
        description => 'Test holiday'
4835
    );
4848
    );
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 4863-4869 subtest 'Incremented fee tests' => sub { Link Here
4863
    $itemtype->rentalcharge(2)->store;
4876
    $itemtype->rentalcharge(2)->store;
4864
    is( $itemtype->rentalcharge + 0, 2, 'Rental charge updated and retreived correctly' );
4877
    is( $itemtype->rentalcharge + 0, 2, 'Rental charge updated and retreived correctly' );
4865
    $issue =
4878
    $issue =
4866
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4879
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4867
    my $accountlines =
4880
    my $accountlines =
4868
      Koha::Account::Lines->search( { itemnumber => $item->id } );
4881
      Koha::Account::Lines->search( { itemnumber => $item->id } );
4869
    is( $accountlines->count, '2', "Fixed charge and accrued charge recorded distinctly" );
4882
    is( $accountlines->count, '2', "Fixed charge and accrued charge recorded distinctly" );
Lines 4903-4909 subtest 'Incremented fee tests' => sub { Link Here
4903
4916
4904
    $itemtype->rentalcharge_hourly_calendar(0)->store();
4917
    $itemtype->rentalcharge_hourly_calendar(0)->store();
4905
    $issue =
4918
    $issue =
4906
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4919
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4907
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4920
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4908
    is(
4921
    is(
4909
        $accountline->amount + 0,
4922
        $accountline->amount + 0,
Lines 4931-4937 subtest 'Incremented fee tests' => sub { Link Here
4931
4944
4932
    $itemtype->rentalcharge_hourly_calendar(1)->store();
4945
    $itemtype->rentalcharge_hourly_calendar(1)->store();
4933
    $issue =
4946
    $issue =
4934
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4947
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4935
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4948
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4936
    is(
4949
    is(
4937
        $accountline->amount + 0,
4950
        $accountline->amount + 0,
Lines 4959-4965 subtest 'Incremented fee tests' => sub { Link Here
4959
4972
4960
    $calendar->delete_holiday( weekday => $closed_day );
4973
    $calendar->delete_holiday( weekday => $closed_day );
4961
    $issue =
4974
    $issue =
4962
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4975
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4963
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4976
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4964
    is(
4977
    is(
4965
        $accountline->amount + 0,
4978
        $accountline->amount + 0,
Lines 5081-5087 subtest 'Do not return on renewal (LOST charge)' => sub { Link Here
5081
    );
5094
    );
5082
5095
5083
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
5096
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
5084
    AddIssue( $patron->unblessed, $item->barcode );
5097
    AddIssue( $patron, $item->barcode );
5085
5098
5086
    my $accountline = Koha::Account::Line->new(
5099
    my $accountline = Koha::Account::Line->new(
5087
        {
5100
        {
Lines 5096-5102 subtest 'Do not return on renewal (LOST charge)' => sub { Link Here
5096
    )->store();
5109
    )->store();
5097
5110
5098
    # AddRenewal doesn't call _FixAccountForLostAndFound
5111
    # AddRenewal doesn't call _FixAccountForLostAndFound
5099
    AddIssue( $patron->unblessed, $item->barcode );
5112
    AddIssue( $patron, $item->barcode );
5100
5113
5101
    is( $patron->checkouts->count, 1,
5114
    is( $patron->checkouts->count, 1,
5102
        'Renewal should not return the item even if a LOST payment has been made earlier'
5115
        'Renewal should not return the item even if a LOST payment has been made earlier'
Lines 5202-5208 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddReturn' => sub { Link Here
5202
                replacementprice => '42',
5215
                replacementprice => '42',
5203
            }
5216
            }
5204
        );
5217
        );
5205
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5218
        my $issue = AddIssue( $patron, $item->barcode );
5206
        LostItem( $item->itemnumber, 'cli', 0 );
5219
        LostItem( $item->itemnumber, 'cli', 0 );
5207
        $item->_result->itemlost(1);
5220
        $item->_result->itemlost(1);
5208
        $item->_result->itemlost_on( $lost_on );
5221
        $item->_result->itemlost_on( $lost_on );
Lines 5237-5243 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddReturn' => sub { Link Here
5237
                replacementprice => '42',
5250
                replacementprice => '42',
5238
            }
5251
            }
5239
        );
5252
        );
5240
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5253
        my $issue = AddIssue( $patron, $item->barcode );
5241
        LostItem( $item->itemnumber, 'cli', 0 );
5254
        LostItem( $item->itemnumber, 'cli', 0 );
5242
        $item->_result->itemlost(1);
5255
        $item->_result->itemlost(1);
5243
        $item->_result->itemlost_on( $lost_on );
5256
        $item->_result->itemlost_on( $lost_on );
Lines 5272-5278 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddReturn' => sub { Link Here
5272
                replacementprice => '42',
5285
                replacementprice => '42',
5273
            }
5286
            }
5274
        );
5287
        );
5275
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5288
        my $issue = AddIssue( $patron, $item->barcode );
5276
        LostItem( $item->itemnumber, 'cli', 0 );
5289
        LostItem( $item->itemnumber, 'cli', 0 );
5277
        $item->_result->itemlost(1);
5290
        $item->_result->itemlost(1);
5278
        $item->_result->itemlost_on( $lost_on );
5291
        $item->_result->itemlost_on( $lost_on );
Lines 5307-5313 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddReturn' => sub { Link Here
5307
                replacementprice => '42',
5320
                replacementprice => '42',
5308
            }
5321
            }
5309
        );
5322
        );
5310
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5323
        my $issue = AddIssue( $patron, $item->barcode );
5311
        LostItem( $item->itemnumber, 'cli', 0 );
5324
        LostItem( $item->itemnumber, 'cli', 0 );
5312
        $item->_result->itemlost(1);
5325
        $item->_result->itemlost(1);
5313
        $item->_result->itemlost_on( $lost_on );
5326
        $item->_result->itemlost_on( $lost_on );
Lines 5395-5401 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5395
                replacementprice => '42',
5408
                replacementprice => '42',
5396
            }
5409
            }
5397
        );
5410
        );
5398
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5411
        my $issue = AddIssue( $patron, $item->barcode );
5399
        LostItem( $item->itemnumber, 'cli', 0 );
5412
        LostItem( $item->itemnumber, 'cli', 0 );
5400
        $item->_result->itemlost(1);
5413
        $item->_result->itemlost(1);
5401
        $item->_result->itemlost_on( $lost_on );
5414
        $item->_result->itemlost_on( $lost_on );
Lines 5409-5415 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5409
        )->next;
5422
        )->next;
5410
        ok( $a, "Found accountline for lost fee" );
5423
        ok( $a, "Found accountline for lost fee" );
5411
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5424
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5412
        $issue = AddIssue( $patron2->unblessed, $item->barcode );
5425
        $issue = AddIssue( $patron2, $item->barcode );
5413
        $a = $a->get_from_storage;
5426
        $a = $a->get_from_storage;
5414
        is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" );
5427
        is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" );
5415
        $a->delete;
5428
        $a->delete;
Lines 5431-5437 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5431
                replacementprice => '42',
5444
                replacementprice => '42',
5432
            }
5445
            }
5433
        );
5446
        );
5434
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5447
        my $issue = AddIssue( $patron, $item->barcode );
5435
        LostItem( $item->itemnumber, 'cli', 0 );
5448
        LostItem( $item->itemnumber, 'cli', 0 );
5436
        $item->_result->itemlost(1);
5449
        $item->_result->itemlost(1);
5437
        $item->_result->itemlost_on( $lost_on );
5450
        $item->_result->itemlost_on( $lost_on );
Lines 5445-5451 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5445
        )->next;
5458
        )->next;
5446
        ok( $a, "Found accountline for lost fee" );
5459
        ok( $a, "Found accountline for lost fee" );
5447
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5460
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5448
        $issue = AddIssue( $patron2->unblessed, $item->barcode );
5461
        $issue = AddIssue( $patron2, $item->barcode );
5449
        $a = $a->get_from_storage;
5462
        $a = $a->get_from_storage;
5450
        is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" );
5463
        is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" );
5451
        $a->delete;
5464
        $a->delete;
Lines 5466-5472 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5466
                replacementprice => '42',
5479
                replacementprice => '42',
5467
            }
5480
            }
5468
        );
5481
        );
5469
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5482
        my $issue = AddIssue( $patron, $item->barcode );
5470
        LostItem( $item->itemnumber, 'cli', 0 );
5483
        LostItem( $item->itemnumber, 'cli', 0 );
5471
        $item->_result->itemlost(1);
5484
        $item->_result->itemlost(1);
5472
        $item->_result->itemlost_on( $lost_on );
5485
        $item->_result->itemlost_on( $lost_on );
Lines 5480-5486 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5480
        )->next;
5493
        )->next;
5481
        ok( $a, "Found accountline for lost fee" );
5494
        ok( $a, "Found accountline for lost fee" );
5482
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5495
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5483
        $issue = AddIssue( $patron2->unblessed, $item->barcode );
5496
        $issue = AddIssue( $patron2, $item->barcode );
5484
        $a = $a->get_from_storage;
5497
        $a = $a->get_from_storage;
5485
        is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" );
5498
        is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" );
5486
        $a->delete;
5499
        $a->delete;
Lines 5501-5507 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5501
                replacementprice => '42',
5514
                replacementprice => '42',
5502
            }
5515
            }
5503
        );
5516
        );
5504
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5517
        my $issue = AddIssue( $patron, $item->barcode );
5505
        LostItem( $item->itemnumber, 'cli', 0 );
5518
        LostItem( $item->itemnumber, 'cli', 0 );
5506
        $item->_result->itemlost(1);
5519
        $item->_result->itemlost(1);
5507
        $item->_result->itemlost_on( $lost_on );
5520
        $item->_result->itemlost_on( $lost_on );
Lines 5516-5522 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5516
        $a = $a->next;
5529
        $a = $a->next;
5517
        ok( $a, "Found accountline for lost fee" );
5530
        ok( $a, "Found accountline for lost fee" );
5518
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5531
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5519
        $issue = AddIssue( $patron2->unblessed, $item->barcode );
5532
        $issue = AddIssue( $patron2, $item->barcode );
5520
        $a = $a->get_from_storage;
5533
        $a = $a->get_from_storage;
5521
        is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" );
5534
        is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" );
5522
        $a->delete;
5535
        $a->delete;
Lines 5602-5608 subtest 'Checkout should correctly terminate a transfer' => sub { Link Here
5602
    is( $transfer->reason,     'Reserve' );
5615
    is( $transfer->reason,     'Reserve' );
5603
5616
5604
    t::lib::Mocks::mock_userenv( { branchcode => $library_2->branchcode } );
5617
    t::lib::Mocks::mock_userenv( { branchcode => $library_2->branchcode } );
5605
    AddIssue( $patron_1->unblessed, $item->barcode );
5618
    AddIssue( $patron_1, $item->barcode );
5606
    $transfer = $transfer->get_from_storage;
5619
    $transfer = $transfer->get_from_storage;
5607
    isnt( $transfer->datearrived, undef );
5620
    isnt( $transfer->datearrived, undef );
5608
    $hold = $hold->get_from_storage;
5621
    $hold = $hold->get_from_storage;
Lines 5645-5658 subtest 'AddIssue records staff who checked out item if appropriate' => sub { Link Here
5645
    my $dt_from = dt_from_string();
5658
    my $dt_from = dt_from_string();
5646
    my $dt_to   = dt_from_string()->add( days => 7 );
5659
    my $dt_to   = dt_from_string()->add( days => 7 );
5647
5660
5648
    my $issue_1 = AddIssue( $patron->unblessed, $item_1->barcode, $dt_to, undef, $dt_from );
5661
    my $issue_1 = AddIssue( $patron, $item_1->barcode, $dt_to, undef, $dt_from );
5649
5662
5650
    is( $issue_1->issuer, undef, "Staff who checked out the item not recorded when RecordStaffUserOnCheckout turned off" );
5663
    is( $issue_1->issuer, undef, "Staff who checked out the item not recorded when RecordStaffUserOnCheckout turned off" );
5651
5664
5652
    t::lib::Mocks::mock_preference('RecordStaffUserOnCheckout', 1);
5665
    t::lib::Mocks::mock_preference('RecordStaffUserOnCheckout', 1);
5653
5666
5654
    my $issue_2 =
5667
    my $issue_2 =
5655
      AddIssue( $patron->unblessed, $item_2->barcode, $dt_to, undef, $dt_from );
5668
      AddIssue( $patron, $item_2->barcode, $dt_to, undef, $dt_from );
5656
5669
5657
    is( $issue_2->issuer->borrowernumber, $issuer->borrowernumber, "Staff who checked out the item recorded when RecordStaffUserOnCheckout turned on" );
5670
    is( $issue_2->issuer->borrowernumber, $issuer->borrowernumber, "Staff who checked out the item recorded when RecordStaffUserOnCheckout turned on" );
5658
};
5671
};
Lines 5680-5688 subtest "Item's onloan value should be set if checked out item is checked out to Link Here
5680
        }
5693
        }
5681
    );
5694
    );
5682
5695
5683
    AddIssue( $patron_1->unblessed, $item->barcode );
5696
    AddIssue( $patron_1, $item->barcode );
5684
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after initial checkout" );
5697
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after initial checkout" );
5685
    AddIssue( $patron_2->unblessed, $item->barcode );
5698
    AddIssue( $patron_2, $item->barcode );
5686
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after second checkout" );
5699
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after second checkout" );
5687
};
5700
};
5688
5701
Lines 5759-5765 subtest "SendCirculationAlert" => sub { Link Here
5759
    })->store;
5772
    })->store;
5760
5773
5761
    # Checkout an item, mark it returned, generate a notice
5774
    # Checkout an item, mark it returned, generate a notice
5762
    my $issue_1 = AddIssue( $patron->unblessed, $item->barcode);
5775
    my $issue_1 = AddIssue( $patron, $item->barcode);
5763
    MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0, { skip_record_index => 1} );
5776
    MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0, { skip_record_index => 1} );
5764
    C4::Circulation::SendCirculationAlert({
5777
    C4::Circulation::SendCirculationAlert({
5765
        type => 'CHECKIN',
5778
        type => 'CHECKIN',
Lines 5773-5779 subtest "SendCirculationAlert" => sub { Link Here
5773
    is($notice->to_address, $patron->smsalertnumber, "Letter has the correct to_address set to smsalertnumber for SMS type notices");
5786
    is($notice->to_address, $patron->smsalertnumber, "Letter has the correct to_address set to smsalertnumber for SMS type notices");
5774
5787
5775
    # Checkout an item, mark it returned, generate a notice
5788
    # Checkout an item, mark it returned, generate a notice
5776
    my $issue_2 = AddIssue( $patron->unblessed, $item->barcode);
5789
    my $issue_2 = AddIssue( $patron, $item->barcode);
5777
    MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0, { skip_record_index => 1} );
5790
    MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0, { skip_record_index => 1} );
5778
    C4::Circulation::SendCirculationAlert({
5791
    C4::Circulation::SendCirculationAlert({
5779
        type => 'CHECKIN',
5792
        type => 'CHECKIN',
Lines 5807-5813 subtest "GetSoonestRenewDate tests" => sub { Link Here
5807
        }
5820
        }
5808
    );
5821
    );
5809
    my $item = $builder->build_sample_item();
5822
    my $item = $builder->build_sample_item();
5810
    my $issue = AddIssue( $patron->unblessed, $item->barcode);
5823
    my $issue = AddIssue( $patron, $item->barcode);
5811
    my $datedue = dt_from_string( $issue->date_due() );
5824
    my $datedue = dt_from_string( $issue->date_due() );
5812
5825
5813
    # Bug 14395
5826
    # Bug 14395
Lines 5895-5900 subtest "CanBookBeIssued + needsconfirmation message" => sub { Link Here
5895
        priority => 1,
5908
        priority => 1,
5896
        found => undef,
5909
        found => undef,
5897
        suspend => 0,
5910
        suspend => 0,
5911
        item_group_id => undef
5898
    }});
5912
    }});
5899
5913
5900
    my ( $error, $needsconfirmation, $alerts, $messages );
5914
    my ( $error, $needsconfirmation, $alerts, $messages );
(-)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 / +23 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
            categorycode => $categorycode,
74
            branchcode => $branchcode
75
        }
76
    }
77
);
78
my $patron2 = $builder->build_object(
79
    {
80
        class => 'Koha::Patrons',
81
        value => {
82
            categorycode => $categorycode,
83
            branchcode => $branchcode
84
        }
85
    }
86
);
87
88
my $borrowernumber1 = $patron1->borrowernumber;
89
my $borrowernumber2 = $patron2->borrowernumber;
74
90
75
my $module = Test::MockModule->new('C4::Context');
91
my $module = Test::MockModule->new('C4::Context');
76
$module->mock('userenv', sub { { branch => $branchcode } });
92
$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);
107
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2);
92
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
108
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
93
109
94
AddIssue($borrower1, '0101');
110
AddIssue($patron1, '0101');
95
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron();
111
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron();
96
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
112
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
97
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron(undef, $biblionumber1);
113
$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);
123
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2);
108
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
124
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
109
125
110
AddIssue($borrower2, '0202');
126
AddIssue($patron2, '0202');
111
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron();
127
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron();
112
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
128
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
113
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron(undef, $biblionumber1);
129
$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 / +20 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-136 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/,
135
                 qr/^item-level_itypes set but no itemtype set for item/,
134
                 qr/^item-level_itypes set but no itemtype set for item/,
136
                 qr/^item-level_itypes set but no itemtype set for item/],
135
                 qr/^item-level_itypes set but no itemtype set for item/],
Lines 166-173 subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub { Link Here
166
    # Create a branch
165
    # Create a branch
167
    $branch = $builder->build({ source => 'Branch' })->{ branchcode };
166
    $branch = $builder->build({ source => 'Branch' })->{ branchcode };
168
    # Create a borrower
167
    # Create a borrower
169
    my $borrowernumber = $builder->build({
168
    my $patron = $builder->build_object({
170
        source => 'Borrower',
169
        class => 'Koha::Patrons',
171
        value => { branchcode => $branch }
170
        value => { branchcode => $branch }
172
    })->{ borrowernumber };
171
    })->{ borrowernumber };
173
    # Look for the defined MARC field for biblio-level itemtype
172
    # Look for the defined MARC field for biblio-level itemtype
Lines 199-207 subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub { Link Here
199
        }
198
        }
200
    );
199
    );
201
200
202
    my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
201
    AddIssue( $patron, $item_with_itemtype->barcode );
203
204
    AddIssue( $borrower, $item_with_itemtype->barcode );
205
    AddReturn( $item_with_itemtype->barcode, $branch );
202
    AddReturn( $item_with_itemtype->barcode, $branch );
206
    # Test item-level itemtype was recorded on the 'statistics' table
203
    # Test item-level itemtype was recorded on the 'statistics' table
207
    my $stat = $schema->resultset('Statistic')->search({
204
    my $stat = $schema->resultset('Statistic')->search({
Lines 213-219 subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub { Link Here
213
    is( $stat->itemtype, $blevel_itemtype,
210
    is( $stat->itemtype, $blevel_itemtype,
214
        "biblio-level itype recorded on statistics for return");
211
        "biblio-level itype recorded on statistics for return");
215
212
216
    AddIssue( $borrower, $item_without_itemtype->barcode );
213
    AddIssue( $patron, $item_without_itemtype->barcode );
217
    AddReturn( $item_without_itemtype->barcode, $branch );
214
    AddReturn( $item_without_itemtype->barcode, $branch );
218
    # Test biblio-level itemtype was recorded on the 'statistics' table
215
    # Test biblio-level itemtype was recorded on the 'statistics' table
219
    $stat = $schema->resultset('Statistic')->search({
216
    $stat = $schema->resultset('Statistic')->search({
Lines 251-260 subtest 'Handle ids duplication' => sub { Link Here
251
            itype => $itemtype->{itemtype},
248
            itype => $itemtype->{itemtype},
252
        }
249
        }
253
    );
250
    );
254
    my $patron = $builder->build({source => 'Borrower'});
251
    my $patron = $builder->build_object(
255
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
252
        { class => 'Koha::Patrons'}
253
    );
256
254
257
    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 ) );
258
    my $issue_id = $original_checkout->issue_id;
256
    my $issue_id = $original_checkout->issue_id;
259
    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 });
260
    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 281-287 subtest 'Handle ids duplication' => sub { Link Here
281
    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' );
282
    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' );
283
281
284
    $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 });
285
    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' );
286
284
287
    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 290-297 subtest 'Handle ids duplication' => sub { Link Here
290
subtest 'BlockReturnOfLostItems' => sub {
288
subtest 'BlockReturnOfLostItems' => sub {
291
    plan tests => 4;
289
    plan tests => 4;
292
    my $item = $builder->build_sample_item;
290
    my $item = $builder->build_sample_item;
293
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
291
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
294
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
292
    my $checkout = AddIssue( $patron, $item->barcode );
295
293
296
    # Mark the item as lost
294
    # Mark the item as lost
297
    $item->itemlost(1)->store;
295
    $item->itemlost(1)->store;
Lines 315-321 subtest 'Checkin of an item claimed as returned should generate a message' => su Link Here
315
    t::lib::Mocks::mock_preference('ClaimReturnedLostValue', 1);
313
    t::lib::Mocks::mock_preference('ClaimReturnedLostValue', 1);
316
    my $item = $builder->build_sample_item;
314
    my $item = $builder->build_sample_item;
317
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
315
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
318
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
316
    my $checkout = AddIssue( $patron, $item->barcode );
319
317
320
    $checkout->claim_returned({ created_by => $patron->id });
318
    $checkout->claim_returned({ created_by => $patron->id });
321
319
Lines 332-343 subtest 'BranchTransferLimitsType' => sub { Link Here
332
330
333
    my $item = $builder->build_sample_item;
331
    my $item = $builder->build_sample_item;
334
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
332
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
335
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
333
    my $checkout = AddIssue( $patron, $item->barcode );
336
    my ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
334
    my ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
337
    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');
338
336
339
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
337
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
340
    $checkout = AddIssue( $patron->unblessed, $item->barcode );
338
    $checkout = AddIssue( $patron, $item->barcode );
341
    ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
339
    ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
342
    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');
343
};
341
};
Lines 351-357 subtest 'Backdated returns should reduce fine if needed' => sub { Link Here
351
    my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
349
    my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
352
    my $item = $builder->build_sample_item;
350
    my $item = $builder->build_sample_item;
353
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
351
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
354
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
352
    my $checkout = AddIssue( $patron, $item->barcode );
355
    my $fine = Koha::Account::Line->new({
353
    my $fine = Koha::Account::Line->new({
356
        issue_id => $checkout->id,
354
        issue_id => $checkout->id,
357
        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 60-67 my $category = $builder->build({ Link Here
60
    source => 'Category',
60
    source => 'Category',
61
});
61
});
62
62
63
my $patron = $builder->build({
63
my $patron = $builder->build_object({
64
    source => 'Borrower',
64
    class => 'Koha::Patrons',
65
    value => {
65
    value => {
66
        categorycode => $category->{categorycode},
66
        categorycode => $category->{categorycode},
67
        branchcode => $branch->{branchcode},
67
        branchcode => $branch->{branchcode},
Lines 75-82 my $item = $builder->build_sample_item({ Link Here
75
    holdingbranch => $branch->{branchcode},
75
    holdingbranch => $branch->{branchcode},
76
});
76
});
77
77
78
my $patron_object = Koha::Patrons->find( $patron->{borrowernumber} );
78
t::lib::Mocks::mock_userenv( { patron => $patron });
79
t::lib::Mocks::mock_userenv( { patron => $patron_object });
80
79
81
# TooMany return ($current_loan_count, $max_loans_allowed) or undef
80
# TooMany return ($current_loan_count, $max_loans_allowed) or undef
82
# CO = Checkout
81
# CO = Checkout
Lines 486-493 subtest 'General vs specific rules limit quantity correctly' => sub { Link Here
486
            notforloan => 0,
485
            notforloan => 0,
487
        }
486
        }
488
    });
487
    });
489
    my $patron = $builder->build({
488
    my $patron = $builder->build_object({
490
        source => 'Borrower',
489
        class => 'Koha::Patrons',
491
        value => {
490
        value => {
492
            categorycode => $category->{categorycode},
491
            categorycode => $category->{categorycode},
493
            branchcode => $branch->{branchcode},
492
            branchcode => $branch->{branchcode},
Lines 777-785 subtest 'itemtype group tests' => sub { Link Here
777
776
778
    my $branch   = $builder->build( { source => 'Branch', } );
777
    my $branch   = $builder->build( { source => 'Branch', } );
779
    my $category = $builder->build( { source => 'Category', } );
778
    my $category = $builder->build( { source => 'Category', } );
780
    my $patron   = $builder->build(
779
    my $patron   = $builder->build_object(
781
        {
780
        {
782
            source => 'Borrower',
781
            class => 'Koha::Patrons',
783
            value  => {
782
            value  => {
784
                categorycode => $category->{categorycode},
783
                categorycode => $category->{categorycode},
785
                branchcode   => $branch->{branchcode},
784
                branchcode   => $branch->{branchcode},
(-)a/t/db_dependent/Circulation/_CalculateAndUpdateFine.t (-6 / +6 lines)
Lines 48-55 my $category = $builder->build({ Link Here
48
    source => 'Category',
48
    source => 'Category',
49
});
49
});
50
50
51
my $patron = $builder->build({
51
my $patron = $builder->build_object({
52
    source => 'Borrower',
52
    class => 'Koha::Patrons',
53
    value => {
53
    value => {
54
        categorycode => $category->{categorycode},
54
        categorycode => $category->{categorycode},
55
        branchcode => $branch->{branchcode},
55
        branchcode => $branch->{branchcode},
Lines 110-135 subtest 'HomeOrHoldingBranch is used' => sub { Link Here
110
    my $return_date = dt_from_string()->add( days => 1 )->set( hour => 23, minute => 59, second => 0 );
110
    my $return_date = dt_from_string()->add( days => 1 )->set( hour => 23, minute => 59, second => 0 );
111
    C4::Circulation::_CalculateAndUpdateFine(
111
    C4::Circulation::_CalculateAndUpdateFine(
112
       {
112
       {
113
            borrower => $patron,
113
            borrower => $patron->unblessed,
114
            issue => $issue,
114
            issue => $issue,
115
            item => $item->unblessed,
115
            item => $item->unblessed,
116
            return_date => $return_date,
116
            return_date => $return_date,
117
        }
117
        }
118
    );
118
    );
119
119
120
    my $fines = Koha::Account::Lines->search({ borrowernumber => $patron->{borrowernumber} });
120
    my $fines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber });
121
    is($fines->total_outstanding, 0, "Fine is not accrued for holdingbranch");
121
    is($fines->total_outstanding, 0, "Fine is not accrued for holdingbranch");
122
122
123
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
123
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
124
    C4::Circulation::_CalculateAndUpdateFine(
124
    C4::Circulation::_CalculateAndUpdateFine(
125
        {
125
        {
126
            borrower => $patron,
126
            borrower => $patron->unblessed,
127
            issue => $issue,
127
            issue => $issue,
128
            item => $item->unblessed,
128
            item => $item->unblessed,
129
            return_date => $return_date,
129
            return_date => $return_date,
130
        }
130
        }
131
    );
131
    );
132
    $fines = Koha::Account::Lines->search({ borrowernumber => $patron->{borrowernumber} });
132
    $fines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber });
133
    is($fines->total_outstanding, 1, "Fine is accrued for homebranch");
133
    is($fines->total_outstanding, 1, "Fine is accrued for homebranch");
134
134
135
};
135
};
(-)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 271-277 subtest 'Show that AddRenewal respects OpacRenewalBranch and interface' => sub { Link Here
271
            my $item = $builder->build_sample_item(
269
            my $item = $builder->build_sample_item(
272
                { library => $item_library->branchcode, itype => $itemtype } );
270
                { library => $item_library->branchcode, itype => $itemtype } );
273
            my $opac_renew_issue =
271
            my $opac_renew_issue =
274
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
272
              C4::Circulation::AddIssue( $patron, $item->barcode );
275
273
276
            AddRenewal(
274
            AddRenewal(
277
                {
275
                {
Lines 296-302 subtest 'Show that AddRenewal respects OpacRenewalBranch and interface' => sub { Link Here
296
            my $item = $builder->build_sample_item(
294
            my $item = $builder->build_sample_item(
297
                { library => $item_library->branchcode, itype => $itemtype } );
295
                { library => $item_library->branchcode, itype => $itemtype } );
298
            my $opac_renew_issue =
296
            my $opac_renew_issue =
299
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
297
              C4::Circulation::AddIssue( $patron, $item->barcode );
300
298
301
            AddRenewal(
299
            AddRenewal(
302
                {
300
                {
Lines 320-326 subtest 'Show that AddRenewal respects OpacRenewalBranch and interface' => sub { Link Here
320
318
321
my @renewcount;
319
my @renewcount;
322
#Test GetRenewCount
320
#Test GetRenewCount
323
my $issue3 = C4::Circulation::AddIssue( $borrower_1, $barcode_1 );
321
my $issue3 = C4::Circulation::AddIssue( $patron_1, $barcode_1 );
324
#Without anything in DB
322
#Without anything in DB
325
@renewcount = C4::Circulation::GetRenewCount();
323
@renewcount = C4::Circulation::GetRenewCount();
326
is_deeply(
324
is_deeply(
Lines 401-407 my $return = $dbh->selectrow_hashref("SELECT DATE(returndate) AS return_date, CU Link Here
401
ok( $return->{return_date} eq $return->{today}, "Item returned with no return date specified has todays date" );
399
ok( $return->{return_date} eq $return->{today}, "Item returned with no return date specified has todays date" );
402
400
403
$dbh->do("DELETE FROM old_issues");
401
$dbh->do("DELETE FROM old_issues");
404
C4::Circulation::AddIssue( $borrower_1, $barcode_1, $daysago10, 0, $today );
402
C4::Circulation::AddIssue( $patron_1, $barcode_1, $daysago10, 0, $today );
405
AddReturn($barcode_1, undef, undef, dt_from_string('2014-04-01 23:42'));
403
AddReturn($barcode_1, undef, undef, dt_from_string('2014-04-01 23:42'));
406
$return = $dbh->selectrow_hashref("SELECT * FROM old_issues LIMIT 1" );
404
$return = $dbh->selectrow_hashref("SELECT * FROM old_issues LIMIT 1" );
407
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" );
405
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 487-493 $item2 = Koha::Items->find( $itemnumber2 ); Link Here
487
ok( $item2->location eq 'CART', q{UpdateItemLocationOnCheckin updates location value from 'GEN' with setting "_ALL_: CART" when transfer filled} );
485
ok( $item2->location eq 'CART', q{UpdateItemLocationOnCheckin updates location value from 'GEN' with setting "_ALL_: CART" when transfer filled} );
488
486
489
ok( $item2->permanent_location eq 'GEN', q{UpdateItemLocationOnCheckin does not update permanent_location value from 'GEN' with setting "_ALL_: CART"} );
487
ok( $item2->permanent_location eq 'GEN', q{UpdateItemLocationOnCheckin does not update permanent_location value from 'GEN' with setting "_ALL_: CART"} );
490
AddIssue( $borrower_1, 'barcode_4', $daysago10,0, $today, '' );
488
AddIssue( $patron_1, 'barcode_4', $daysago10,0, $today, '' );
491
$item2 = Koha::Items->find( $itemnumber2 );
489
$item2 = Koha::Items->find( $itemnumber2 );
492
ok( $item2->location eq 'GEN', q{Location updates from 'CART' to permanent location on issue} );
490
ok( $item2->location eq 'GEN', q{Location updates from 'CART' to permanent location on issue} );
493
491
Lines 536-542 my $reserve_id = AddReserve( Link Here
536
    }
534
    }
537
);
535
);
538
ok( $reserve_id, 'The reserve should have been inserted' );
536
ok( $reserve_id, 'The reserve should have been inserted' );
539
AddIssue( $borrower_2, $barcode_1, dt_from_string, 'cancel' );
537
AddIssue( $patron_2, $barcode_1, dt_from_string, 'cancel' );
540
my $hold = Koha::Holds->find( $reserve_id );
538
my $hold = Koha::Holds->find( $reserve_id );
541
is( $hold, undef, 'The reserve should have been correctly cancelled' );
539
is( $hold, undef, 'The reserve should have been correctly cancelled' );
542
540
Lines 559-565 my $unseen_library = $builder->build_object( { class => 'Koha::Libraries' } ); Link Here
559
my $unseen_patron  = $builder->build_object( { class => 'Koha::Patrons' } );
557
my $unseen_patron  = $builder->build_object( { class => 'Koha::Patrons' } );
560
my $unseen_item = $builder->build_sample_item(
558
my $unseen_item = $builder->build_sample_item(
561
    { library => $unseen_library->branchcode, itype => $itemtype } );
559
    { library => $unseen_library->branchcode, itype => $itemtype } );
562
my $unseen_issue = C4::Circulation::AddIssue( $unseen_patron->unblessed, $unseen_item->barcode );
560
my $unseen_issue = C4::Circulation::AddIssue( $unseen_patron, $unseen_item->barcode );
563
561
564
# Does an unseen renewal increment the issue's count
562
# Does an unseen renewal increment the issue's count
565
my ( $unseen_before ) = ( C4::Circulation::GetRenewCount( $unseen_patron->borrowernumber, $unseen_item->itemnumber ) )[3];
563
my ( $unseen_before ) = ( C4::Circulation::GetRenewCount( $unseen_patron->borrowernumber, $unseen_item->itemnumber ) )[3];
(-)a/t/db_dependent/Circulation/maxsuspensiondays.t (-10 / +8 lines)
Lines 42-55 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 $patron_object = Koha::Patrons->find( $borrowernumber );
52
my $borrower = $patron_object->unblessed;
53
51
54
my $record = MARC::Record->new();
52
my $record = MARC::Record->new();
55
$record->append_fields(
53
$record->append_fields(
Lines 75-83 $dbh->do('DELETE FROM repeatable_holidays'); Link Here
75
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));
76
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));
77
75
78
AddIssue( $borrower, $barcode, $daysago20 );
76
AddIssue( $patron, $barcode, $daysago20 );
79
AddReturn( $barcode, $branchcode );
77
AddReturn( $barcode, $branchcode );
80
my $debarments = $patron_object->restrictions;
78
my $debarments = $patron->restrictions;
81
my $THE_debarment = $debarments->next;
79
my $THE_debarment = $debarments->next;
82
is(
80
is(
83
    $THE_debarment->expiration,
81
    $THE_debarment->expiration,
Lines 99-107 Koha::CirculationRules->set_rules( Link Here
99
);
97
);
100
98
101
my $daysafter10 = dt_from_string->add_duration(DateTime::Duration->new(days => 10));
99
my $daysafter10 = dt_from_string->add_duration(DateTime::Duration->new(days => 10));
102
AddIssue( $borrower, $barcode, $daysago20 );
100
AddIssue( $patron, $barcode, $daysago20 );
103
AddReturn( $barcode, $branchcode );
101
AddReturn( $barcode, $branchcode );
104
$debarments = $patron_object->restrictions;
102
$debarments = $patron->restrictions;
105
$THE_debarment = $debarments->next;
103
$THE_debarment = $debarments->next;
106
is(
104
is(
107
    $THE_debarment->expiration,
105
    $THE_debarment->expiration,
Lines 130-136 subtest "suspension_chargeperiod" => sub { Link Here
130
128
131
    my $last_year = dt_from_string->clone->subtract( years => 1 );
129
    my $last_year = dt_from_string->clone->subtract( years => 1 );
132
    my $today = dt_from_string;
130
    my $today = dt_from_string;
133
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron->unblessed, $item->unblessed, $last_year, $today );
131
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron, $item, $last_year, $today );
134
    is( $new_debar_dt->truncate( to => 'day' ),
132
    is( $new_debar_dt->truncate( to => 'day' ),
135
        $today->clone->add( days => 365 / 15 * 7 )->truncate( to => 'day' ) );
133
        $today->clone->add( days => 365 / 15 * 7 )->truncate( to => 'day' ) );
136
134
Lines 156-162 subtest "maxsuspensiondays" => sub { Link Here
156
154
157
    my $last_year = dt_from_string->clone->subtract( years => 1 );
155
    my $last_year = dt_from_string->clone->subtract( years => 1 );
158
    my $today = dt_from_string;
156
    my $today = dt_from_string;
159
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron->unblessed, $item->unblessed, $last_year, $today );
157
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron, $item, $last_year, $today );
160
    is( $new_debar_dt->truncate( to => 'day' ),
158
    is( $new_debar_dt->truncate( to => 'day' ),
161
        $today->clone->add( days => 333 )->truncate( to => 'day' ) );
159
        $today->clone->add( days => 333 )->truncate( to => 'day' ) );
162
};
160
};
(-)a/t/db_dependent/Circulation/transferbook.t (-2 / +2 lines)
Lines 208-214 subtest 'transfer an issued item' => sub { Link Here
208
    );
208
    );
209
209
210
    my $dt_to = dt_from_string();
210
    my $dt_to = dt_from_string();
211
    my $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to );
211
    my $issue = AddIssue( $patron, $item->barcode, $dt_to );
212
212
213
    # 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.
214
    # * 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 222-228 subtest 'transfer an issued item' => sub { Link Here
222
    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');
223
223
224
    # Reset issue
224
    # Reset issue
225
    $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to );
225
    $issue = AddIssue( $patron, $item->barcode, $dt_to );
226
226
227
    # 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.
228
    # * 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 113-119 is( $is, 1, "Items availability: both of 2 items are available" ); Link Here
113
$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
113
$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
114
is( $is, 0, "Item cannot be held, 2 items available" );
114
is( $is, 0, "Item cannot be held, 2 items available" );
115
115
116
my $issue1 = AddIssue( $patron2->unblessed, $item1->barcode );
116
my $issue1 = AddIssue( $patron2, $item1->barcode );
117
117
118
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
118
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
119
is( $is, 1, "Items availability: one item is available" );
119
is( $is, 1, "Items availability: one item is available" );
Lines 121-127 is( $is, 1, "Items availability: one item is available" ); Link Here
121
$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
121
$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
122
is( $is, 0, "Item cannot be held, 1 item available" );
122
is( $is, 0, "Item cannot be held, 1 item available" );
123
123
124
AddIssue( $patron2->unblessed, $item2->barcode );
124
AddIssue( $patron2, $item2->barcode );
125
$cache->flush();
125
$cache->flush();
126
126
127
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
127
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
Lines 464-470 subtest 'Check holds availability with different item types' => sub { Link Here
464
    $is = IsAvailableForItemLevelRequest( $item5, $patron1 );
464
    $is = IsAvailableForItemLevelRequest( $item5, $patron1 );
465
    is( $is, 0, "Item5 cannot be requested to hold: 2 items, Item4 available, Item5 restricted" );
465
    is( $is, 0, "Item5 cannot be requested to hold: 2 items, Item4 available, Item5 restricted" );
466
466
467
    AddIssue( $patron2->unblessed, $item4->barcode );
467
    AddIssue( $patron2, $item4->barcode );
468
    $cache->flush();
468
    $cache->flush();
469
469
470
    $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblio2->biblionumber, patron => $patron1 } );
470
    $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblio2->biblionumber, patron => $patron1 } );
(-)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/HoldsQueue.t (-1 / +1 lines)
Lines 1840-1846 subtest 'Remove holds on check-in match' => sub { Link Here
1840
1840
1841
    t::lib::Mocks::mock_userenv( { branchcode => $lib->branchcode } );
1841
    t::lib::Mocks::mock_userenv( { branchcode => $lib->branchcode } );
1842
1842
1843
    AddIssue( $patron1->unblessed, $item->barcode, dt_from_string );
1843
    AddIssue( $patron1, $item->barcode, dt_from_string );
1844
1844
1845
    my $hold_id = AddReserve(
1845
    my $hold_id = AddReserve(
1846
        {
1846
        {
(-)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 1610-1616 subtest 'Checking in hook' => sub { Link Here
1610
    t::lib::Mocks::mock_preference('CirculateILL', 1);
1610
    t::lib::Mocks::mock_preference('CirculateILL', 1);
1611
1611
1612
    # Add an issue
1612
    # Add an issue
1613
    AddIssue( $patron->unblessed, $item->barcode );
1613
    AddIssue( $patron, $item->barcode );
1614
    # Make the item withdrawn so checking-in is rejected
1614
    # Make the item withdrawn so checking-in is rejected
1615
    t::lib::Mocks::mock_preference('BlockReturnOfWithdrawnItems', 1);
1615
    t::lib::Mocks::mock_preference('BlockReturnOfWithdrawnItems', 1);
1616
    $item->set({ withdrawn => 1 })->store;
1616
    $item->set({ withdrawn => 1 })->store;
(-)a/t/db_dependent/Koha/Account/Line.t (-9 / +17 lines)
Lines 518-523 subtest 'Renewal related tests' => sub { Link Here
518
            }
518
            }
519
        }
519
        }
520
    );
520
    );
521
521
    my $line = Koha::Account::Line->new(
522
    my $line = Koha::Account::Line->new(
522
    {
523
    {
523
        borrowernumber    => $patron->borrowernumber,
524
        borrowernumber    => $patron->borrowernumber,
Lines 703-709 subtest 'checkout() tests' => sub { Link Here
703
    my $account = $patron->account;
704
    my $account = $patron->account;
704
705
705
    t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode });
706
    t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode });
706
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
707
    my $checkout = AddIssue( $patron, $item->barcode );
707
708
708
    my $line = $account->add_debit({
709
    my $line = $account->add_debit({
709
        amount    => 10,
710
        amount    => 10,
Lines 816-829 subtest "void() tests" => sub { Link Here
816
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
817
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
817
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
818
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
818
819
819
    my $borrower = Koha::Patron->new( {
820
    my $staff = $builder->build_object({ class => 'Koha::Patrons' });
820
        cardnumber => 'dariahall',
821
    t::lib::Mocks::mock_userenv({ patron => $staff });
821
        surname => 'Hall',
822
822
        firstname => 'Daria',
823
    my $borrower = $builder->build_object(
823
    } );
824
        {
824
    $borrower->categorycode( $categorycode );
825
            class => 'Koha::Patrons',
825
    $borrower->branchcode( $branchcode );
826
            value => {
826
    $borrower->store;
827
                cardnumber => 'dariahall',
828
                surname => 'Hall',
829
                firstname => 'Daria',
830
                categorycode => $categorycode,
831
                branchcode => $branchcode,
832
            }
833
        }
834
    );
827
835
828
    my $account = Koha::Account->new({ patron_id => $borrower->id });
836
    my $account = Koha::Account->new({ patron_id => $borrower->id });
829
837
(-)a/t/db_dependent/Koha/Biblio.t (-5 / +5 lines)
Lines 904-911 subtest 'current_checkouts() and old_checkouts() tests' => sub { Link Here
904
904
905
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
905
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
906
906
907
    my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' })->unblessed;
907
    my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' });
908
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' })->unblessed;
908
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
909
909
910
    my $item_1 = $builder->build_sample_item;
910
    my $item_1 = $builder->build_sample_item;
911
    my $item_2 = $builder->build_sample_item({ biblionumber => $item_1->biblionumber });
911
    my $item_2 = $builder->build_sample_item({ biblionumber => $item_1->biblionumber });
Lines 1044-1050 subtest 'Recalls tests' => sub { Link Here
1044
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has more existing recall(s) than recalls_per_record" );
1044
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has more existing recall(s) than recalls_per_record" );
1045
1045
1046
    $recall1->set_cancelled;
1046
    $recall1->set_cancelled;
1047
    C4::Circulation::AddIssue( $patron1->unblessed, $item2->barcode );
1047
    C4::Circulation::AddIssue( $patron1, $item2->barcode );
1048
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has already checked out an item attached to this biblio" );
1048
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has already checked out an item attached to this biblio" );
1049
1049
1050
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if on_shelf_recalls = all and items are still available" );
1050
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if on_shelf_recalls = all and items are still available" );
Lines 1063-1070 subtest 'Recalls tests' => sub { Link Here
1063
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if no items are checked out" );
1063
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if no items are checked out" );
1064
1064
1065
    $recall2->set_cancelled;
1065
    $recall2->set_cancelled;
1066
    C4::Circulation::AddIssue( $patron2->unblessed, $item2->barcode );
1066
    C4::Circulation::AddIssue( $patron2, $item2->barcode );
1067
    C4::Circulation::AddIssue( $patron2->unblessed, $item1->barcode );
1067
    C4::Circulation::AddIssue( $patron2, $item1->barcode );
1068
    is( $biblio->can_be_recalled({ patron => $patron1 }), 2, "Can recall two items" );
1068
    is( $biblio->can_be_recalled({ patron => $patron1 }), 2, "Can recall two items" );
1069
1069
1070
    $item1->update({ withdrawn => 1 });
1070
    $item1->update({ withdrawn => 1 });
(-)a/t/db_dependent/Koha/Items.t (-12 / +12 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 497-503 subtest 'store' => sub { Link Here
497
            );
497
            );
498
498
499
            my $issue =
499
            my $issue =
500
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
500
              C4::Circulation::AddIssue( $patron, $item->barcode );
501
501
502
            # Simulate item marked as lost
502
            # Simulate item marked as lost
503
            $item->itemlost(3)->store;
503
            $item->itemlost(3)->store;
Lines 603-609 subtest 'store' => sub { Link Here
603
            );
603
            );
604
604
605
            my $issue =
605
            my $issue =
606
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
606
              C4::Circulation::AddIssue( $patron, $item->barcode );
607
607
608
            # Simulate item marked as lost
608
            # Simulate item marked as lost
609
            $item->itemlost(1)->store;
609
            $item->itemlost(1)->store;
Lines 810-816 subtest 'store' => sub { Link Here
810
            )->store;
810
            )->store;
811
811
812
            my $issue =
812
            my $issue =
813
              C4::Circulation::AddIssue( $patron->unblessed, $barcode );
813
              C4::Circulation::AddIssue( $patron, $barcode );
814
814
815
            # Simulate item marked as lost
815
            # Simulate item marked as lost
816
            $item->itemlost(1)->store;
816
            $item->itemlost(1)->store;
Lines 934-940 subtest 'store' => sub { Link Here
934
            )->store;
934
            )->store;
935
935
936
            my $issue =
936
            my $issue =
937
              C4::Circulation::AddIssue( $patron->unblessed, $barcode );
937
              C4::Circulation::AddIssue( $patron, $barcode );
938
938
939
            # Simulate item marked as lost
939
            # Simulate item marked as lost
940
            $item->itemlost(1)->store;
940
            $item->itemlost(1)->store;
Lines 984-990 subtest 'store' => sub { Link Here
984
            );
984
            );
985
985
986
            my $issue =
986
            my $issue =
987
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
987
              C4::Circulation::AddIssue( $patron, $item->barcode );
988
988
989
            # Simulate item marked as lost
989
            # Simulate item marked as lost
990
            $item->itemlost(1)->store;
990
            $item->itemlost(1)->store;
Lines 1075-1081 subtest 'store' => sub { Link Here
1075
            );
1075
            );
1076
1076
1077
            my $issue =
1077
            my $issue =
1078
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
1078
              C4::Circulation::AddIssue( $patron, $item->barcode );
1079
1079
1080
            # Simulate item marked as lost
1080
            # Simulate item marked as lost
1081
            $item->itemlost(1)->store;
1081
            $item->itemlost(1)->store;
Lines 1185-1191 subtest 'store' => sub { Link Here
1185
            );
1185
            );
1186
1186
1187
            my $issue =
1187
            my $issue =
1188
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
1188
              C4::Circulation::AddIssue( $patron, $item->barcode );
1189
1189
1190
            # Simulate item marked as lost
1190
            # Simulate item marked as lost
1191
            $item->itemlost(1)->store;
1191
            $item->itemlost(1)->store;
Lines 1309-1315 subtest 'store' => sub { Link Here
1309
            );
1309
            );
1310
1310
1311
            my $issue =
1311
            my $issue =
1312
              C4::Circulation::AddIssue( $patron->unblessed, $barcode );
1312
              C4::Circulation::AddIssue( $patron, $barcode );
1313
1313
1314
            # Simulate item marked as lost
1314
            # Simulate item marked as lost
1315
            $item->itemlost(1)->store;
1315
            $item->itemlost(1)->store;
Lines 1485-1496 subtest 'checkout' => sub { Link Here
1485
    is( $checkout, undef, 'Koha::Item->checkout should return undef if there is no current checkout on this item' );
1485
    is( $checkout, undef, 'Koha::Item->checkout should return undef if there is no current checkout on this item' );
1486
1486
1487
    # Add a checkout
1487
    # Add a checkout
1488
    my $patron = $builder->build({ source => 'Borrower' });
1488
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
1489
    C4::Circulation::AddIssue( $patron, $item->barcode );
1489
    C4::Circulation::AddIssue( $patron, $item->barcode );
1490
    $checkout = $retrieved_item_1->checkout;
1490
    $checkout = $retrieved_item_1->checkout;
1491
    is( ref( $checkout ), 'Koha::Checkout', 'Koha::Item->checkout should return a Koha::Checkout' );
1491
    is( ref( $checkout ), 'Koha::Checkout', 'Koha::Item->checkout should return a Koha::Checkout' );
1492
    is( $checkout->itemnumber, $item->itemnumber, 'Koha::Item->checkout should return the correct checkout' );
1492
    is( $checkout->itemnumber, $item->itemnumber, 'Koha::Item->checkout should return the correct checkout' );
1493
    is( $checkout->borrowernumber, $patron->{borrowernumber}, 'Koha::Item->checkout should return the correct checkout' );
1493
    is( $checkout->borrowernumber, $patron->borrowernumber, 'Koha::Item->checkout should return the correct checkout' );
1494
1494
1495
    # Do the return
1495
    # Do the return
1496
    C4::Circulation::AddReturn( $item->barcode );
1496
    C4::Circulation::AddReturn( $item->barcode );
(-)a/t/db_dependent/Koha/Object.t (-3 / +2 lines)
Lines 974-980 subtest 'unblessed_all_relateds' => sub { Link Here
974
    my ($biblionumber) = AddBiblio( MARC::Record->new, '' );
974
    my ($biblionumber) = AddBiblio( MARC::Record->new, '' );
975
    my $biblio = Koha::Biblios->find( $biblionumber );
975
    my $biblio = Koha::Biblios->find( $biblionumber );
976
    my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
976
    my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
977
978
    my $item = $builder->build_object(
977
    my $item = $builder->build_object(
979
        {
978
        {
980
            class => 'Koha::Items',
979
            class => 'Koha::Items',
Lines 984-995 subtest 'unblessed_all_relateds' => sub { Link Here
984
                biblionumber  => $biblio->biblionumber,
983
                biblionumber  => $biblio->biblionumber,
985
                itemlost      => 0,
984
                itemlost      => 0,
986
                withdrawn     => 0,
985
                withdrawn     => 0,
987
                itype => $itemtype
986
                itype         => $itemtype
988
            }
987
            }
989
        }
988
        }
990
    );
989
    );
991
990
992
    my $issue = AddIssue( $patron->unblessed, $item->barcode, DateTime->now->subtract( days => 1 ) );
991
    my $issue = AddIssue( $patron, $item->barcode, DateTime->now->subtract( days => 1 ) );
993
    my $overdues = Koha::Patrons->find( $patron->id )->overdues; # Koha::Patron->overdues prefetches
992
    my $overdues = Koha::Patrons->find( $patron->id )->overdues; # Koha::Patron->overdues prefetches
994
    my $overdue = $overdues->next->unblessed_all_relateds;
993
    my $overdue = $overdues->next->unblessed_all_relateds;
995
    is( $overdue->{issue_id}, $issue->issue_id, 'unblessed_all_relateds has field from the original table (issues)' );
994
    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 658-673 subtest 'checkouts + pending_checkouts + overdues + old_checkouts' => sub { Link Here
658
    is( $old_checkouts->count, 0, 'old_checkouts should not return any issues for that patron' );
658
    is( $old_checkouts->count, 0, 'old_checkouts should not return any issues for that patron' );
659
    is( ref($old_checkouts), 'Koha::Old::Checkouts', 'old_checkouts should return a Koha::Old::Checkouts object' );
659
    is( ref($old_checkouts), 'Koha::Old::Checkouts', 'old_checkouts should return a Koha::Old::Checkouts object' );
660
660
661
    # Not sure how this is useful, but AddIssue pass this variable to different other subroutines
662
    $patron = Koha::Patrons->find( $patron->borrowernumber )->unblessed;
663
664
    t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
661
    t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
665
662
666
    AddIssue( $patron, $item_1->barcode, DateTime->now->subtract( days => 1 ) );
663
    AddIssue( $patron, $item_1->barcode, DateTime->now->subtract( days => 1 ) );
667
    AddIssue( $patron, $item_2->barcode, DateTime->now->subtract( days => 5 ) );
664
    AddIssue( $patron, $item_2->barcode, DateTime->now->subtract( days => 5 ) );
668
    AddIssue( $patron, $item_3->barcode );
665
    AddIssue( $patron, $item_3->barcode );
669
666
670
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
671
    $checkouts = $patron->checkouts;
667
    $checkouts = $patron->checkouts;
672
    is( $checkouts->count, 3, 'checkouts should return 3 issues for that patron' );
668
    is( $checkouts->count, 3, 'checkouts should return 3 issues for that patron' );
673
    is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' );
669
    is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' );
Lines 1495-1505 subtest 'overdues' => sub { Link Here
1495
1491
1496
    t::lib::Mocks::mock_preference({ branchcode => $library->{branchcode} });
1492
    t::lib::Mocks::mock_preference({ branchcode => $library->{branchcode} });
1497
1493
1494
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
1495
1498
    AddIssue( $patron, $item_1->barcode, DateTime->now->subtract( days => 1 ) );
1496
    AddIssue( $patron, $item_1->barcode, DateTime->now->subtract( days => 1 ) );
1499
    AddIssue( $patron, $item_2->barcode, DateTime->now->subtract( days => 5 ) );
1497
    AddIssue( $patron, $item_2->barcode, DateTime->now->subtract( days => 5 ) );
1500
    AddIssue( $patron, $item_3->barcode );
1498
    AddIssue( $patron, $item_3->barcode );
1501
1499
1502
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
1503
    my $overdues = $patron->overdues;
1500
    my $overdues = $patron->overdues;
1504
    is( $overdues->count, 2, 'Patron should have 2 overdues');
1501
    is( $overdues->count, 2, 'Patron should have 2 overdues');
1505
    is( $overdues->next->itemnumber, $item_1->itemnumber, 'The issue should be returned in the same order as they have been done, first is correct' );
1502
    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/Plugins/Recall_hooks.t (-1 / +1 lines)
Lines 80-86 subtest 'after_recall_action hook' => sub { Link Here
80
        }
80
        }
81
    });
81
    });
82
82
83
    C4::Circulation::AddIssue( $patron2->unblessed, $item->barcode );
83
    C4::Circulation::AddIssue( $patron2, $item->barcode );
84
84
85
    warning_like {
85
    warning_like {
86
      Koha::Recalls->add_recall({
86
      Koha::Recalls->add_recall({
(-)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/Recall.t (-2 / +2 lines)
Lines 65-71 Koha::CirculationRules->set_rule({ Link Here
65
});
65
});
66
66
67
my $overdue_date = dt_from_string->subtract( days => 4 );
67
my $overdue_date = dt_from_string->subtract( days => 4 );
68
C4::Circulation::AddIssue( $patron2->unblessed, $item1->barcode, $overdue_date );
68
C4::Circulation::AddIssue( $patron2, $item1->barcode, $overdue_date );
69
69
70
my $recall1 = Koha::Recall->new({
70
my $recall1 = Koha::Recall->new({
71
    patron_id => $patron1->borrowernumber,
71
    patron_id => $patron1->borrowernumber,
Lines 160-166 is( $recall3->item_id, $item1->itemnumber, "Item persists for item-level recall" Link Here
160
$recall3->set_fulfilled;
160
$recall3->set_fulfilled;
161
ok( $recall3->fulfilled, "Recall has been fulfilled" );
161
ok( $recall3->fulfilled, "Recall has been fulfilled" );
162
162
163
C4::Circulation::AddIssue( $patron2->unblessed, $item1->barcode );
163
C4::Circulation::AddIssue( $patron2, $item1->barcode );
164
my $recall4 = Koha::Recall->new({
164
my $recall4 = Koha::Recall->new({
165
    patron_id => $patron1->borrowernumber,
165
    patron_id => $patron1->borrowernumber,
166
    created_date => dt_from_string,
166
    created_date => dt_from_string,
(-)a/t/db_dependent/Koha/Recalls.t (-2 / +2 lines)
Lines 65-72 Koha::CirculationRules->set_rules({ Link Here
65
    }
65
    }
66
});
66
});
67
67
68
C4::Circulation::AddIssue( $patron3->unblessed, $item1->barcode );
68
C4::Circulation::AddIssue( $patron3, $item1->barcode );
69
C4::Circulation::AddIssue( $patron3->unblessed, $item2->barcode );
69
C4::Circulation::AddIssue( $patron3, $item2->barcode );
70
70
71
my ( $recall, $due_interval, $due_date ) = Koha::Recalls->add_recall({
71
my ( $recall, $due_interval, $due_date ) = Koha::Recalls->add_recall({
72
    patron => undef,
72
    patron => undef,
(-)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 (-31 / +40 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 357-363 Dear <<borrowers.firstname>> <<borrowers.surname>>, Link Here
357
The order <<aqorders.ordernumber>> (<<biblio.title>>) has been received.
358
The order <<aqorders.ordernumber>> (<<biblio.title>>) has been received.
358
Your library.
359
Your library.
359
        |;
360
        |;
360
        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 } };
361
        my $letter = process_letter( { template => $template, %$params });
362
        my $letter = process_letter( { template => $template, %$params });
362
        my $tt_template = q|
363
        my $tt_template = q|
363
Dear [% borrower.firstname %] [% borrower.surname %],
364
Dear [% borrower.firstname %] [% borrower.surname %],
Lines 433-446 Notes: [% article_request.patron_notes %] Link Here
433
434
434
        my $dbh = C4::Context->dbh;
435
        my $dbh = C4::Context->dbh;
435
        # Enable notification for CHECKOUT - Things are hardcoded here but should work with default data
436
        # Enable notification for CHECKOUT - Things are hardcoded here but should work with default data
436
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 6 );
437
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|,
438
            undef, $patron->borrowernumber, 6 );
437
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
439
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
438
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
440
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
441
439
        # Enable notification for CHECKIN - Things are hardcoded here but should work with default data
442
        # Enable notification for CHECKIN - Things are hardcoded here but should work with default data
440
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 5 );
443
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|,
444
            undef, $patron->borrowernumber, 5);
441
        $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
445
        $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
442
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
446
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
443
447
448
444
        # historic syntax
449
        # historic syntax
445
        my $checkout_template = q|
450
        my $checkout_template = q|
446
The following items have been checked out:
451
The following items have been checked out:
Lines 461-471 Thank you for visiting <<branches.branchname>>. Link Here
461
466
462
        C4::Circulation::AddIssue( $patron, $item1->{barcode} );
467
        C4::Circulation::AddIssue( $patron, $item1->{barcode} );
463
        my $first_checkout_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
468
        my $first_checkout_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
469
464
        C4::Circulation::AddIssue( $patron, $item2->{barcode} );
470
        C4::Circulation::AddIssue( $patron, $item2->{barcode} );
465
        my $second_checkout_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
471
        my $second_checkout_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
466
472
467
        AddReturn( $item1->{barcode} );
473
        AddReturn( $item1->{barcode} );
468
        my $first_checkin_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
474
        my $first_checkin_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
475
469
        AddReturn( $item2->{barcode} );
476
        AddReturn( $item2->{barcode} );
470
        my $second_checkin_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
477
        my $second_checkin_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
471
478
Lines 491-501 Thank you for visiting [% branch.branchname %]. Link Here
491
498
492
        C4::Circulation::AddIssue( $patron, $item1->{barcode} );
499
        C4::Circulation::AddIssue( $patron, $item1->{barcode} );
493
        my $first_checkout_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
500
        my $first_checkout_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
501
494
        C4::Circulation::AddIssue( $patron, $item2->{barcode} );
502
        C4::Circulation::AddIssue( $patron, $item2->{barcode} );
495
        my $second_checkout_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
503
        my $second_checkout_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
496
504
497
        AddReturn( $item1->{barcode} );
505
        AddReturn( $item1->{barcode} );
498
        my $first_checkin_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
506
        my $first_checkin_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
507
499
        AddReturn( $item2->{barcode} );
508
        AddReturn( $item2->{barcode} );
500
        my $second_checkin_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
509
        my $second_checkin_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
501
510
Lines 513-519 Thank you for visiting [% branch.branchname %]. Link Here
513
522
514
        my $dbh = C4::Context->dbh;
523
        my $dbh = C4::Context->dbh;
515
        # Enable notification for DUEDGST - Things are hardcoded here but should work with default data
524
        # Enable notification for DUEDGST - Things are hardcoded here but should work with default data
516
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 1 );
525
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->borrowernumber, 1 );
517
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
526
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
518
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
527
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
519
528
Lines 542-548 You have [% count %] items due Link Here
542
        my $reserve_id1 = C4::Reserves::AddReserve(
551
        my $reserve_id1 = C4::Reserves::AddReserve(
543
            {
552
            {
544
                branchcode     => $library->{branchcode},
553
                branchcode     => $library->{branchcode},
545
                borrowernumber => $patron->{borrowernumber},
554
                borrowernumber => $patron->borrowernumber,
546
                biblionumber   => $biblio1->{biblionumber},
555
                biblionumber   => $biblio1->{biblionumber},
547
                notes          => "a note",
556
                notes          => "a note",
548
                itemnumber     => $item1->{itemnumber},
557
                itemnumber     => $item1->{itemnumber},
Lines 551-557 You have [% count %] items due Link Here
551
        my $reserve_id2 = C4::Reserves::AddReserve(
560
        my $reserve_id2 = C4::Reserves::AddReserve(
552
            {
561
            {
553
                branchcode     => $library->{branchcode},
562
                branchcode     => $library->{branchcode},
554
                borrowernumber => $patron->{borrowernumber},
563
                borrowernumber => $patron->borrowernumber,
555
                biblionumber   => $biblio1->{biblionumber},
564
                biblionumber   => $biblio1->{biblionumber},
556
                notes          => "a note",
565
                notes          => "a note",
557
                itemnumber     => $item1->{itemnumber},
566
                itemnumber     => $item1->{itemnumber},
Lines 560-566 You have [% count %] items due Link Here
560
        my $reserve_id3 = C4::Reserves::AddReserve(
569
        my $reserve_id3 = C4::Reserves::AddReserve(
561
            {
570
            {
562
                branchcode     => $library->{branchcode},
571
                branchcode     => $library->{branchcode},
563
                borrowernumber => $patron->{borrowernumber},
572
                borrowernumber => $patron->borrowernumber,
564
                biblionumber   => $biblio2->{biblionumber},
573
                biblionumber   => $biblio2->{biblionumber},
565
                notes          => "another note",
574
                notes          => "another note",
566
                itemnumber     => $item2->{itemnumber},
575
                itemnumber     => $item2->{itemnumber},
Lines 708-720 EOF Link Here
708
717
709
        my $checkout = C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
718
        my $checkout = C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
710
        $checkout->set( { timestamp => $now, issuedate => $one_minute_ago } )->store;
719
        $checkout->set( { timestamp => $now, issuedate => $one_minute_ago } )->store;
711
        my $first_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
720
        my $first_slip = C4::Members::IssueSlip( $branchcode, $patron->borrowernumber );
712
721
713
        $checkout = C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
722
        $checkout = C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
714
        $checkout->set( { timestamp => $now, issuedate => $now } )->store;
723
        $checkout->set( { timestamp => $now, issuedate => $now } )->store;
715
        my $yesterday = dt_from_string->subtract( days => 1 );
724
        my $yesterday = dt_from_string->subtract( days => 1 );
716
        C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue
725
        C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue
717
        my $second_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
726
        my $second_slip = C4::Members::IssueSlip( $branchcode, $patron->borrowernumber );
718
727
719
        # Cleanup
728
        # Cleanup
720
        AddReturn( $item1->{barcode} );
729
        AddReturn( $item1->{barcode} );
Lines 768-779 EOF Link Here
768
777
769
        $checkout = C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
778
        $checkout = C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
770
        $checkout->set( { timestamp => $now, issuedate => $one_minute_ago } )->store;
779
        $checkout->set( { timestamp => $now, issuedate => $one_minute_ago } )->store;
771
        my $first_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
780
        my $first_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->borrowernumber );
772
781
773
        $checkout = C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
782
        $checkout = C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
774
        $checkout->set( { timestamp => $now, issuedate => $now } )->store;
783
        $checkout->set( { timestamp => $now, issuedate => $now } )->store;
775
        C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue
784
        C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue
776
        my $second_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
785
        my $second_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->borrowernumber );
777
786
778
        # There is too many line breaks generated by the historic syntax
787
        # There is too many line breaks generated by the historic syntax
779
        $second_slip->{content} =~ s|</p>\n\n\n<p>|</p>\n\n<p>|s;
788
        $second_slip->{content} =~ s|</p>\n\n\n<p>|</p>\n\n<p>|s;
Lines 846-852 EOF Link Here
846
        my $letter = C4::Overdues::parse_overdues_letter(
855
        my $letter = C4::Overdues::parse_overdues_letter(
847
            {
856
            {
848
                letter_code => $code,
857
                letter_code => $code,
849
                borrowernumber => $patron->{borrowernumber},
858
                borrowernumber => $patron->borrowernumber,
850
                branchcode  => $library->{branchcode},
859
                branchcode  => $library->{branchcode},
851
                items       => \@items,
860
                items       => \@items,
852
                substitute  => {
861
                substitute  => {
Lines 904-910 EOF Link Here
904
        my $tt_letter = C4::Overdues::parse_overdues_letter(
913
        my $tt_letter = C4::Overdues::parse_overdues_letter(
905
            {
914
            {
906
                letter_code => $code,
915
                letter_code => $code,
907
                borrowernumber => $patron->{borrowernumber},
916
                borrowernumber => $patron->borrowernumber,
908
                branchcode  => $library->{branchcode},
917
                branchcode  => $library->{branchcode},
909
                items       => \@items,
918
                items       => \@items,
910
                substitute  => {
919
                substitute  => {
Lines 931-941 EOF Link Here
931
        $dbh->do("DELETE FROM message_queue");
940
        $dbh->do("DELETE FROM message_queue");
932
941
933
        # Enable notification for CHECKOUT - Things are hardcoded here but should work with default data
942
        # Enable notification for CHECKOUT - Things are hardcoded here but should work with default data
934
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 6 );
943
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->borrowernumber, 6 );
935
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
944
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
936
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
945
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
937
        # Enable notification for CHECKIN - Things are hardcoded here but should work with default data
946
        # Enable notification for CHECKIN - Things are hardcoded here but should work with default data
938
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 5 );
947
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->borrowernumber, 5 );
939
        $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
948
        $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
940
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
949
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
941
950
(-)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 (-35 / +33 lines)
Lines 48-77 my $another_library = $builder->build({ source => 'Branch' }); Link Here
48
my $itemtype        = $builder->build({ source => 'Itemtype' })->{itemtype};
48
my $itemtype        = $builder->build({ source => 'Itemtype' })->{itemtype};
49
49
50
C4::Context->_new_userenv('xxx');
50
C4::Context->_new_userenv('xxx');
51
my $patron = $builder->build({
51
my $patron = $builder->build_object({
52
    source => 'Borrower',
52
    class => 'Koha::Patrons',
53
    value => {
53
    value => {
54
        branchcode => $library->{branchcode},
54
        branchcode => $library->{branchcode},
55
        flags      => 1, # superlibrarian
55
        flags      => 1, # superlibrarian
56
    }
56
    }
57
});
57
});
58
my $p = Koha::Patrons->find( $patron->{borrowernumber} );
58
t::lib::Mocks::mock_userenv({ patron => $patron });
59
t::lib::Mocks::mock_userenv({ patron => $p });
60
59
61
my $patron2 = $builder->build({
60
my $patron2 = $builder->build_object({
62
    source => 'Borrower',
61
    class => 'Koha::Patrons',
63
    value => {
62
    value => {
64
        branchcode => $library->{branchcode},
63
        branchcode => $library->{branchcode},
65
    }
64
    }
66
});
65
});
67
my $patron3 = $builder->build({
66
my $patron3 = $builder->build_object({
68
    source => 'Borrower',
67
    class => 'Koha::Patrons',
69
    value => {
68
    value => {
70
        branchcode => $another_library->{branchcode},
69
        branchcode => $another_library->{branchcode},
71
        flags => undef,
70
        flags => undef,
72
    }
71
    }
73
});
72
});
74
my $p3 = Koha::Patrons->find( $patron3->{borrowernumber} );
75
73
76
# Discharge not possible with issues
74
# Discharge not possible with issues
77
my ( $biblionumber ) = AddBiblio( MARC::Record->new, '');
75
my ( $biblionumber ) = AddBiblio( MARC::Record->new, '');
Lines 86-122 $builder->build_sample_item( Link Here
86
);
84
);
87
85
88
AddIssue( $patron, $barcode );
86
AddIssue( $patron, $barcode );
89
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->{borrowernumber} }), 0, 'A patron with issues cannot be discharged' );
87
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 0, 'A patron with issues cannot be discharged' );
90
88
91
is( Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} }), undef, 'No request done if patron has issues' );
89
is( Koha::Patron::Discharge::request({ borrowernumber => $patron->borrowernumber }), undef, 'No request done if patron has issues' );
92
is( Koha::Patron::Discharge::discharge({ borrowernumber => $patron->{borrowernumber} }), undef, 'No discharge done if patron has issues' );
90
is( Koha::Patron::Discharge::discharge({ borrowernumber => $patron->borrowernumber }), undef, 'No discharge done if patron has issues' );
93
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request' );
91
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request' );
94
is_deeply( [ Koha::Patron::Discharge::get_validated ], [], 'There is no validated discharge' );
92
is_deeply( [ Koha::Patron::Discharge::get_validated ], [], 'There is no validated discharge' );
95
93
96
AddReturn( $barcode );
94
AddReturn( $barcode );
97
95
98
# Discharge possible without issue
96
# Discharge possible without issue
99
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->{borrowernumber} }), 1, 'A patron without issues can be discharged' );
97
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 1, 'A patron without issues can be discharged' );
100
98
101
is(Koha::Patron::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
99
is(Koha::Patron::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
102
100
103
# Verify that the user is not discharged anymore if the restriction has been lifted
101
# Verify that the user is not discharged anymore if the restriction has been lifted
104
Koha::Patron::Discharge::discharge( { borrowernumber => $patron->{borrowernumber} } );
102
Koha::Patron::Discharge::discharge( { borrowernumber => $patron->borrowernumber } );
105
Koha::Patron::Discharge::discharge( { borrowernumber => $patron2->{borrowernumber} } );
103
Koha::Patron::Discharge::discharge( { borrowernumber => $patron2->borrowernumber } );
106
Koha::Patron::Discharge::discharge( { borrowernumber => $patron3->{borrowernumber} } );
104
Koha::Patron::Discharge::discharge( { borrowernumber => $patron3->borrowernumber } );
107
is( Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->{borrowernumber} } ), 1, 'The patron has been discharged' );
105
is( Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->borrowernumber } ), 1, 'The patron has been discharged' );
108
is( Koha::Patrons->find( $patron->{borrowernumber} )->is_debarred, '9999-12-31', 'The patron has been debarred after discharge' );
106
is( Koha::Patrons->find( $patron->borrowernumber )->is_debarred, '9999-12-31', 'The patron has been debarred after discharge' );
109
is( scalar( Koha::Patron::Discharge::get_validated ),             3,            'There are 3 validated discharges' );
107
is( scalar( Koha::Patron::Discharge::get_validated ),             3,            'There are 3 validated discharges' );
110
is( scalar( Koha::Patron::Discharge::get_validated( { borrowernumber => $patron->{borrowernumber} } ) ), 1, 'There is 1 validated discharge for a given patron' );
108
is( scalar( Koha::Patron::Discharge::get_validated( { borrowernumber => $patron->borrowernumber } ) ), 1, 'There is 1 validated discharge for a given patron' );
111
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
109
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
112
Koha::Patron::Debarments::DelUniqueDebarment( { 'borrowernumber' => $patron->{borrowernumber}, 'type' => 'DISCHARGE' } );
110
Koha::Patron::Debarments::DelUniqueDebarment( { 'borrowernumber' => $patron->borrowernumber, 'type' => 'DISCHARGE' } );
113
ok( !Koha::Patrons->find( $patron->{borrowernumber} )->is_debarred, 'The debarment has been lifted' );
111
ok( !Koha::Patrons->find( $patron->borrowernumber )->is_debarred, 'The debarment has been lifted' );
114
ok( !Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->{borrowernumber} } ), 'The patron is not discharged after the restriction has been lifted' );
112
ok( !Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->borrowernumber } ), 'The patron is not discharged after the restriction has been lifted' );
115
113
116
# Verify that the discharge works multiple times
114
# Verify that the discharge works multiple times
117
Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} });
115
Koha::Patron::Discharge::request({ borrowernumber => $patron->borrowernumber });
118
is(scalar( Koha::Patron::Discharge::get_pendings ), 1, 'There is a pending discharge request (second time)');
116
is(scalar( Koha::Patron::Discharge::get_pendings ), 1, 'There is a pending discharge request (second time)');
119
Koha::Patron::Discharge::discharge( { borrowernumber => $patron->{borrowernumber} } );
117
Koha::Patron::Discharge::discharge( { borrowernumber => $patron->borrowernumber } );
120
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request (second time)');
118
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request (second time)');
121
119
122
SKIP: {
120
SKIP: {
Lines 124-130 SKIP: { Link Here
124
        5 unless can_run('weasyprint');
122
        5 unless can_run('weasyprint');
125
123
126
    isnt(
124
    isnt(
127
        Koha::Patron::Discharge::generate_as_pdf( { borrowernumber => $patron->{borrowernumber} } ),
125
        Koha::Patron::Discharge::generate_as_pdf( { borrowernumber => $patron->borrowernumber } ),
128
        undef,
126
        undef,
129
        "Temporary PDF generated."
127
        "Temporary PDF generated."
130
    );
128
    );
Lines 135-141 SKIP: { Link Here
135
133
136
    my $result;
134
    my $result;
137
    warning_is
135
    warning_is
138
        { $result = Koha::Patron::Discharge::generate_as_pdf( { borrowernumber => $patron->{borrowernumber} } ); }
136
        { $result = Koha::Patron::Discharge::generate_as_pdf( { borrowernumber => $patron->borrowernumber } ); }
139
        'Some error',
137
        'Some error',
140
        'Failed call to run() prints the generated error';
138
        'Failed call to run() prints the generated error';
141
139
Lines 144-150 SKIP: { Link Here
144
    $mocked_ipc->mock( 'can_run', undef );
142
    $mocked_ipc->mock( 'can_run', undef );
145
143
146
    warning_is
144
    warning_is
147
        { $result = Koha::Patron::Discharge::generate_as_pdf( { borrowernumber => $patron->{borrowernumber} } ); }
145
        { $result = Koha::Patron::Discharge::generate_as_pdf( { borrowernumber => $patron->borrowernumber } ); }
148
        'weasyprint not found!',
146
        'weasyprint not found!',
149
        'Expected failure because of missing weasyprint';
147
        'Expected failure because of missing weasyprint';
150
148
Lines 152-158 SKIP: { Link Here
152
}
150
}
153
151
154
# FIXME Should be a Koha::Object object
152
# FIXME Should be a Koha::Object object
155
is( ref(Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} })), 'Koha::Schema::Result::Discharge', 'Discharge request sent' );
153
is( ref(Koha::Patron::Discharge::request({ borrowernumber => $patron->borrowernumber })), 'Koha::Schema::Result::Discharge', 'Discharge request sent' );
156
154
157
subtest 'search_limited' => sub {
155
subtest 'search_limited' => sub {
158
    plan tests => 4;
156
    plan tests => 4;
Lines 161-177 subtest 'search_limited' => sub { Link Here
161
    my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2' } )->store;
159
    my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2' } )->store;
162
    # $patron and $patron2 are from the same library, $patron3 from another one
160
    # $patron and $patron2 are from the same library, $patron3 from another one
163
    # Logged in user is $patron, superlibrarian
161
    # Logged in user is $patron, superlibrarian
164
    t::lib::Mocks::mock_userenv({ patron => $p });
162
    t::lib::Mocks::mock_userenv({ patron => $patron });
165
    Koha::Library::Group->new({ parent_id => $group_1->id,  branchcode => $patron->{branchcode} })->store();
163
    Koha::Library::Group->new({ parent_id => $group_1->id,  branchcode => $patron->branchcode })->store();
166
    Koha::Library::Group->new({ parent_id => $group_2->id,  branchcode => $patron3->{branchcode} })->store();
164
    Koha::Library::Group->new({ parent_id => $group_2->id,  branchcode => $patron3->branchcode })->store();
167
    Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} });
165
    Koha::Patron::Discharge::request({ borrowernumber => $patron->borrowernumber });
168
    Koha::Patron::Discharge::request({ borrowernumber => $patron2->{borrowernumber} });
166
    Koha::Patron::Discharge::request({ borrowernumber => $patron2->borrowernumber });
169
    Koha::Patron::Discharge::request({ borrowernumber => $patron3->{borrowernumber} });
167
    Koha::Patron::Discharge::request({ borrowernumber => $patron3->borrowernumber });
170
    is( scalar( Koha::Patron::Discharge::get_pendings), 3, 'With permission, all discharges are visible' );
168
    is( scalar( Koha::Patron::Discharge::get_pendings), 3, 'With permission, all discharges are visible' );
171
    is( Koha::Patron::Discharge::count({pending => 1}), 3, 'With permission, all discharges are visible' );
169
    is( Koha::Patron::Discharge::count({pending => 1}), 3, 'With permission, all discharges are visible' );
172
170
173
    # With patron 3 logged in, only discharges from their group are visible
171
    # With patron 3 logged in, only discharges from their group are visible
174
    t::lib::Mocks::mock_userenv({ patron => $p3 });
172
    t::lib::Mocks::mock_userenv({ patron => $patron3 });
175
    is( scalar( Koha::Patron::Discharge::get_pendings), 1, 'Without permission, only discharge from our group are visible' );
173
    is( scalar( Koha::Patron::Discharge::get_pendings), 1, 'Without permission, only discharge from our group are visible' );
176
    is( Koha::Patron::Discharge::count({pending => 1}), 1, 'Without permission, only discharge from our group are visible' );
174
    is( Koha::Patron::Discharge::count({pending => 1}), 1, 'Without permission, only discharge from our group are visible' );
177
};
175
};
(-)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/Reserves.t (-2 / +2 lines)
Lines 1156-1162 subtest 'RevertWaitingStatus' => sub { Link Here
1156
    my $hold_4 = place_item_hold( $patron_4, $item_1, $library, $priority );
1156
    my $hold_4 = place_item_hold( $patron_4, $item_1, $library, $priority );
1157
1157
1158
    $hold_1->set_waiting;
1158
    $hold_1->set_waiting;
1159
    AddIssue( $patron_3->unblessed, $item_1->barcode, undef, 'revert' );
1159
    AddIssue( $patron_3, $item_1->barcode, undef, 'revert' );
1160
1160
1161
    my $holds = $biblio->holds;
1161
    my $holds = $biblio->holds;
1162
    is( $holds->count, 3, 'One hold has been deleted' );
1162
    is( $holds->count, 3, 'One hold has been deleted' );
Lines 1320-1326 subtest 'AllowHoldOnPatronPossession test' => sub { Link Here
1320
    my $patron = $builder->build_object({ class => "Koha::Patrons",
1320
    my $patron = $builder->build_object({ class => "Koha::Patrons",
1321
                                          value => { branchcode => $item->homebranch }});
1321
                                          value => { branchcode => $item->homebranch }});
1322
1322
1323
    C4::Circulation::AddIssue($patron->unblessed,
1323
    C4::Circulation::AddIssue($patron,
1324
                              $item->barcode);
1324
                              $item->barcode);
1325
    t::lib::Mocks::mock_preference('AllowHoldsOnPatronsPossessions', 0);
1325
    t::lib::Mocks::mock_preference('AllowHoldsOnPatronsPossessions', 0);
1326
1326
(-)a/t/db_dependent/Reserves/GetReserveFee.t (-52 / +52 lines)
Lines 59-81 $builder->build({ Link Here
59
        reservefee            => 0,
59
        reservefee            => 0,
60
    },
60
    },
61
});
61
});
62
my $patron1 = $builder->build({
62
my $patron1 = $builder->build_object({
63
    source => 'Borrower',
63
    class => 'Koha::Patrons',
64
    value  => {
64
    value  => {
65
        categorycode => 'XYZ1',
65
        categorycode => 'XYZ1',
66
    },
66
    },
67
});
67
});
68
my $patron2 = $builder->build({
68
my $patron2 = $builder->build_object({
69
    source => 'Borrower',
69
    class => 'Koha::Patrons',
70
    value  => {
70
    value  => {
71
        categorycode => 'XYZ1',
71
        categorycode => 'XYZ1',
72
    },
72
    },
73
});
73
});
74
my $patron3 = $builder->build({
74
my $patron3 = $builder->build_object({
75
    source => 'Borrower',
75
    class => 'Koha::Patrons',
76
});
76
});
77
my $patron4 = $builder->build({
77
my $patron4 = $builder->build_object({
78
    source => 'Borrower',
78
    class => 'Koha::Patrons',
79
    value  => {
79
    value  => {
80
        categorycode => 'XYZ2',
80
        categorycode => 'XYZ2',
81
    },
81
    },
Lines 101-130 subtest 'GetReserveFee' => sub { Link Here
101
101
102
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} ); # the date does not really matter
102
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} ); # the date does not really matter
103
    C4::Circulation::AddIssue( $patron3, $item2->barcode, '2015-12-31', 0, undef, 0, {} ); # the date does not really matter
103
    C4::Circulation::AddIssue( $patron3, $item2->barcode, '2015-12-31', 0, undef, 0, {} ); # the date does not really matter
104
    my $acc2 = acctlines( $patron2->{borrowernumber} );
104
    my $acc2 = acctlines( $patron2->borrowernumber );
105
    my $res1 = addreserve( $patron1->{borrowernumber} );
105
    my $res1 = addreserve( $patron1->borrowernumber );
106
106
107
    t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
107
    t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
108
    my $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->biblionumber );
108
    my $fee = C4::Reserves::GetReserveFee( $patron2->borrowernumber, $biblio->biblionumber );
109
    is( $fee > 0, 1, 'Patron 2 should be charged cf GetReserveFee' );
109
    is( $fee > 0, 1, 'Patron 2 should be charged cf GetReserveFee' );
110
    C4::Reserves::ChargeReserveFee( $patron2->{borrowernumber}, $fee, $biblio->title );
110
    C4::Reserves::ChargeReserveFee( $patron2->borrowernumber, $fee, $biblio->title );
111
    is( acctlines( $patron2->{borrowernumber} ), $acc2 + 1, 'Patron 2 has been charged by ChargeReserveFee' );
111
    is( acctlines( $patron2->borrowernumber ), $acc2 + 1, 'Patron 2 has been charged by ChargeReserveFee' );
112
112
113
    # If we delete the reserve, there should be no charge
113
    # If we delete the reserve, there should be no charge
114
    $dbh->do( "DELETE FROM reserves WHERE borrowernumber = ?", undef, ( $patron1->{borrowernumber}) );
114
    $dbh->do( "DELETE FROM reserves WHERE borrowernumber = ?", undef, ( $patron1->borrowernumber) );
115
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->biblionumber );
115
    $fee = C4::Reserves::GetReserveFee( $patron2->borrowernumber, $biblio->biblionumber );
116
    is( $fee, 0, 'HoldFeeMode=not_always, Patron 2 should not be charged' );
116
    is( $fee, 0, 'HoldFeeMode=not_always, Patron 2 should not be charged' );
117
117
118
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
118
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
119
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->biblionumber );
119
    $fee = C4::Reserves::GetReserveFee( $patron2->borrowernumber, $biblio->biblionumber );
120
    is( int($fee), 2, 'HoldFeeMode=any_time_is_placed, Patron 2 should be charged' );
120
    is( int($fee), 2, 'HoldFeeMode=any_time_is_placed, Patron 2 should be charged' );
121
121
122
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
122
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
123
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->biblionumber );
123
    $fee = C4::Reserves::GetReserveFee( $patron2->borrowernumber, $biblio->biblionumber );
124
    is( int($fee), 2, 'HoldFeeMode=any_time_is_collected, Patron 2 should be charged' );
124
    is( int($fee), 2, 'HoldFeeMode=any_time_is_collected, Patron 2 should be charged' );
125
125
126
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
126
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
127
    $fee = C4::Reserves::GetReserveFee( $patron4->{borrowernumber}, $biblio->biblionumber );
127
    $fee = C4::Reserves::GetReserveFee( $patron4->borrowernumber, $biblio->biblionumber );
128
    is( $fee, 0, 'HoldFeeMode=any_time_is_placed ; fee == 0, Patron 4 should not be charged' );
128
    is( $fee, 0, 'HoldFeeMode=any_time_is_placed ; fee == 0, Patron 4 should not be charged' );
129
};
129
};
130
130
Lines 138-158 subtest 'Integration with AddReserve' => sub { Link Here
138
138
139
        t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
139
        t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
140
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
140
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
141
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
141
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->borrowernumber );
142
        addreserve( $patron1->{borrowernumber} );
142
        addreserve( $patron1->borrowernumber );
143
        is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - No fee charged for patron 1 if not issued' );
143
        is( acctlines( $patron1->borrowernumber ), 0, 'not_always - No fee charged for patron 1 if not issued' );
144
144
145
        t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
145
        t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
146
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
146
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
147
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
147
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->borrowernumber );
148
        addreserve( $patron1->{borrowernumber} );
148
        addreserve( $patron1->borrowernumber );
149
        is( acctlines( $patron1->{borrowernumber} ), 1, 'any_time_is_placed - Patron should be always charged' );
149
        is( acctlines( $patron1->borrowernumber ), 1, 'any_time_is_placed - Patron should be always charged' );
150
150
151
        t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
151
        t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
152
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
152
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
153
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
153
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->borrowernumber );
154
        addreserve( $patron1->{borrowernumber} );
154
        addreserve( $patron1->borrowernumber );
155
        is( acctlines( $patron1->{borrowernumber} ), 0, 'any_time_is_collected - Patron should not be charged when placing a hold' );
155
        is( acctlines( $patron1->borrowernumber ), 0, 'any_time_is_collected - Patron should not be charged when placing a hold' );
156
    };
156
    };
157
157
158
    subtest 'Items are issued' => sub {
158
    subtest 'Items are issued' => sub {
Lines 164-219 subtest 'Integration with AddReserve' => sub { Link Here
164
164
165
        t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
165
        t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
166
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
166
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
167
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
167
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->borrowernumber );
168
        addreserve( $patron1->{borrowernumber} );
168
        addreserve( $patron1->borrowernumber );
169
        is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged if items are not all checked out' );
169
        is( acctlines( $patron1->borrowernumber ), 0, 'not_always - Patron should not be charged if items are not all checked out' );
170
170
171
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
171
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
172
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
172
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->borrowernumber );
173
        addreserve( $patron3->{borrowernumber} );
173
        addreserve( $patron3->borrowernumber );
174
        addreserve( $patron1->{borrowernumber} );
174
        addreserve( $patron1->borrowernumber );
175
        is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged if all the items are not checked out, even if 1 hold is already placed' );
175
        is( acctlines( $patron1->borrowernumber ), 0, 'not_always - Patron should not be charged if all the items are not checked out, even if 1 hold is already placed' );
176
176
177
        C4::Circulation::AddIssue( $patron3, $item2->barcode, '2015-12-31', 0, undef, 0, {} );
177
        C4::Circulation::AddIssue( $patron3, $item2->barcode, '2015-12-31', 0, undef, 0, {} );
178
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
178
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
179
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
179
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->borrowernumber );
180
        addreserve( $patron1->{borrowernumber} );
180
        addreserve( $patron1->borrowernumber );
181
        is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged if all items are checked out but no holds are placed' );
181
        is( acctlines( $patron1->borrowernumber ), 0, 'not_always - Patron should not be charged if all items are checked out but no holds are placed' );
182
182
183
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
183
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
184
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
184
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->borrowernumber );
185
        addreserve( $patron3->{borrowernumber} );
185
        addreserve( $patron3->borrowernumber );
186
        addreserve( $patron1->{borrowernumber} );
186
        addreserve( $patron1->borrowernumber );
187
        is( acctlines( $patron1->{borrowernumber} ), 1, 'not_always - Patron should only be charged if all items are checked out and at least 1 hold is already placed' );
187
        is( acctlines( $patron1->borrowernumber ), 1, 'not_always - Patron should only be charged if all items are checked out and at least 1 hold is already placed' );
188
    };
188
    };
189
};
189
};
190
190
191
subtest 'Integration with AddIssue' => sub {
191
subtest 'Integration with AddIssue' => sub {
192
    plan tests => 5;
192
    plan tests => 5;
193
193
194
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->{borrowernumber} );
194
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->borrowernumber );
195
    $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
195
    $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
196
    $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
196
    $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->borrowernumber );
197
197
198
    t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
198
    t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
199
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} );
199
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} );
200
    is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged' );
200
    is( acctlines( $patron1->borrowernumber ), 0, 'not_always - Patron should not be charged' );
201
201
202
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
202
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
203
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->{borrowernumber} );
203
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->borrowernumber );
204
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} );
204
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} );
205
    is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged' );
205
    is( acctlines( $patron1->borrowernumber ), 0, 'not_always - Patron should not be charged' );
206
206
207
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
207
    t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
208
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->{borrowernumber} );
208
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->borrowernumber );
209
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} );
209
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} );
210
    is( acctlines( $patron1->{borrowernumber} ), 0, 'any_time_is_collected - Patron should not be charged when checking out an item which was not placed hold for him' );
210
    is( acctlines( $patron1->borrowernumber ), 0, 'any_time_is_collected - Patron should not be charged when checking out an item which was not placed hold for him' );
211
211
212
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->{borrowernumber} );
212
    $dbh->do( "DELETE FROM issues       WHERE borrowernumber = ?", undef, $patron1->borrowernumber );
213
    my $id = addreserve( $patron1->{borrowernumber} );
213
    my $id = addreserve( $patron1->borrowernumber );
214
    is( acctlines( $patron1->{borrowernumber} ), 0, 'any_time_is_collected - Patron should not be charged yet (just checking to make sure)');
214
    is( acctlines( $patron1->borrowernumber ), 0, 'any_time_is_collected - Patron should not be charged yet (just checking to make sure)');
215
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} );
215
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} );
216
    is( acctlines( $patron1->{borrowernumber} ), 1, 'any_time_is_collected - Patron should not be charged when checking out an item which was not placed hold for him' );
216
    is( acctlines( $patron1->borrowernumber ), 1, 'any_time_is_collected - Patron should not be charged when checking out an item which was not placed hold for him' );
217
};
217
};
218
218
219
sub acctlines { #calculate number of accountlines for a patron
219
sub acctlines { #calculate number of accountlines for a patron
(-)a/t/db_dependent/SIP/ILS.t (-5 / +5 lines)
Lines 199-205 subtest cancel_waiting_hold => sub { Link Here
199
    t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode, flags => 1 });
199
    t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode, flags => 1 });
200
200
201
    my $item = $builder->build_sample_item({
201
    my $item = $builder->build_sample_item({
202
        library       => $library->branchcode,
202
        library => $library->branchcode,
203
    });
203
    });
204
204
205
    Koha::CirculationRules->set_rules(
205
    Koha::CirculationRules->set_rules(
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/api/v1/biblios.t (-2 / +2 lines)
Lines 686-693 subtest 'get_checkouts() tests' => sub { Link Here
686
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
686
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
687
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
687
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
688
688
689
    AddIssue( $patron->unblessed, $item_1->barcode );
689
    AddIssue( $patron, $item_1->barcode );
690
    AddIssue( $patron->unblessed, $item_2->barcode );
690
    AddIssue( $patron, $item_2->barcode );
691
691
692
    my $ret = $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts")
692
    my $ret = $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts")
693
      ->status_is(200)
693
      ->status_is(200)
(-)a/t/db_dependent/api/v1/checkouts.t (-4 / +4 lines)
Lines 89-101 my $item3 = $builder->build_sample_item; Link Here
89
my $item4 = $builder->build_sample_item;
89
my $item4 = $builder->build_sample_item;
90
90
91
my $date_due = DateTime->now->add(weeks => 2);
91
my $date_due = DateTime->now->add(weeks => 2);
92
my $issue1 = C4::Circulation::AddIssue($patron->unblessed, $item1->barcode, $date_due);
92
my $issue1 = C4::Circulation::AddIssue($patron, $item1->barcode, $date_due);
93
my $date_due1 = Koha::DateUtils::dt_from_string( $issue1->date_due );
93
my $date_due1 = Koha::DateUtils::dt_from_string( $issue1->date_due );
94
my $issue2 = C4::Circulation::AddIssue($patron->unblessed, $item2->barcode, $date_due);
94
my $issue2 = C4::Circulation::AddIssue($patron, $item2->barcode, $date_due);
95
my $date_due2 = Koha::DateUtils::dt_from_string( $issue2->date_due );
95
my $date_due2 = Koha::DateUtils::dt_from_string( $issue2->date_due );
96
my $issue3 = C4::Circulation::AddIssue($librarian->unblessed, $item3->barcode, $date_due);
96
my $issue3 = C4::Circulation::AddIssue($librarian, $item3->barcode, $date_due);
97
my $date_due3 = Koha::DateUtils::dt_from_string( $issue3->date_due );
97
my $date_due3 = Koha::DateUtils::dt_from_string( $issue3->date_due );
98
my $issue4 = C4::Circulation::AddIssue($patron->unblessed, $item4->barcode);
98
my $issue4 = C4::Circulation::AddIssue($patron, $item4->barcode);
99
C4::Circulation::AddReturn($item4->barcode, $branchcode);
99
C4::Circulation::AddReturn($item4->barcode, $branchcode);
100
100
101
$t->get_ok( "//$userid:$password@/api/v1/checkouts?patron_id=$patron_id" )
101
$t->get_ok( "//$userid:$password@/api/v1/checkouts?patron_id=$patron_id" )
(-)a/t/db_dependent/api/v1/return_claims.t (-4 / +4 lines)
Lines 62-68 subtest 'claim_returned() tests' => sub { Link Here
62
    t::lib::Mocks::mock_userenv({ branchcode => $librarian->branchcode });
62
    t::lib::Mocks::mock_userenv({ branchcode => $librarian->branchcode });
63
63
64
    my $item  = $builder->build_sample_item;
64
    my $item  = $builder->build_sample_item;
65
    my $issue = AddIssue( $patron->unblessed, $item->barcode, dt_from_string->add( weeks => 2 ) );
65
    my $issue = AddIssue( $patron, $item->barcode, dt_from_string->add( weeks => 2 ) );
66
66
67
    t::lib::Mocks::mock_preference( 'ClaimReturnedChargeFee', 'ask' );
67
    t::lib::Mocks::mock_preference( 'ClaimReturnedChargeFee', 'ask' );
68
    t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', '99' );
68
    t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', '99' );
Lines 131-137 subtest 'update_notes() tests' => sub { Link Here
131
    t::lib::Mocks::mock_userenv( { branchcode => $item->homebranch } )
131
    t::lib::Mocks::mock_userenv( { branchcode => $item->homebranch } )
132
      ;    # needed by AddIssue
132
      ;    # needed by AddIssue
133
133
134
    my $issue = AddIssue( $librarian->unblessed, $item->barcode,
134
    my $issue = AddIssue( $librarian, $item->barcode,
135
        dt_from_string->add( weeks => 2 ) );
135
        dt_from_string->add( weeks => 2 ) );
136
136
137
    my $claim = $issue->claim_returned(
137
    my $claim = $issue->claim_returned(
Lines 197-203 subtest 'resolve_claim() tests' => sub { Link Here
197
    my $ClaimReturnedLostValue = 1;
197
    my $ClaimReturnedLostValue = 1;
198
    t::lib::Mocks::mock_preference('ClaimReturnedLostValue', $ClaimReturnedLostValue);
198
    t::lib::Mocks::mock_preference('ClaimReturnedLostValue', $ClaimReturnedLostValue);
199
199
200
    my $issue = AddIssue( $librarian->unblessed, $item->barcode, dt_from_string->add( weeks => 2 ) );
200
    my $issue = AddIssue( $librarian, $item->barcode, dt_from_string->add( weeks => 2 ) );
201
201
202
    my $claim = $issue->claim_returned(
202
    my $claim = $issue->claim_returned(
203
        {
203
        {
Lines 278-284 subtest 'delete() tests' => sub { Link Here
278
278
279
    t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch });
279
    t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch });
280
280
281
    my $issue = C4::Circulation::AddIssue( $librarian->unblessed,
281
    my $issue = C4::Circulation::AddIssue( $librarian,
282
        $item->barcode, dt_from_string->add( weeks => 2 ) );
282
        $item->barcode, dt_from_string->add( weeks => 2 ) );
283
283
284
    my $claim = $issue->claim_returned(
284
    my $claim = $issue->claim_returned(
(-)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 32496