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

(-)a/C4/Circulation.pm (-78 / +71 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 793-802 sub CanBookBeIssued { Link Here
793
    my $dbh             = C4::Context->dbh;
789
    my $dbh             = C4::Context->dbh;
794
    my $patron_unblessed = $patron->unblessed;
790
    my $patron_unblessed = $patron->unblessed;
795
791
796
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_unblessed, $patron_unblessed) );
792
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_object, $patron) );
797
793
798
    my $now = dt_from_string();
794
    my $now = dt_from_string();
799
    $duedate ||= CalcDateDue( $now, $effective_itemtype, $circ_library->branchcode, $patron_unblessed );
795
    $duedate ||= CalcDateDue( $now, $effective_itemtype, $circ_library->branchcode, $patron );
800
    if (DateTime->compare($duedate,$now) == -1 ) { # duedate cannot be before now
796
    if (DateTime->compare($duedate,$now) == -1 ) { # duedate cannot be before now
801
         $needsconfirmation{INVALID_DATE} = $duedate;
797
         $needsconfirmation{INVALID_DATE} = $duedate;
802
    }
798
    }
Lines 1003-1009 sub CanBookBeIssued { Link Here
1003
      and $issue
999
      and $issue
1004
      and $issue->onsite_checkout
1000
      and $issue->onsite_checkout
1005
      and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
1001
      and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
1006
    my $toomany = TooMany( $patron_unblessed, $item_object, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
1002
    my $toomany = TooMany( $patron, $item_object, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
1007
    # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
1003
    # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
1008
    if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) {
1004
    if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) {
1009
        if ( $toomany->{max_allowed} == 0 ) {
1005
        if ( $toomany->{max_allowed} == 0 ) {
Lines 1343-1349 sub CanBookBeReturned { Link Here
1343
1339
1344
sub checkHighHolds {
1340
sub checkHighHolds {
1345
    my ( $item, $patron ) = @_;
1341
    my ( $item, $patron ) = @_;
1346
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
1342
    my $branchcode = _GetCircControlBranch( $item, $patron );
1347
1343
1348
    my $return_data = {
1344
    my $return_data = {
1349
        exceeded    => 0,
1345
        exceeded    => 0,
Lines 1417-1423 sub checkHighHolds { Link Here
1417
        );
1413
        );
1418
        my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
1414
        my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
1419
1415
1420
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron->unblessed );
1416
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron );
1421
1417
1422
        my $rule = Koha::CirculationRules->get_effective_rule_value(
1418
        my $rule = Koha::CirculationRules->get_effective_rule_value(
1423
            {
1419
            {
Lines 1452-1464 sub checkHighHolds { Link Here
1452
1448
1453
=head2 AddIssue
1449
=head2 AddIssue
1454
1450
1455
  &AddIssue($borrower, $barcode, [$datedue], [$cancelreserve], [$issuedate])
1451
  &AddIssue($patron, $barcode, [$datedue], [$cancelreserve], [$issuedate])
1456
1452
1457
Issue a book. Does no check, they are done in CanBookBeIssued. If we reach this sub, it means the user confirmed if needed.
1453
Issue a book. Does no check, they are done in CanBookBeIssued. If we reach this sub, it means the user confirmed if needed.
1458
1454
1459
=over 4
1455
=over 4
1460
1456
1461
=item C<$borrower> is a hash with borrower informations (from Koha::Patron->unblessed).
1457
=item C<$patron> is a patron object.
1462
1458
1463
=item C<$barcode> is the barcode of the item being issued.
1459
=item C<$barcode> is the barcode of the item being issued.
1464
1460
Lines 1493-1499 AddIssue does the following things : Link Here
1493
=cut
1489
=cut
1494
1490
1495
sub AddIssue {
1491
sub AddIssue {
1496
    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode, $params ) = @_;
1492
    my ( $patron, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode, $params ) = @_;
1497
1493
1498
    my $onsite_checkout = $params && $params->{onsite_checkout} ? 1 : 0;
1494
    my $onsite_checkout = $params && $params->{onsite_checkout} ? 1 : 0;
1499
    my $switch_onsite_checkout = $params && $params->{switch_onsite_checkout};
1495
    my $switch_onsite_checkout = $params && $params->{switch_onsite_checkout};
Lines 1521-1542 sub AddIssue { Link Here
1521
    }
1517
    }
1522
1518
1523
    # Stop here if the patron or barcode doesn't exist
1519
    # Stop here if the patron or barcode doesn't exist
1524
    if ( $borrower && $barcode && $barcodecheck ) {
1520
    if ( $patron && $barcode && $barcodecheck ) {
1525
        # find which item we issue
1521
        # find which item we issue
1526
        my $item_object = Koha::Items->find({ barcode => $barcode })
1522
        my $item_object = Koha::Items->find({ barcode => $barcode })
1527
          or return;    # if we don't get an Item, abort.
1523
          or return;    # if we don't get an Item, abort.
1528
        my $item_unblessed = $item_object->unblessed;
1524
        my $item_unblessed = $item_object->unblessed;
1529
1525
1530
        my $branchcode = _GetCircControlBranch( $item_unblessed, $borrower );
1526
        my $branchcode = _GetCircControlBranch( $item_object, $patron );
1531
1527
1532
        # get actual issuing if there is one
1528
        # get actual issuing if there is one
1533
        my $actualissue = $item_object->checkout;
1529
        my $actualissue = $item_object->checkout;
1534
1530
1535
        # check if we just renew the issue.
1531
        # check if we just renew the issue.
1536
        if ( $actualissue and $actualissue->borrowernumber eq $borrower->{'borrowernumber'}
1532
        if ( $actualissue and $actualissue->borrowernumber eq $patron->borrowernumber
1537
                and not $switch_onsite_checkout ) {
1533
                and not $switch_onsite_checkout ) {
1538
            $datedue = AddRenewal(
1534
            $datedue = AddRenewal(
1539
                $borrower->{'borrowernumber'},
1535
                $patron->borrowernumber,
1540
                $item_object->itemnumber,
1536
                $item_object->itemnumber,
1541
                $branchcode,
1537
                $branchcode,
1542
                $datedue,
1538
                $datedue,
Lines 1547-1553 sub AddIssue { Link Here
1547
1543
1548
            unless ($datedue) {
1544
            unless ($datedue) {
1549
                my $itype = $item_object->effective_itemtype;
1545
                my $itype = $item_object->effective_itemtype;
1550
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1546
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $patron );
1551
1547
1552
            }
1548
            }
1553
1549
Lines 1556-1562 sub AddIssue { Link Here
1556
                # Check if there is an ILL connected with the biblio of the item we are issuing
1552
                # Check if there is an ILL connected with the biblio of the item we are issuing
1557
                my $ill_request = Koha::Illrequests->search({
1553
                my $ill_request = Koha::Illrequests->search({
1558
                    biblio_id => $item_object->biblionumber,
1554
                    biblio_id => $item_object->biblionumber,
1559
                    borrowernumber => $borrower->{'borrowernumber'},
1555
                    borrowernumber => $patron->borrowernumber,
1560
                    completed => undef,
1556
                    completed => undef,
1561
                    due_date => { '!=', undef },
1557
                    due_date => { '!=', undef },
1562
                })->next;
1558
                })->next;
Lines 1571-1577 sub AddIssue { Link Here
1571
1567
1572
            $datedue->truncate( to => 'minute' );
1568
            $datedue->truncate( to => 'minute' );
1573
1569
1574
            my $patron = Koha::Patrons->find( $borrower );
1575
            my $library = Koha::Libraries->find( $branchcode );
1570
            my $library = Koha::Libraries->find( $branchcode );
1576
            my $fees = Koha::Charges::Fees->new(
1571
            my $fees = Koha::Charges::Fees->new(
1577
                {
1572
                {
Lines 1599-1610 sub AddIssue { Link Here
1599
                        action         => $cancel_recall,
1594
                        action         => $cancel_recall,
1600
                        recall_id      => $recall_id,
1595
                        recall_id      => $recall_id,
1601
                        item           => $item_object,
1596
                        item           => $item_object,
1602
                        borrowernumber => $borrower->{borrowernumber},
1597
                        borrowernumber => $patron->borrowernumber,
1603
                    }
1598
                    }
1604
                );
1599
                );
1605
            }
1600
            }
1606
1601
1607
            C4::Reserves::MoveReserve( $item_object->itemnumber, $borrower->{'borrowernumber'}, $cancelreserve );
1602
            C4::Reserves::MoveReserve( $item_object->itemnumber, $patron->borrowernumber, $cancelreserve );
1608
1603
1609
            # Starting process for transfer job (checking transfert and validate it if we have one)
1604
            # Starting process for transfer job (checking transfert and validate it if we have one)
1610
            if ( my $transfer = $item_object->get_transfer ) {
1605
            if ( my $transfer = $item_object->get_transfer ) {
Lines 1629-1635 sub AddIssue { Link Here
1629
            unless ($auto_renew) {
1624
            unless ($auto_renew) {
1630
                my $rule = Koha::CirculationRules->get_effective_rule_value(
1625
                my $rule = Koha::CirculationRules->get_effective_rule_value(
1631
                    {
1626
                    {
1632
                        categorycode => $borrower->{categorycode},
1627
                        categorycode => $patron->categorycode,
1633
                        itemtype     => $item_object->effective_itemtype,
1628
                        itemtype     => $item_object->effective_itemtype,
1634
                        branchcode   => $branchcode,
1629
                        branchcode   => $branchcode,
1635
                        rule_name    => 'auto_renew'
1630
                        rule_name    => 'auto_renew'
Lines 1640-1646 sub AddIssue { Link Here
1640
            }
1635
            }
1641
1636
1642
            my $issue_attributes = {
1637
            my $issue_attributes = {
1643
                borrowernumber  => $borrower->{'borrowernumber'},
1638
                borrowernumber  => $patron->borrowernumber,
1644
                issuedate       => $issuedate,
1639
                issuedate       => $issuedate,
1645
                date_due        => $datedue,
1640
                date_due        => $datedue,
1646
                branchcode      => C4::Context->userenv->{'branch'},
1641
                branchcode      => C4::Context->userenv->{'branch'},
Lines 1674-1680 sub AddIssue { Link Here
1674
                )->store;
1669
                )->store;
1675
            }
1670
            }
1676
            $issue->discard_changes;
1671
            $issue->discard_changes;
1677
            C4::Auth::track_login_daily( $borrower->{userid} );
1672
            C4::Auth::track_login_daily( $patron->userid );
1678
            if ( $item_object->location && $item_object->location eq 'CART'
1673
            if ( $item_object->location && $item_object->location eq 'CART'
1679
                && ( !$item_object->permanent_location || $item_object->permanent_location ne 'CART' ) ) {
1674
                && ( !$item_object->permanent_location || $item_object->permanent_location ne 'CART' ) ) {
1680
            ## Item was moved to cart via UpdateItemLocationOnCheckin, anything issued should be taken off the cart.
1675
            ## Item was moved to cart via UpdateItemLocationOnCheckin, anything issued should be taken off the cart.
Lines 1700-1730 sub AddIssue { Link Here
1700
            if ($was_lost) {
1695
            if ($was_lost) {
1701
                if ( $item_object->{_charge} ) {
1696
                if ( $item_object->{_charge} ) {
1702
                    $actualissue //= Koha::Old::Checkouts->search(
1697
                    $actualissue //= Koha::Old::Checkouts->search(
1703
                        { itemnumber => $item_unblessed->{itemnumber} },
1698
                        { itemnumber => $item_object->itemnumber },
1704
                        {
1699
                        {
1705
                            order_by => { '-desc' => 'returndate' },
1700
                            order_by => { '-desc' => 'returndate' },
1706
                            rows     => 1
1701
                            rows     => 1
1707
                        }
1702
                        }
1708
                    )->single;
1703
                    )->single;
1709
                    unless ( exists( $borrower->{branchcode} ) ) {
1704
                    unless ( $patron->branchcode ) {
1710
                        my $patron = $actualissue->patron;
1705
                        $patron = $actualissue->patron;
1711
                        $borrower = $patron->unblessed;
1712
                    }
1706
                    }
1713
                    _CalculateAndUpdateFine(
1707
                    _CalculateAndUpdateFine(
1714
                        {
1708
                        {
1715
                            issue       => $actualissue,
1709
                            issue       => $actualissue,
1716
                            item        => $item_unblessed,
1710
                            item        => $item_unblessed,
1717
                            borrower    => $borrower,
1711
                            borrower    => $patron->unblessed,
1718
                            return_date => $issuedate
1712
                            return_date => $issuedate
1719
                        }
1713
                        }
1720
                    );
1714
                    );
1721
                    _FixOverduesOnReturn( $borrower->{borrowernumber},
1715
                    _FixOverduesOnReturn( $patron->borrowernumber,
1722
                        $item_object->itemnumber, undef, 'RENEWED' );
1716
                        $item_object->itemnumber, undef, 'RENEWED' );
1723
                }
1717
                }
1724
            }
1718
            }
1725
1719
1726
            # If it costs to borrow this book, charge it to the patron's account.
1720
            # If it costs to borrow this book, charge it to the patron's account.
1727
            my ( $charge, $itemtype ) = GetIssuingCharges( $item_object->itemnumber, $borrower->{'borrowernumber'} );
1721
            my ( $charge, $itemtype ) = GetIssuingCharges( $item_object->itemnumber, $patron->borrowernumber );
1728
            if ( $charge && $charge > 0 ) {
1722
            if ( $charge && $charge > 0 ) {
1729
                AddIssuingCharge( $issue, $charge, 'RENT' );
1723
                AddIssuingCharge( $issue, $charge, 'RENT' );
1730
            }
1724
            }
Lines 1749-1757 sub AddIssue { Link Here
1749
                    itemnumber     => $item_object->itemnumber,
1743
                    itemnumber     => $item_object->itemnumber,
1750
                    itemtype       => $item_object->effective_itemtype,
1744
                    itemtype       => $item_object->effective_itemtype,
1751
                    location       => $item_object->location,
1745
                    location       => $item_object->location,
1752
                    borrowernumber => $borrower->{'borrowernumber'},
1746
                    borrowernumber => $patron->borrowernumber,
1753
                    ccode          => $item_object->ccode,
1747
                    ccode          => $item_object->ccode,
1754
                    categorycode   => $borrower->{'categorycode'}
1748
                    categorycode   => $patron->categorycode
1755
                }
1749
                }
1756
            );
1750
            );
1757
1751
Lines 1759-1765 sub AddIssue { Link Here
1759
            my $circulation_alert = 'C4::ItemCirculationAlertPreference';
1753
            my $circulation_alert = 'C4::ItemCirculationAlertPreference';
1760
            my %conditions        = (
1754
            my %conditions        = (
1761
                branchcode   => $branchcode,
1755
                branchcode   => $branchcode,
1762
                categorycode => $borrower->{categorycode},
1756
                categorycode => $patron->categorycode,
1763
                item_type    => $item_object->effective_itemtype,
1757
                item_type    => $item_object->effective_itemtype,
1764
                notification => 'CHECKOUT',
1758
                notification => 'CHECKOUT',
1765
            );
1759
            );
Lines 1768-1781 sub AddIssue { Link Here
1768
                    {
1762
                    {
1769
                        type     => 'CHECKOUT',
1763
                        type     => 'CHECKOUT',
1770
                        item     => $item_object->unblessed,
1764
                        item     => $item_object->unblessed,
1771
                        borrower => $borrower,
1765
                        borrower => $patron->unblessed,
1772
                        branch   => $branchcode,
1766
                        branch   => $branchcode,
1773
                    }
1767
                    }
1774
                );
1768
                );
1775
            }
1769
            }
1776
            logaction(
1770
            logaction(
1777
                "CIRCULATION", "ISSUE",
1771
                "CIRCULATION", "ISSUE",
1778
                $borrower->{'borrowernumber'},
1772
                $patron->borrowernumber,
1779
                $item_object->itemnumber,
1773
                $item_object->itemnumber,
1780
            ) if C4::Context->preference("IssueLog");
1774
            ) if C4::Context->preference("IssueLog");
1781
1775
Lines 2298-2304 sub AddReturn { Link Here
2298
2292
2299
        if ( $issue and $issue->is_overdue($return_date) ) {
2293
        if ( $issue and $issue->is_overdue($return_date) ) {
2300
        # fix fine days
2294
        # fix fine days
2301
            my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item->unblessed, dt_from_string($issue->date_due), $return_date );
2295
            my ( $debardate, $reminder ) = _debar_user_on_return( $patron, $item, dt_from_string($issue->date_due), $return_date );
2302
            if ($reminder){
2296
            if ($reminder){
2303
                $messages->{'PrevDebarred'} = $debardate;
2297
                $messages->{'PrevDebarred'} = $debardate;
2304
            } else {
2298
            } else {
Lines 2553-2563 sub MarkIssueReturned { Link Here
2553
2547
2554
=head2 _debar_user_on_return
2548
=head2 _debar_user_on_return
2555
2549
2556
    _debar_user_on_return($borrower, $item, $datedue, $returndate);
2550
    _debar_user_on_return($patron, $item, $datedue, $returndate);
2557
2551
2558
C<$borrower> borrower hashref
2552
C<$patron> patron object
2559
2553
2560
C<$item> item hashref
2554
C<$item> patron object
2561
2555
2562
C<$datedue> date due DateTime object
2556
C<$datedue> date due DateTime object
2563
2557
Lines 2574-2586 to ease testing. Link Here
2574
=cut
2568
=cut
2575
2569
2576
sub _calculate_new_debar_dt {
2570
sub _calculate_new_debar_dt {
2577
    my ( $borrower, $item, $dt_due, $return_date ) = @_;
2571
    my ( $patron, $item, $dt_due, $return_date ) = @_;
2578
2572
2579
    my $branchcode = _GetCircControlBranch( $item, $borrower );
2573
    my $branchcode = _GetCircControlBranch( $item, $patron );
2580
    my $circcontrol = C4::Context->preference('CircControl');
2574
    my $circcontrol = C4::Context->preference('CircControl');
2581
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2575
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2582
        {   categorycode => $borrower->{categorycode},
2576
        {   categorycode => $patron->categorycode,
2583
            itemtype     => $item->{itype},
2577
            itemtype     => $item->effective_itemtype,
2584
            branchcode   => $branchcode,
2578
            branchcode   => $branchcode,
2585
            rules => [
2579
            rules => [
2586
                'finedays',
2580
                'finedays',
Lines 2629-2636 sub _calculate_new_debar_dt { Link Here
2629
        }
2623
        }
2630
2624
2631
        my ( $has_been_extended );
2625
        my ( $has_been_extended );
2632
        if ( C4::Context->preference('CumulativeRestrictionPeriods') and $borrower->{debarred} ) {
2626
        if ( C4::Context->preference('CumulativeRestrictionPeriods') and $patron->is_debarred ) {
2633
            my $debarment = @{ GetDebarments( { borrowernumber => $borrower->{borrowernumber}, type => 'SUSPENSION' } ) }[0];
2627
            my $debarment = @{ GetDebarments( { borrowernumber => $patron->borrowernumber, type => 'SUSPENSION' } ) }[0];
2634
            if ( $debarment ) {
2628
            if ( $debarment ) {
2635
                $return_date = dt_from_string( $debarment->{expiration}, 'sql' );
2629
                $return_date = dt_from_string( $debarment->{expiration}, 'sql' );
2636
                $has_been_extended = 1;
2630
                $has_been_extended = 1;
Lines 2655-2679 sub _calculate_new_debar_dt { Link Here
2655
}
2649
}
2656
2650
2657
sub _debar_user_on_return {
2651
sub _debar_user_on_return {
2658
    my ( $borrower, $item, $dt_due, $return_date ) = @_;
2652
    my ( $patron, $item, $dt_due, $return_date ) = @_;
2659
2653
2660
    $return_date //= dt_from_string();
2654
    $return_date //= dt_from_string();
2661
2655
2662
    my $new_debar_dt = _calculate_new_debar_dt ($borrower, $item, $dt_due, $return_date);
2656
    my $new_debar_dt = _calculate_new_debar_dt($patron, $item, $dt_due, $return_date);
2663
2657
2664
    return unless $new_debar_dt;
2658
    return unless $new_debar_dt;
2665
2659
2666
    Koha::Patron::Debarments::AddUniqueDebarment({
2660
    Koha::Patron::Debarments::AddUniqueDebarment({
2667
        borrowernumber => $borrower->{borrowernumber},
2661
        borrowernumber => $patron->borrowernumber,
2668
        expiration     => $new_debar_dt->ymd(),
2662
        expiration     => $new_debar_dt->ymd(),
2669
        type           => 'SUSPENSION',
2663
        type           => 'SUSPENSION',
2670
    });
2664
    });
2671
    # if borrower was already debarred but does not get an extra debarment
2665
    # if borrower was already debarred but does not get an extra debarment
2672
    my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
2673
    my ($new_debarment_str, $is_a_reminder);
2666
    my ($new_debarment_str, $is_a_reminder);
2674
    if ( $borrower->{debarred} && $borrower->{debarred} eq $patron->is_debarred ) {
2667
    if ( $patron->is_debarred ) {
2675
        $is_a_reminder = 1;
2668
        $is_a_reminder = 1;
2676
        $new_debarment_str = $borrower->{debarred};
2669
        $new_debarment_str = $patron->debarred;
2677
    } else {
2670
    } else {
2678
        $new_debarment_str = $new_debar_dt->ymd();
2671
        $new_debarment_str = $new_debar_dt->ymd();
2679
    }
2672
    }
Lines 2764-2799 sub _FixOverduesOnReturn { Link Here
2764
2757
2765
=head2 _GetCircControlBranch
2758
=head2 _GetCircControlBranch
2766
2759
2767
   my $circ_control_branch = _GetCircControlBranch($iteminfos, $borrower);
2760
   my $circ_control_branch = _GetCircControlBranch($item, $patron);
2768
2761
2769
Internal function : 
2762
Internal function :
2770
2763
2771
Return the library code to be used to determine which circulation
2764
Return the library code to be used to determine which circulation
2772
policy applies to a transaction.  Looks up the CircControl and
2765
policy applies to a transaction.  Looks up the CircControl and
2773
HomeOrHoldingBranch system preferences.
2766
HomeOrHoldingBranch system preferences.
2774
2767
2775
C<$iteminfos> is a hashref to iteminfo. Only {homebranch or holdingbranch} is used.
2768
C<$item> is an item object.
2776
2769
2777
C<$borrower> is a hashref to borrower. Only {branchcode} is used.
2770
C<$patron> is a patron object.
2778
2771
2779
=cut
2772
=cut
2780
2773
2781
sub _GetCircControlBranch {
2774
sub _GetCircControlBranch {
2782
    my ($item, $borrower) = @_;
2775
    my ($item, $patron) = @_;
2783
    my $circcontrol = C4::Context->preference('CircControl');
2776
    my $circcontrol = C4::Context->preference('CircControl');
2784
    my $branch;
2777
    my $branch;
2785
2778
2786
    if ($circcontrol eq 'PickupLibrary' and (C4::Context->userenv and C4::Context->userenv->{'branch'}) ) {
2779
    if ($circcontrol eq 'PickupLibrary' and (C4::Context->userenv and C4::Context->userenv->{'branch'}) ) {
2787
        $branch= C4::Context->userenv->{'branch'};
2780
        $branch = C4::Context->userenv->{'branch'};
2788
    } elsif ($circcontrol eq 'PatronLibrary') {
2781
    } elsif ($circcontrol eq 'PatronLibrary') {
2789
        $branch=$borrower->{branchcode};
2782
        $branch = $patron->branchcode;
2790
    } else {
2783
    } else {
2791
        my $branchfield = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch';
2784
        my $branchfield = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch';
2792
        $branch = $item->{$branchfield};
2785
        $branch = $item->get_column($branchfield);
2793
        # default to item home branch if holdingbranch is used
2786
        # default to item home branch if holdingbranch is used
2794
        # and is not defined
2787
        # and is not defined
2795
        if (!defined($branch) && $branchfield eq 'holdingbranch') {
2788
        if (!defined($branch) && $branchfield eq 'holdingbranch') {
2796
            $branch = $item->{homebranch};
2789
            $branch = $item->homebranch;
2797
        }
2790
        }
2798
    }
2791
    }
2799
    return $branch;
2792
    return $branch;
Lines 2869-2875 sub CanBookBeRenewed { Link Here
2869
2862
2870
       # override_limit will override anything else except on_reserve
2863
       # override_limit will override anything else except on_reserve
2871
    unless ( $override_limit ){
2864
    unless ( $override_limit ){
2872
        my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
2865
        my $branchcode = _GetCircControlBranch( $item, $patron );
2873
        my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2866
        my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2874
            {
2867
            {
2875
                categorycode => $patron->categorycode,
2868
                categorycode => $patron->categorycode,
Lines 3059-3065 sub AddRenewal { Link Here
3059
    my $patron = Koha::Patrons->find( $borrowernumber ) or return; # FIXME Should do more than just return
3052
    my $patron = Koha::Patrons->find( $borrowernumber ) or return; # FIXME Should do more than just return
3060
    my $patron_unblessed = $patron->unblessed;
3053
    my $patron_unblessed = $patron->unblessed;
3061
3054
3062
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_unblessed, $patron_unblessed) );
3055
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_object, $patron) );
3063
3056
3064
    my $schema = Koha::Database->schema;
3057
    my $schema = Koha::Database->schema;
3065
    $schema->txn_do(sub{
3058
    $schema->txn_do(sub{
Lines 3078-3084 sub AddRenewal { Link Here
3078
            $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
3071
            $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
3079
                                            dt_from_string( $issue->date_due, 'sql' ) :
3072
                                            dt_from_string( $issue->date_due, 'sql' ) :
3080
                                            dt_from_string();
3073
                                            dt_from_string();
3081
            $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, 'is a renewal');
3074
            $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron, 'is a renewal');
3082
        }
3075
        }
3083
3076
3084
        my $fees = Koha::Charges::Fees->new(
3077
        my $fees = Koha::Charges::Fees->new(
Lines 3247-3253 sub GetRenewCount { Link Here
3247
    $renewcount = $data->{'renewals_count'} if $data->{'renewals_count'};
3240
    $renewcount = $data->{'renewals_count'} if $data->{'renewals_count'};
3248
    $unseencount = $data->{'unseen_renewals'} if $data->{'unseen_renewals'};
3241
    $unseencount = $data->{'unseen_renewals'} if $data->{'unseen_renewals'};
3249
    # $item and $borrower should be calculated
3242
    # $item and $borrower should be calculated
3250
    my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed);
3243
    my $branchcode = _GetCircControlBranch($item, $patron);
3251
3244
3252
    my $rules = Koha::CirculationRules->get_effective_rules(
3245
    my $rules = Koha::CirculationRules->get_effective_rules(
3253
        {
3246
        {
Lines 3303-3309 sub GetSoonestRenewDate { Link Here
3303
3296
3304
    my $dbh = C4::Context->dbh;
3297
    my $dbh = C4::Context->dbh;
3305
3298
3306
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
3299
    my $branchcode = _GetCircControlBranch( $item, $patron );
3307
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
3300
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
3308
        {   categorycode => $patron->categorycode,
3301
        {   categorycode => $patron->categorycode,
3309
            itemtype     => $item->effective_itemtype,
3302
            itemtype     => $item->effective_itemtype,
Lines 3370-3377 sub GetLatestAutoRenewDate { Link Here
3370
    return unless $item;
3363
    return unless $item;
3371
3364
3372
    my $dbh = C4::Context->dbh;
3365
    my $dbh = C4::Context->dbh;
3373
3374
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
3366
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
3367
3375
    my $circulation_rules = Koha::CirculationRules->get_effective_rules(
3368
    my $circulation_rules = Koha::CirculationRules->get_effective_rules(
3376
        {
3369
        {
3377
            categorycode => $patron->categorycode,
3370
            categorycode => $patron->categorycode,
Lines 3667-3685 checking against the holidays calendar as per the daysmode circulation rule. Link Here
3667
C<$startdate>   = DateTime object representing start date of loan period (assumed to be today)
3660
C<$startdate>   = DateTime object representing start date of loan period (assumed to be today)
3668
C<$itemtype>  = itemtype code of item in question
3661
C<$itemtype>  = itemtype code of item in question
3669
C<$branch>  = location whose calendar to use
3662
C<$branch>  = location whose calendar to use
3670
C<$borrower> = Borrower object
3663
C<$patron> = Patron object
3671
C<$isrenewal> = Boolean: is true if we want to calculate the date due for a renewal. Else is false.
3664
C<$isrenewal> = Boolean: is true if we want to calculate the date due for a renewal. Else is false.
3672
3665
3673
=cut
3666
=cut
3674
3667
3675
sub CalcDateDue {
3668
sub CalcDateDue {
3676
    my ( $startdate, $itemtype, $branch, $borrower, $isrenewal ) = @_;
3669
    my ( $startdate, $itemtype, $branch, $patron, $isrenewal ) = @_;
3677
3670
3678
    $isrenewal ||= 0;
3671
    $isrenewal ||= 0;
3679
3672
3680
    # loanlength now a href
3673
    # loanlength now a href
3681
    my $loanlength =
3674
    my $loanlength =
3682
            GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch );
3675
            GetLoanLength( $patron->categorycode, $itemtype, $branch );
3683
3676
3684
    my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} and $loanlength->{renewalperiod} ne q{} )
3677
    my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} and $loanlength->{renewalperiod} ne q{} )
3685
            ? qq{renewalperiod}
3678
            ? qq{renewalperiod}
Lines 3699-3705 sub CalcDateDue { Link Here
3699
3692
3700
    my $daysmode = Koha::CirculationRules->get_effective_daysmode(
3693
    my $daysmode = Koha::CirculationRules->get_effective_daysmode(
3701
        {
3694
        {
3702
            categorycode => $borrower->{categorycode},
3695
            categorycode => $patron->categorycode,
3703
            itemtype     => $itemtype,
3696
            itemtype     => $itemtype,
3704
            branchcode   => $branch,
3697
            branchcode   => $branch,
3705
        }
3698
        }
Lines 3733-3739 sub CalcDateDue { Link Here
3733
3726
3734
    # if Hard Due Dates are used, retrieve them and apply as necessary
3727
    # if Hard Due Dates are used, retrieve them and apply as necessary
3735
    my ( $hardduedate, $hardduedatecompare ) =
3728
    my ( $hardduedate, $hardduedatecompare ) =
3736
      GetHardDueDate( $borrower->{'categorycode'}, $itemtype, $branch );
3729
      GetHardDueDate( $patron->categorycode, $itemtype, $branch );
3737
    if ($hardduedate) {    # hardduedates are currently dates
3730
    if ($hardduedate) {    # hardduedates are currently dates
3738
        $hardduedate->truncate( to => 'minute' );
3731
        $hardduedate->truncate( to => 'minute' );
3739
        $hardduedate->set_hour(23);
3732
        $hardduedate->set_hour(23);
Lines 3753-3759 sub CalcDateDue { Link Here
3753
3746
3754
    # if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate
3747
    # if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate
3755
    if ( C4::Context->preference('ReturnBeforeExpiry') ) {
3748
    if ( C4::Context->preference('ReturnBeforeExpiry') ) {
3756
        my $expiry_dt = dt_from_string( $borrower->{dateexpiry}, 'iso', 'floating');
3749
        my $expiry_dt = dt_from_string( $patron->dateexpiry, 'iso', 'floating');
3757
        if( $expiry_dt ) { #skip empty expiry date..
3750
        if( $expiry_dt ) { #skip empty expiry date..
3758
            $expiry_dt->set( hour => 23, minute => 59);
3751
            $expiry_dt->set( hour => 23, minute => 59);
3759
            my $d1= $datedue->clone->set_time_zone('floating');
3752
            my $d1= $datedue->clone->set_time_zone('floating');
Lines 4037-4043 sub ProcessOfflineIssue { Link Here
4037
            );
4030
            );
4038
        }
4031
        }
4039
        AddIssue(
4032
        AddIssue(
4040
            $patron->unblessed,
4033
            $patron,
4041
            $operation->{'barcode'},
4034
            $operation->{'barcode'},
4042
            undef,
4035
            undef,
4043
            undef,
4036
            undef,
(-)a/C4/SIP/ILS/Transaction/Checkout.pm (-1 / +1 lines)
Lines 141-147 sub do_checkout { Link Here
141
        });
141
        });
142
    } else {
142
    } else {
143
        # can issue
143
        # can issue
144
        my $issue = AddIssue( $patron->unblessed, $barcode, $overridden_duedate, 0 );
144
        my $issue = AddIssue( $patron, $barcode, $overridden_duedate, 0 );
145
        $self->{due} = $self->duedatefromissue($issue, $itemnumber);
145
        $self->{due} = $self->duedatefromissue($issue, $itemnumber);
146
    }
146
    }
147
147
(-)a/C4/SIP/ILS/Transaction/Renew.pm (-1 / +1 lines)
Lines 46-52 sub do_renew_for { Link Here
46
46
47
    }
47
    }
48
    if ($renewokay){
48
    if ($renewokay){
49
        my $issue = AddIssue( $borrower, $self->{item}->id, undef, 0 );
49
        my $issue = AddIssue( $patron, $self->{item}->id, undef, 0 );
50
        $self->{due} = $self->duedatefromissue($issue, $self->{item}->{itemnumber});
50
        $self->{due} = $self->duedatefromissue($issue, $self->{item}->{itemnumber});
51
        $self->renewal_ok(1);
51
        $self->renewal_ok(1);
52
    } else {
52
    } else {
(-)a/Koha/CurbsidePickup.pm (-1 / +1 lines)
Lines 250-256 sub mark_as_delivered { Link Here
250
250
251
            unless ( keys %$issuingimpossible ) {
251
            unless ( keys %$issuingimpossible ) {
252
                my $issue =
252
                my $issue =
253
                  C4::Circulation::AddIssue( $patron->unblessed, $hold->item->barcode );
253
                  C4::Circulation::AddIssue( $patron, $hold->item->barcode );
254
                if ($issue) {
254
                if ($issue) {
255
                    Koha::CurbsidePickupIssue->new(
255
                    Koha::CurbsidePickupIssue->new(
256
                        {
256
                        {
(-)a/Koha/Illrequest.pm (-2 lines)
Lines 1320-1327 sub check_out { Link Here
1320
        }
1320
        }
1321
1321
1322
        # We can allegedly check out, so make it so
1322
        # We can allegedly check out, so make it so
1323
        # For some reason, AddIssue requires an unblessed Patron
1324
        $issue_args[0] = $patron->unblessed;
1325
        my $issue = C4::Circulation::AddIssue(@issue_args);
1323
        my $issue = C4::Circulation::AddIssue(@issue_args);
1326
1324
1327
        if ($issue) {
1325
        if ($issue) {
(-)a/Koha/Item.pm (-1 / +1 lines)
Lines 1869-1875 sub can_be_recalled { Link Here
1869
1869
1870
    my $branchcode = C4::Context->userenv->{'branch'};
1870
    my $branchcode = C4::Context->userenv->{'branch'};
1871
    if ( $patron ) {
1871
    if ( $patron ) {
1872
        $branchcode = C4::Circulation::_GetCircControlBranch( $self->unblessed, $patron->unblessed );
1872
        $branchcode = C4::Circulation::_GetCircControlBranch( $self, $patron );
1873
    }
1873
    }
1874
1874
1875
    # Check the circulation rule for each relevant itemtype for this item
1875
    # Check the circulation rule for each relevant itemtype for this item
(-)a/Koha/Recall.pm (-1 / +1 lines)
Lines 258-264 sub calc_expirationdate { Link Here
258
258
259
    my $branchcode = $self->patron->branchcode;
259
    my $branchcode = $self->patron->branchcode;
260
    if ( $item ) {
260
    if ( $item ) {
261
        $branchcode = C4::Circulation::_GetCircControlBranch( $item->unblessed, $self->patron->unblessed );
261
        $branchcode = C4::Circulation::_GetCircControlBranch( $item, $self->patron );
262
    }
262
    }
263
263
264
    my $rule = Koha::CirculationRules->get_effective_rule({
264
    my $rule = Koha::CirculationRules->get_effective_rule({
(-)a/circ/circulation.pl (-1 / +1 lines)
Lines 400-406 if (@$barcodes) { Link Here
400
                );
400
                );
401
                $recall_id = ( $recall and $recall->id ) ? $recall->id : undef;
401
                $recall_id = ( $recall and $recall->id ) ? $recall->id : undef;
402
            }
402
            }
403
            my $issue = AddIssue( $patron->unblessed, $barcode, $datedue, $cancelreserve, undef, undef, { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew'), switch_onsite_checkout => $switch_onsite_checkout, cancel_recall => $cancel_recall, recall_id => $recall_id, } );
403
            my $issue = AddIssue( $patron, $barcode, $datedue, $cancelreserve, undef, undef, { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew'), switch_onsite_checkout => $switch_onsite_checkout, cancel_recall => $cancel_recall, recall_id => $recall_id, } );
404
            $template_params->{issue} = $issue;
404
            $template_params->{issue} = $issue;
405
            $session->clear('auto_renew');
405
            $session->clear('auto_renew');
406
            $inprocess = 1;
406
            $inprocess = 1;
(-)a/offline_circ/process_koc.pl (-19 / +18 lines)
Lines 246-252 sub kocIssueItem { Link Here
246
246
247
    my $branchcode = C4::Context->userenv->{branch};
247
    my $branchcode = C4::Context->userenv->{branch};
248
    my $patron = Koha::Patrons->find( { cardnumber => $circ->{cardnumber} } );
248
    my $patron = Koha::Patrons->find( { cardnumber => $circ->{cardnumber} } );
249
    my $borrower = $patron->unblessed;
250
    my $item = Koha::Items->find({ barcode => $circ->{barcode} });
249
    my $item = Koha::Items->find({ barcode => $circ->{barcode} });
251
    my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
250
    my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
252
    my $biblio = $item->biblio;
251
    my $biblio = $item->biblio;
Lines 254-260 sub kocIssueItem { Link Here
254
    if ( $issue ) { ## Item is currently checked out to another person.
253
    if ( $issue ) { ## Item is currently checked out to another person.
255
        #warn "Item Currently Issued.";
254
        #warn "Item Currently Issued.";
256
255
257
        if ( $issue->borrowernumber eq $borrower->{'borrowernumber'} ) { ## Issued to this person already, renew it.
256
        if ( $issue->borrowernumber eq $patron->borrowernumber ) { ## Issued to this person already, renew it.
258
            #warn "Item issued to this member already, renewing.";
257
            #warn "Item issued to this member already, renewing.";
259
258
260
            C4::Circulation::AddRenewal(
259
            C4::Circulation::AddRenewal(
Lines 270-280 sub kocIssueItem { Link Here
270
                title => $biblio->title,
269
                title => $biblio->title,
271
                biblionumber => $biblio->biblionumber,
270
                biblionumber => $biblio->biblionumber,
272
                barcode => $item->barcode,
271
                barcode => $item->barcode,
273
                firstname => $borrower->{ 'firstname' },
272
                firstname => $patron->firstname,
274
                surname => $borrower->{ 'surname' },
273
                surname => $patron->surname,
275
                borrowernumber => $borrower->{'borrowernumber'},
274
                borrowernumber => $patron->borrowernumber,
276
                cardnumber => $borrower->{'cardnumber'},
275
                cardnumber => $patron->cardnumber,
277
                datetime => $circ->{ 'datetime' }
276
                datetime => $circ->datetime
278
            };
277
            };
279
278
280
        } else {
279
        } else {
Lines 285-301 sub kocIssueItem { Link Here
285
            my ( $c_y, $c_m, $c_d ) = split( /-/, $circ->{'date'} );
284
            my ( $c_y, $c_m, $c_d ) = split( /-/, $circ->{'date'} );
286
285
287
            if ( Date_to_Days( $i_y, $i_m, $i_d ) < Date_to_Days( $c_y, $c_m, $c_d ) ) { ## Current issue to a different persion is older than this issue, return and issue.
286
            if ( Date_to_Days( $i_y, $i_m, $i_d ) < Date_to_Days( $c_y, $c_m, $c_d ) ) { ## Current issue to a different persion is older than this issue, return and issue.
288
                C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
287
                C4::Circulation::AddIssue( $patron, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
289
                push @output, {
288
                push @output, {
290
                    issue => 1,
289
                    issue => 1,
291
                    title => $biblio->title,
290
                    title => $biblio->title,
292
                    biblionumber => $biblio->biblionumber,
291
                    biblionumber => $biblio->biblionumber,
293
                    barcode => $item->barcode,
292
                    barcode => $item->barcode,
294
                    firstname => $borrower->{ 'firstname' },
293
                    firstname => $patron->firstname,
295
                    surname => $borrower->{ 'surname' },
294
                    surname => $patron->surname,
296
                    borrowernumber => $borrower->{'borrowernumber'},
295
                    borrowernumber => $patron->borrowernumber,
297
                    cardnumber => $borrower->{'cardnumber'},
296
                    cardnumber => $patron->cardnumber,
298
                    datetime => $circ->{ 'datetime' }
297
                    datetime => $circ->datetime
299
                };
298
                };
300
299
301
            } else { ## Current issue is *newer* than this issue, write a 'returned' issue, as the item is most likely in the hands of someone else now.
300
            } else { ## Current issue is *newer* than this issue, write a 'returned' issue, as the item is most likely in the hands of someone else now.
Lines 305-321 sub kocIssueItem { Link Here
305
            }
304
            }
306
        }
305
        }
307
    } else { ## Item is not checked out to anyone at the moment, go ahead and issue it
306
    } else { ## Item is not checked out to anyone at the moment, go ahead and issue it
308
        C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
307
        C4::Circulation::AddIssue( $patron, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
309
        push @output, {
308
        push @output, {
310
            issue => 1,
309
            issue => 1,
311
            title => $biblio->title,
310
            title => $biblio->title,
312
            biblionumber => $biblio->biblionumber,
311
            biblionumber => $biblio->biblionumber,
313
            barcode => $item->barcode,
312
            barcode => $item->barcode,
314
            firstname => $borrower->{ 'firstname' },
313
            firstname => $patron->firstname,
315
            surname => $borrower->{ 'surname' },
314
            surname => $patron->surname,
316
            borrowernumber => $borrower->{'borrowernumber'},
315
            borrowernumber => $patron->borrowernumber,
317
            cardnumber => $borrower->{'cardnumber'},
316
            cardnumber => $patron->cardnumber,
318
            datetime =>$circ->{ 'datetime' }
317
            datetime =>$circ->datetime
319
        };
318
        };
320
    }
319
    }
321
}
320
}
(-)a/opac/sco/sco-main.pl (-1 / +1 lines)
Lines 245-251 elsif ( $patron && ( $op eq 'checkout' ) ) { Link Here
245
                )->count;
245
                )->count;
246
            }
246
            }
247
247
248
            AddIssue( $patron->unblessed, $barcode );
248
            AddIssue( $patron, $barcode );
249
            $template->param( issued => 1 );
249
            $template->param( issued => 1 );
250
            push @newissueslist, $barcode;
250
            push @newissueslist, $barcode;
251
251
(-)a/reserve/request.pl (-2 / +1 lines)
Lines 479-486 if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold ) Link Here
479
                }
479
                }
480
480
481
                if ( $patron ) {
481
                if ( $patron ) {
482
                    my $patron_unblessed = $patron->unblessed;
482
                    my $branch = _GetCircControlBranch($item_object, $patron);
483
                    my $branch = C4::Circulation::_GetCircControlBranch($item, $patron_unblessed);
484
483
485
                    my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
484
                    my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
486
485
(-)a/svc/letters/preview (-5 / +2 lines)
Lines 151-159 if ( $code eq 'CHECKIN' ) { Link Here
151
    my $checkout = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
151
    my $checkout = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
152
    if ($checkout) {
152
    if ($checkout) {
153
        my $patron = Koha::Patrons->find( $checkout->borrowernumber );
153
        my $patron = Koha::Patrons->find( $checkout->borrowernumber );
154
        my $branchcode =
154
        my $branchcode = C4::Circulation::_GetCircControlBranch( $item, $patron );
155
          C4::Circulation::_GetCircControlBranch( $item->unblessed,
156
            $patron->unblessed );
157
        $letter_params = {
155
        $letter_params = {
158
            tables => {
156
            tables => {
159
                issues      => $item->itemnumber,
157
                issues      => $item->itemnumber,
Lines 177-184 elsif ( $code eq 'CHECKOUT' ) { Link Here
177
    my $patron = Koha::Patrons->find( $borrowernumber );
175
    my $patron = Koha::Patrons->find( $borrowernumber );
178
    if ($item and $patron) {
176
    if ($item and $patron) {
179
        my $branchcode =
177
        my $branchcode =
180
          C4::Circulation::_GetCircControlBranch( $item->unblessed,
178
          C4::Circulation::_GetCircControlBranch( $item, $patron );
181
            $patron->unblessed );
182
        $letter_params = {
179
        $letter_params = {
183
            tables => {
180
            tables => {
184
                issues      => $item->itemnumber,
181
                issues      => $item->itemnumber,
(-)a/t/db_dependent/Circulation.t (-71 / +84 lines)
Lines 164-177 my $patron_category = $builder->build( Link Here
164
my $CircControl = C4::Context->preference('CircControl');
164
my $CircControl = C4::Context->preference('CircControl');
165
my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch');
165
my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch');
166
166
167
my $item = {
167
my $item = $builder->build_object({
168
    homebranch => $library2->{branchcode},
168
    class => 'Koha::Items',
169
    holdingbranch => $library2->{branchcode}
169
    value => {
170
};
170
        homebranch => $library2->{branchcode},
171
        holdingbranch => $library2->{branchcode}
172
    }
173
});
171
174
172
my $borrower = {
175
my $borrower = $builder->build_object({
173
    branchcode => $library2->{branchcode}
176
    class => 'Koha::Patrons',
174
};
177
    value => { branchcode => $library2->{branchcode} }
178
});
175
179
176
t::lib::Mocks::mock_preference('AutoReturnCheckedOutItems', 0);
180
t::lib::Mocks::mock_preference('AutoReturnCheckedOutItems', 0);
177
181
Lines 185-191 is( Link Here
185
);
189
);
186
is(
190
is(
187
    C4::Circulation::_GetCircControlBranch($item, $borrower),
191
    C4::Circulation::_GetCircControlBranch($item, $borrower),
188
    $item->{$HomeOrHoldingBranch},
192
    $item->get_column($HomeOrHoldingBranch),
189
    '_GetCircControlBranch returned item branch (no userenv defined)'
193
    '_GetCircControlBranch returned item branch (no userenv defined)'
190
);
194
);
191
195
Lines 198-204 is( Link Here
198
);
202
);
199
is(
203
is(
200
    C4::Circulation::_GetCircControlBranch($item, $borrower),
204
    C4::Circulation::_GetCircControlBranch($item, $borrower),
201
    $borrower->{branchcode},
205
    $borrower->branchcode,
202
    '_GetCircControlBranch returned borrower branch'
206
    '_GetCircControlBranch returned borrower branch'
203
);
207
);
204
208
Lines 210-216 is( Link Here
210
    'CircControl changed to ItemHomeLibrary'
214
    'CircControl changed to ItemHomeLibrary'
211
);
215
);
212
is(
216
is(
213
    $item->{$HomeOrHoldingBranch},
217
    $item->get_column($HomeOrHoldingBranch),
214
    C4::Circulation::_GetCircControlBranch($item, $borrower),
218
    C4::Circulation::_GetCircControlBranch($item, $borrower),
215
    '_GetCircControlBranch returned item branch'
219
    '_GetCircControlBranch returned item branch'
216
);
220
);
Lines 241-247 is( Link Here
241
);
245
);
242
is(
246
is(
243
    C4::Circulation::_GetCircControlBranch($item, $borrower),
247
    C4::Circulation::_GetCircControlBranch($item, $borrower),
244
    $borrower->{branchcode},
248
    $borrower->branchcode,
245
    '_GetCircControlBranch returned borrower branch'
249
    '_GetCircControlBranch returned borrower branch'
246
);
250
);
247
251
Lines 254-260 is( Link Here
254
);
258
);
255
is(
259
is(
256
    C4::Circulation::_GetCircControlBranch($item, $borrower),
260
    C4::Circulation::_GetCircControlBranch($item, $borrower),
257
    $item->{$HomeOrHoldingBranch},
261
    $item->get_column($HomeOrHoldingBranch),
258
    '_GetCircControlBranch returned item branch'
262
    '_GetCircControlBranch returned item branch'
259
);
263
);
260
264
Lines 329-335 subtest "CanBookBeRenewed AllowRenewalIfOtherItemsAvailable multiple borrowers a Link Here
329
        homebranch   => $patron_hold_1->branchcode
333
        homebranch   => $patron_hold_1->branchcode
330
    });
334
    });
331
335
332
    my $issue = AddIssue( $patron->unblessed, $item_1->barcode);
336
    my $issue = AddIssue( $patron, $item_1->barcode);
333
    my $datedue = dt_from_string( $issue->date_due() );
337
    my $datedue = dt_from_string( $issue->date_due() );
334
    is (defined $issue->date_due(), 1, "Item 1 checked out, due date: " . $issue->date_due() );
338
    is (defined $issue->date_due(), 1, "Item 1 checked out, due date: " . $issue->date_due() );
335
339
Lines 512-522 subtest "CanBookBeRenewed tests" => sub { Link Here
512
    my $checkitem      = undef;
516
    my $checkitem      = undef;
513
    my $found          = undef;
517
    my $found          = undef;
514
518
515
    my $issue_1 = AddIssue( $renewing_borrower_obj->unblessed, $item_1->barcode);
519
    my $issue_1 = AddIssue( $renewing_borrower_obj, $item_1->barcode);
516
    my $datedue = dt_from_string( $issue_1->date_due() );
520
    my $datedue = dt_from_string( $issue_1->date_due() );
517
    is (defined $issue_1->date_due(), 1, "Item 1 checked out, due date: " . $issue_1->date_due() );
521
    is (defined $issue_1->date_due(), 1, "Item 1 checked out, due date: " . $issue_1->date_due() );
518
522
519
    my $issue_2 = AddIssue( $renewing_borrower_obj->unblessed, $item_2->barcode);
523
    my $issue_2 = AddIssue( $renewing_borrower_obj, $item_2->barcode);
520
    is (defined $issue_2, 1, "Item 2 checked out, due date: " . $issue_2->date_due());
524
    is (defined $issue_2, 1, "Item 2 checked out, due date: " . $issue_2->date_due());
521
525
522
    my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $item_1->itemnumber } )->borrowernumber;
526
    my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $item_1->itemnumber } )->borrowernumber;
Lines 627-633 subtest "CanBookBeRenewed tests" => sub { Link Here
627
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
631
    is( $error, 'on_reserve', '(Bug 10663) Cannot renew, reserved (returned error is on_reserve)');
628
632
629
    my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
633
    my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
630
    my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber )->unblessed;
634
    my $reserving_borrower = Koha::Patrons->find( $reserving_borrowernumber );
631
    AddIssue($reserving_borrower, $item_3->barcode);
635
    AddIssue($reserving_borrower, $item_3->barcode);
632
    my $reserve = $dbh->selectrow_hashref(
636
    my $reserve = $dbh->selectrow_hashref(
633
        'SELECT * FROM old_reserves WHERE reserve_id = ?',
637
        'SELECT * FROM old_reserves WHERE reserve_id = ?',
Lines 675-681 subtest "CanBookBeRenewed tests" => sub { Link Here
675
            itype            => $itemtype,
679
            itype            => $itemtype,
676
        }
680
        }
677
    );
681
    );
678
    my $issue_5 = AddIssue($restricted_borrower_obj->unblessed, $item_5->barcode);
682
    my $issue_5 = AddIssue($restricted_borrower_obj, $item_5->barcode);
679
    is (defined $issue_5, 1, "Item with date due checked out, due date: ". $issue_5->date_due);
683
    is (defined $issue_5, 1, "Item with date due checked out, due date: ". $issue_5->date_due);
680
684
681
    t::lib::Mocks::mock_preference('RestrictionBlockRenewing','1');
685
    t::lib::Mocks::mock_preference('RestrictionBlockRenewing','1');
Lines 704-710 subtest "CanBookBeRenewed tests" => sub { Link Here
704
        }
708
        }
705
    );
709
    );
706
710
707
    my $issue_6 = AddIssue( $renewing_borrower_obj->unblessed, $item_6->barcode);
711
    my $issue_6 = AddIssue( $renewing_borrower_obj, $item_6->barcode);
708
    is (defined $issue_6, 1, "Item 2 checked out, due date: ".$issue_6->date_due);
712
    is (defined $issue_6, 1, "Item 2 checked out, due date: ".$issue_6->date_due);
709
713
710
    my $now = dt_from_string();
714
    my $now = dt_from_string();
Lines 712-718 subtest "CanBookBeRenewed tests" => sub { Link Here
712
    my $five_weeks_ago = $now - $five_weeks;
716
    my $five_weeks_ago = $now - $five_weeks;
713
    t::lib::Mocks::mock_preference('finesMode', 'production');
717
    t::lib::Mocks::mock_preference('finesMode', 'production');
714
718
715
    my $issue_7 = AddIssue($renewing_borrower_obj->unblessed, $item_7->barcode, $five_weeks_ago);
719
    my $issue_7 = AddIssue($renewing_borrower_obj, $item_7->barcode, $five_weeks_ago);
716
    is (defined $issue_7, 1, "Item with passed date due checked out, due date: " . $issue_7->date_due);
720
    is (defined $issue_7, 1, "Item with passed date due checked out, due date: " . $issue_7->date_due);
717
721
718
    t::lib::Mocks::mock_preference('OverduesBlockRenewing','allow');
722
    t::lib::Mocks::mock_preference('OverduesBlockRenewing','allow');
Lines 793-799 subtest "CanBookBeRenewed tests" => sub { Link Here
793
    my $old_issue_log_size = Koha::ActionLogs->count( \%params_issue );
797
    my $old_issue_log_size = Koha::ActionLogs->count( \%params_issue );
794
    my $old_renew_log_size = Koha::ActionLogs->count( \%params_renewal );
798
    my $old_renew_log_size = Koha::ActionLogs->count( \%params_renewal );
795
    AddIssue(
799
    AddIssue(
796
        $renewing_borrower_obj->unblessed,
800
        $renewing_borrower_obj,
797
        $item_7->barcode,
801
        $item_7->barcode,
798
        Koha::DateUtils::output_pref({str=>$issue_6->date_due, dateformat =>'iso'}),
802
        Koha::DateUtils::output_pref({str=>$issue_6->date_due, dateformat =>'iso'}),
799
        0,
803
        0,
Lines 821-827 subtest "CanBookBeRenewed tests" => sub { Link Here
821
        }
825
        }
822
    );
826
    );
823
827
824
    my $issue_4 = AddIssue( $renewing_borrower_obj->unblessed, $item_4->barcode, undef, undef, undef, undef, { auto_renew => 1 } );
828
    my $issue_4 = AddIssue( $renewing_borrower_obj, $item_4->barcode, undef, undef, undef, undef, { auto_renew => 1 } );
825
    my $info;
829
    my $info;
826
    ( $renewokay, $error, $info ) =
830
    ( $renewokay, $error, $info ) =
827
      CanBookBeRenewed( $renewing_borrower_obj, $issue_4 );
831
      CanBookBeRenewed( $renewing_borrower_obj, $issue_4 );
Lines 951-957 subtest "CanBookBeRenewed tests" => sub { Link Here
951
955
952
        my $ten_days_before = dt_from_string->add( days => -10 );
956
        my $ten_days_before = dt_from_string->add( days => -10 );
953
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
957
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
954
        my $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
958
        my $issue = AddIssue( $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
955
959
956
        Koha::CirculationRules->set_rules(
960
        Koha::CirculationRules->set_rules(
957
            {
961
            {
Lines 1080-1086 subtest "CanBookBeRenewed tests" => sub { Link Here
1080
1084
1081
        my $ten_days_before = dt_from_string->add( days => -10 );
1085
        my $ten_days_before = dt_from_string->add( days => -10 );
1082
        my $ten_days_ahead = dt_from_string->add( days => 10 );
1086
        my $ten_days_ahead = dt_from_string->add( days => 10 );
1083
        my $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1087
        my $issue = AddIssue( $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1084
1088
1085
        Koha::CirculationRules->set_rules(
1089
        Koha::CirculationRules->set_rules(
1086
            {
1090
            {
Lines 1190-1196 subtest "CanBookBeRenewed tests" => sub { Link Here
1190
        # Patron is expired and BlockExpiredPatronOpacActions=0
1194
        # Patron is expired and BlockExpiredPatronOpacActions=0
1191
        # => auto renew is allowed
1195
        # => auto renew is allowed
1192
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 0);
1196
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 0);
1193
        my $issue = AddIssue( $expired_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1197
        my $issue = AddIssue( $expired_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1194
        ( $renewokay, $error ) =
1198
        ( $renewokay, $error ) =
1195
          CanBookBeRenewed( $expired_borrower_obj, $issue );
1199
          CanBookBeRenewed( $expired_borrower_obj, $issue );
1196
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1200
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
Lines 1201-1207 subtest "CanBookBeRenewed tests" => sub { Link Here
1201
        # Patron is expired and BlockExpiredPatronOpacActions=1
1205
        # Patron is expired and BlockExpiredPatronOpacActions=1
1202
        # => auto renew is not allowed
1206
        # => auto renew is not allowed
1203
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
1207
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
1204
        $issue = AddIssue( $expired_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1208
        $issue = AddIssue( $expired_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1205
        ( $renewokay, $error ) =
1209
        ( $renewokay, $error ) =
1206
          CanBookBeRenewed( $expired_borrower_obj, $issue );
1210
          CanBookBeRenewed( $expired_borrower_obj, $issue );
1207
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1211
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
Lines 1211-1217 subtest "CanBookBeRenewed tests" => sub { Link Here
1211
        # Patron is not expired and BlockExpiredPatronOpacActions=1
1215
        # Patron is not expired and BlockExpiredPatronOpacActions=1
1212
        # => auto renew is allowed
1216
        # => auto renew is allowed
1213
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
1217
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
1214
        $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1218
        $issue = AddIssue( $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1215
        ( $renewokay, $error ) =
1219
        ( $renewokay, $error ) =
1216
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1220
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1217
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1221
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
Lines 1230-1236 subtest "CanBookBeRenewed tests" => sub { Link Here
1230
1234
1231
        my $ten_days_before = dt_from_string->add( days => -10 );
1235
        my $ten_days_before = dt_from_string->add( days => -10 );
1232
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
1236
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
1233
        my $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1237
        my $issue = AddIssue( $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1234
        Koha::CirculationRules->set_rules(
1238
        Koha::CirculationRules->set_rules(
1235
            {
1239
            {
1236
                categorycode => undef,
1240
                categorycode => undef,
Lines 1482-1488 subtest "CanBookBeRenewed tests" => sub { Link Here
1482
    my $recall_item1 = $builder->build_sample_item({ biblionumber => $recall_biblio->biblionumber });
1486
    my $recall_item1 = $builder->build_sample_item({ biblionumber => $recall_biblio->biblionumber });
1483
    my $recall_item2 = $builder->build_sample_item({ biblionumber => $recall_biblio->biblionumber });
1487
    my $recall_item2 = $builder->build_sample_item({ biblionumber => $recall_biblio->biblionumber });
1484
1488
1485
    my $recall_issue = AddIssue( $renewing_borrower_obj->unblessed, $recall_item1->barcode );
1489
    my $recall_issue = AddIssue( $renewing_borrower_obj, $recall_item1->barcode );
1486
1490
1487
    # item-level and this item: renewal not allowed
1491
    # item-level and this item: renewal not allowed
1488
    my $recall = Koha::Recall->new({
1492
    my $recall = Koha::Recall->new({
Lines 1563-1569 subtest "GetUpcomingDueIssues" => sub { Link Here
1563
    );
1567
    );
1564
1568
1565
    my $a_borrower_borrowernumber = Koha::Patron->new(\%a_borrower_data)->store->borrowernumber;
1569
    my $a_borrower_borrowernumber = Koha::Patron->new(\%a_borrower_data)->store->borrowernumber;
1566
    my $a_borrower = Koha::Patrons->find( $a_borrower_borrowernumber )->unblessed;
1570
    my $a_borrower = Koha::Patrons->find( $a_borrower_borrowernumber );
1567
1571
1568
    my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 );
1572
    my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 );
1569
    my $two_days_ahead = DateTime->today(time_zone => C4::Context->tz())->add( days => 2 );
1573
    my $two_days_ahead = DateTime->today(time_zone => C4::Context->tz())->add( days => 2 );
Lines 1640-1646 subtest "Bug 13841 - Do not create new 0 amount fines" => sub { Link Here
1640
1644
1641
    my $borrowernumber = Koha::Patron->new(\%a_borrower_data)->store->borrowernumber;
1645
    my $borrowernumber = Koha::Patron->new(\%a_borrower_data)->store->borrowernumber;
1642
1646
1643
    my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
1647
    my $borrower = Koha::Patrons->find( $borrowernumber );
1644
    my $issue = AddIssue( $borrower, $item->barcode );
1648
    my $issue = AddIssue( $borrower, $item->barcode );
1645
    UpdateFine(
1649
    UpdateFine(
1646
        {
1650
        {
Lines 1893-1899 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1893
        branchcode => $branch,
1897
        branchcode => $branch,
1894
    })->store;
1898
    })->store;
1895
1899
1896
    my $issue = AddIssue( $borrower->unblessed, $item->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } );
1900
    my $issue = AddIssue( $borrower, $item->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } );
1897
    my ( $renewed, $error ) = CanBookBeRenewed( $borrower, $issue );
1901
    my ( $renewed, $error ) = CanBookBeRenewed( $borrower, $issue );
1898
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew on-site checkout' );
1902
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew on-site checkout' );
1899
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
1903
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
Lines 1913-1919 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1913
    );
1917
    );
1914
    my $patron = $builder->build_object( { class => 'Koha::Patrons',  value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } );
1918
    my $patron = $builder->build_object( { class => 'Koha::Patrons',  value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } );
1915
1919
1916
    my $issue = AddIssue( $patron->unblessed, $item->barcode );
1920
    my $issue = AddIssue( $patron, $item->barcode );
1917
    UpdateFine(
1921
    UpdateFine(
1918
        {
1922
        {
1919
            issue_id       => $issue->id,
1923
            issue_id       => $issue->id,
Lines 1972-1978 subtest 'CanBookBeIssued & AllowReturnToBranch' => sub { Link Here
1972
1976
1973
    set_userenv($holdingbranch);
1977
    set_userenv($holdingbranch);
1974
1978
1975
    my $issue = AddIssue( $patron_1->unblessed, $item->barcode );
1979
    my $issue = AddIssue( $patron_1, $item->barcode );
1976
    is( ref($issue), 'Koha::Checkout', 'AddIssue should return a Koha::Checkout object' );
1980
    is( ref($issue), 'Koha::Checkout', 'AddIssue should return a Koha::Checkout object' );
1977
1981
1978
    my ( $error, $question, $alerts );
1982
    my ( $error, $question, $alerts );
Lines 2047-2054 subtest 'AddIssue & AllowReturnToBranch' => sub { Link Here
2047
    my $homebranch    = $builder->build( { source => 'Branch' } );
2051
    my $homebranch    = $builder->build( { source => 'Branch' } );
2048
    my $holdingbranch = $builder->build( { source => 'Branch' } );
2052
    my $holdingbranch = $builder->build( { source => 'Branch' } );
2049
    my $otherbranch   = $builder->build( { source => 'Branch' } );
2053
    my $otherbranch   = $builder->build( { source => 'Branch' } );
2050
    my $patron_1      = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } );
2054
2051
    my $patron_2      = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } );
2055
    my $patron_1  = $builder->build_object({
2056
        class => 'Koha::Patrons',
2057
        value => { categorycode => $patron_category->{categorycode} }
2058
    });
2059
2060
    my $patron_2  = $builder->build_object({
2061
        class => 'Koha::Patrons',
2062
        value => { categorycode => $patron_category->{categorycode} }
2063
    });
2064
2052
2065
2053
    my $item = $builder->build_sample_item(
2066
    my $item = $builder->build_sample_item(
2054
        {
2067
        {
Lines 4091-4097 subtest 'CanBookBeIssued | is_overdue' => sub { Link Here
4091
        }
4104
        }
4092
    );
4105
    );
4093
4106
4094
    my $issue = AddIssue( $patron->unblessed, $item->barcode, $five_days_go ); # date due was 10d ago
4107
    my $issue = AddIssue( $patron, $item->barcode, $five_days_go ); # date due was 10d ago
4095
    my $actualissue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
4108
    my $actualissue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
4096
    is( output_pref({ str => $actualissue->date_due, dateonly => 1}), output_pref({ str => $five_days_go, dateonly => 1}), "First issue works");
4109
    is( output_pref({ str => $actualissue->date_due, dateonly => 1}), output_pref({ str => $five_days_go, dateonly => 1}), "First issue works");
4097
    my ($issuingimpossible, $needsconfirmation) = CanBookBeIssued($patron, $item->barcode, $ten_days_go, undef, undef, undef);
4110
    my ($issuingimpossible, $needsconfirmation) = CanBookBeIssued($patron, $item->barcode, $ten_days_go, undef, undef, undef);
Lines 4383-4389 subtest 'AddReturn | recalls' => sub { Link Here
4383
    });
4396
    });
4384
4397
4385
    # this item can fill a recall with pickup at this branch
4398
    # this item can fill a recall with pickup at this branch
4386
    AddIssue( $patron1->unblessed, $item1->barcode );
4399
    AddIssue( $patron1, $item1->barcode );
4387
    my $recall1 = Koha::Recall->new(
4400
    my $recall1 = Koha::Recall->new(
4388
        {   patron_id         => $patron2->borrowernumber,
4401
        {   patron_id         => $patron2->borrowernumber,
4389
            biblio_id         => $item1->biblionumber,
4402
            biblio_id         => $item1->biblionumber,
Lines 4397-4403 subtest 'AddReturn | recalls' => sub { Link Here
4397
    $recall1->set_cancelled;
4410
    $recall1->set_cancelled;
4398
4411
4399
    # this item can fill a recall but needs transfer
4412
    # this item can fill a recall but needs transfer
4400
    AddIssue( $patron1->unblessed, $item1->barcode );
4413
    AddIssue( $patron1, $item1->barcode );
4401
    $recall1 = Koha::Recall->new(
4414
    $recall1 = Koha::Recall->new(
4402
        {   patron_id         => $patron2->borrowernumber,
4415
        {   patron_id         => $patron2->borrowernumber,
4403
            biblio_id         => $item1->biblionumber,
4416
            biblio_id         => $item1->biblionumber,
Lines 4411-4417 subtest 'AddReturn | recalls' => sub { Link Here
4411
    $recall1->set_cancelled;
4424
    $recall1->set_cancelled;
4412
4425
4413
    # this item is already in transit, do not ask to transfer
4426
    # this item is already in transit, do not ask to transfer
4414
    AddIssue( $patron1->unblessed, $item1->barcode );
4427
    AddIssue( $patron1, $item1->barcode );
4415
    $recall1 = Koha::Recall->new(
4428
    $recall1 = Koha::Recall->new(
4416
        {   patron_id         => $patron2->borrowernumber,
4429
        {   patron_id         => $patron2->borrowernumber,
4417
            biblio_id         => $item1->biblionumber,
4430
            biblio_id         => $item1->biblionumber,
Lines 4489-4495 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
4489
    $context->mock( userenv => { branch => $library->id } );
4502
    $context->mock( userenv => { branch => $library->id } );
4490
4503
4491
    # Check the item out
4504
    # Check the item out
4492
    AddIssue( $patron->unblessed, $item->barcode );
4505
    AddIssue( $patron, $item->barcode );
4493
4506
4494
    throws_ok {
4507
    throws_ok {
4495
        AddRenewal( $patron->borrowernumber, $item->itemnumber, $library->id, undef, {break=>"the_renewal"} );
4508
        AddRenewal( $patron->borrowernumber, $item->itemnumber, $library->id, undef, {break=>"the_renewal"} );
Lines 4547-4553 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
4547
    is( $new_stats_size, $old_stats_size + 1, 'renew statistic successfully added with passed branch' );
4560
    is( $new_stats_size, $old_stats_size + 1, 'renew statistic successfully added with passed branch' );
4548
4561
4549
    AddReturn( $item->id, $library->id, undef, $date );
4562
    AddReturn( $item->id, $library->id, undef, $date );
4550
    AddIssue( $patron->unblessed, $item->barcode, $now );
4563
    AddIssue( $patron, $item->barcode, $now );
4551
    AddRenewal( $patron->id, $item->id, $library->id, undef, undef, 1 );
4564
    AddRenewal( $patron->id, $item->id, $library->id, undef, undef, 1 );
4552
    my $lines_skipped = Koha::Account::Lines->search({
4565
    my $lines_skipped = Koha::Account::Lines->search({
4553
        borrowernumber => $patron->id,
4566
        borrowernumber => $patron->id,
Lines 4571-4577 subtest 'AddRenewal() adds to renewals' => sub { Link Here
4571
    set_userenv( $library->unblessed );
4584
    set_userenv( $library->unblessed );
4572
4585
4573
    # Check the item out
4586
    # Check the item out
4574
    my $issue = AddIssue( $patron->unblessed, $item->barcode );
4587
    my $issue = AddIssue( $patron, $item->barcode );
4575
    is(ref($issue), 'Koha::Checkout', 'Issue added');
4588
    is(ref($issue), 'Koha::Checkout', 'Issue added');
4576
4589
4577
    # Renew item
4590
    # Renew item
Lines 4655-4661 subtest 'Incremented fee tests' => sub { Link Here
4655
4668
4656
    # Daily Tests
4669
    # Daily Tests
4657
    my $issue =
4670
    my $issue =
4658
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4671
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4659
    my $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4672
    my $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4660
    is(
4673
    is(
4661
        $accountline->amount + 0,
4674
        $accountline->amount + 0,
Lines 4676-4682 subtest 'Incremented fee tests' => sub { Link Here
4676
    t::lib::Mocks::mock_preference( 'finesCalendar', 'noFinesWhenClosed' );
4689
    t::lib::Mocks::mock_preference( 'finesCalendar', 'noFinesWhenClosed' );
4677
    $itemtype->rentalcharge_daily_calendar(1)->store();
4690
    $itemtype->rentalcharge_daily_calendar(1)->store();
4678
    $issue =
4691
    $issue =
4679
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4692
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4680
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4693
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4681
    is(
4694
    is(
4682
        $accountline->amount + 0,
4695
        $accountline->amount + 0,
Lines 4707-4713 subtest 'Incremented fee tests' => sub { Link Here
4707
        description => 'Test holiday'
4720
        description => 'Test holiday'
4708
    );
4721
    );
4709
    $issue =
4722
    $issue =
4710
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4723
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4711
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4724
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4712
    is(
4725
    is(
4713
        $accountline->amount + 0,
4726
        $accountline->amount + 0,
Lines 4728-4734 subtest 'Incremented fee tests' => sub { Link Here
4728
    $itemtype->rentalcharge(2)->store;
4741
    $itemtype->rentalcharge(2)->store;
4729
    is( $itemtype->rentalcharge + 0, 2, 'Rental charge updated and retreived correctly' );
4742
    is( $itemtype->rentalcharge + 0, 2, 'Rental charge updated and retreived correctly' );
4730
    $issue =
4743
    $issue =
4731
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4744
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4732
    my $accountlines =
4745
    my $accountlines =
4733
      Koha::Account::Lines->search( { itemnumber => $item->id } );
4746
      Koha::Account::Lines->search( { itemnumber => $item->id } );
4734
    is( $accountlines->count, '2', "Fixed charge and accrued charge recorded distinctly" );
4747
    is( $accountlines->count, '2', "Fixed charge and accrued charge recorded distinctly" );
Lines 4760-4766 subtest 'Incremented fee tests' => sub { Link Here
4760
4773
4761
    $itemtype->rentalcharge_hourly_calendar(0)->store();
4774
    $itemtype->rentalcharge_hourly_calendar(0)->store();
4762
    $issue =
4775
    $issue =
4763
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4776
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4764
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4777
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4765
    is(
4778
    is(
4766
        $accountline->amount + 0,
4779
        $accountline->amount + 0,
Lines 4780-4786 subtest 'Incremented fee tests' => sub { Link Here
4780
4793
4781
    $itemtype->rentalcharge_hourly_calendar(1)->store();
4794
    $itemtype->rentalcharge_hourly_calendar(1)->store();
4782
    $issue =
4795
    $issue =
4783
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4796
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4784
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4797
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4785
    is(
4798
    is(
4786
        $accountline->amount + 0,
4799
        $accountline->amount + 0,
Lines 4800-4806 subtest 'Incremented fee tests' => sub { Link Here
4800
4813
4801
    $calendar->delete_holiday( weekday => $closed_day );
4814
    $calendar->delete_holiday( weekday => $closed_day );
4802
    $issue =
4815
    $issue =
4803
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
4816
      AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
4804
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4817
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
4805
    is(
4818
    is(
4806
        $accountline->amount + 0,
4819
        $accountline->amount + 0,
Lines 4914-4920 subtest 'Do not return on renewal (LOST charge)' => sub { Link Here
4914
    );
4927
    );
4915
4928
4916
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
4929
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
4917
    AddIssue( $patron->unblessed, $item->barcode );
4930
    AddIssue( $patron, $item->barcode );
4918
4931
4919
    my $accountline = Koha::Account::Line->new(
4932
    my $accountline = Koha::Account::Line->new(
4920
        {
4933
        {
Lines 4929-4935 subtest 'Do not return on renewal (LOST charge)' => sub { Link Here
4929
    )->store();
4942
    )->store();
4930
4943
4931
    # AddRenewal doesn't call _FixAccountForLostAndFound
4944
    # AddRenewal doesn't call _FixAccountForLostAndFound
4932
    AddIssue( $patron->unblessed, $item->barcode );
4945
    AddIssue( $patron, $item->barcode );
4933
4946
4934
    is( $patron->checkouts->count, 1,
4947
    is( $patron->checkouts->count, 1,
4935
        'Renewal should not return the item even if a LOST payment has been made earlier'
4948
        'Renewal should not return the item even if a LOST payment has been made earlier'
Lines 5035-5041 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddReturn' => sub { Link Here
5035
                replacementprice => '42',
5048
                replacementprice => '42',
5036
            }
5049
            }
5037
        );
5050
        );
5038
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5051
        my $issue = AddIssue( $patron, $item->barcode );
5039
        LostItem( $item->itemnumber, 'cli', 0 );
5052
        LostItem( $item->itemnumber, 'cli', 0 );
5040
        $item->_result->itemlost(1);
5053
        $item->_result->itemlost(1);
5041
        $item->_result->itemlost_on( $lost_on );
5054
        $item->_result->itemlost_on( $lost_on );
Lines 5070-5076 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddReturn' => sub { Link Here
5070
                replacementprice => '42',
5083
                replacementprice => '42',
5071
            }
5084
            }
5072
        );
5085
        );
5073
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5086
        my $issue = AddIssue( $patron, $item->barcode );
5074
        LostItem( $item->itemnumber, 'cli', 0 );
5087
        LostItem( $item->itemnumber, 'cli', 0 );
5075
        $item->_result->itemlost(1);
5088
        $item->_result->itemlost(1);
5076
        $item->_result->itemlost_on( $lost_on );
5089
        $item->_result->itemlost_on( $lost_on );
Lines 5105-5111 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddReturn' => sub { Link Here
5105
                replacementprice => '42',
5118
                replacementprice => '42',
5106
            }
5119
            }
5107
        );
5120
        );
5108
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5121
        my $issue = AddIssue( $patron, $item->barcode );
5109
        LostItem( $item->itemnumber, 'cli', 0 );
5122
        LostItem( $item->itemnumber, 'cli', 0 );
5110
        $item->_result->itemlost(1);
5123
        $item->_result->itemlost(1);
5111
        $item->_result->itemlost_on( $lost_on );
5124
        $item->_result->itemlost_on( $lost_on );
Lines 5140-5146 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddReturn' => sub { Link Here
5140
                replacementprice => '42',
5153
                replacementprice => '42',
5141
            }
5154
            }
5142
        );
5155
        );
5143
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5156
        my $issue = AddIssue( $patron, $item->barcode );
5144
        LostItem( $item->itemnumber, 'cli', 0 );
5157
        LostItem( $item->itemnumber, 'cli', 0 );
5145
        $item->_result->itemlost(1);
5158
        $item->_result->itemlost(1);
5146
        $item->_result->itemlost_on( $lost_on );
5159
        $item->_result->itemlost_on( $lost_on );
Lines 5228-5234 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5228
                replacementprice => '42',
5241
                replacementprice => '42',
5229
            }
5242
            }
5230
        );
5243
        );
5231
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5244
        my $issue = AddIssue( $patron, $item->barcode );
5232
        LostItem( $item->itemnumber, 'cli', 0 );
5245
        LostItem( $item->itemnumber, 'cli', 0 );
5233
        $item->_result->itemlost(1);
5246
        $item->_result->itemlost(1);
5234
        $item->_result->itemlost_on( $lost_on );
5247
        $item->_result->itemlost_on( $lost_on );
Lines 5242-5248 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5242
        )->next;
5255
        )->next;
5243
        ok( $a, "Found accountline for lost fee" );
5256
        ok( $a, "Found accountline for lost fee" );
5244
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5257
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5245
        $issue = AddIssue( $patron2->unblessed, $item->barcode );
5258
        $issue = AddIssue( $patron2, $item->barcode );
5246
        $a = $a->get_from_storage;
5259
        $a = $a->get_from_storage;
5247
        is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" );
5260
        is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" );
5248
        $a->delete;
5261
        $a->delete;
Lines 5264-5270 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5264
                replacementprice => '42',
5277
                replacementprice => '42',
5265
            }
5278
            }
5266
        );
5279
        );
5267
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5280
        my $issue = AddIssue( $patron, $item->barcode );
5268
        LostItem( $item->itemnumber, 'cli', 0 );
5281
        LostItem( $item->itemnumber, 'cli', 0 );
5269
        $item->_result->itemlost(1);
5282
        $item->_result->itemlost(1);
5270
        $item->_result->itemlost_on( $lost_on );
5283
        $item->_result->itemlost_on( $lost_on );
Lines 5278-5284 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5278
        )->next;
5291
        )->next;
5279
        ok( $a, "Found accountline for lost fee" );
5292
        ok( $a, "Found accountline for lost fee" );
5280
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5293
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5281
        $issue = AddIssue( $patron2->unblessed, $item->barcode );
5294
        $issue = AddIssue( $patron2, $item->barcode );
5282
        $a = $a->get_from_storage;
5295
        $a = $a->get_from_storage;
5283
        is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" );
5296
        is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" );
5284
        $a->delete;
5297
        $a->delete;
Lines 5299-5305 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5299
                replacementprice => '42',
5312
                replacementprice => '42',
5300
            }
5313
            }
5301
        );
5314
        );
5302
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5315
        my $issue = AddIssue( $patron, $item->barcode );
5303
        LostItem( $item->itemnumber, 'cli', 0 );
5316
        LostItem( $item->itemnumber, 'cli', 0 );
5304
        $item->_result->itemlost(1);
5317
        $item->_result->itemlost(1);
5305
        $item->_result->itemlost_on( $lost_on );
5318
        $item->_result->itemlost_on( $lost_on );
Lines 5313-5319 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5313
        )->next;
5326
        )->next;
5314
        ok( $a, "Found accountline for lost fee" );
5327
        ok( $a, "Found accountline for lost fee" );
5315
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5328
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5316
        $issue = AddIssue( $patron2->unblessed, $item->barcode );
5329
        $issue = AddIssue( $patron2, $item->barcode );
5317
        $a = $a->get_from_storage;
5330
        $a = $a->get_from_storage;
5318
        is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" );
5331
        is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" );
5319
        $a->delete;
5332
        $a->delete;
Lines 5334-5340 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5334
                replacementprice => '42',
5347
                replacementprice => '42',
5335
            }
5348
            }
5336
        );
5349
        );
5337
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
5350
        my $issue = AddIssue( $patron, $item->barcode );
5338
        LostItem( $item->itemnumber, 'cli', 0 );
5351
        LostItem( $item->itemnumber, 'cli', 0 );
5339
        $item->_result->itemlost(1);
5352
        $item->_result->itemlost(1);
5340
        $item->_result->itemlost_on( $lost_on );
5353
        $item->_result->itemlost_on( $lost_on );
Lines 5349-5355 subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { Link Here
5349
        $a = $a->next;
5362
        $a = $a->next;
5350
        ok( $a, "Found accountline for lost fee" );
5363
        ok( $a, "Found accountline for lost fee" );
5351
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5364
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
5352
        $issue = AddIssue( $patron2->unblessed, $item->barcode );
5365
        $issue = AddIssue( $patron2, $item->barcode );
5353
        $a = $a->get_from_storage;
5366
        $a = $a->get_from_storage;
5354
        is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" );
5367
        is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" );
5355
        $a->delete;
5368
        $a->delete;
Lines 5435-5441 subtest 'Checkout should correctly terminate a transfer' => sub { Link Here
5435
    is( $transfer->reason,     'Reserve' );
5448
    is( $transfer->reason,     'Reserve' );
5436
5449
5437
    t::lib::Mocks::mock_userenv( { branchcode => $library_2->branchcode } );
5450
    t::lib::Mocks::mock_userenv( { branchcode => $library_2->branchcode } );
5438
    AddIssue( $patron_1->unblessed, $item->barcode );
5451
    AddIssue( $patron_1, $item->barcode );
5439
    $transfer = $transfer->get_from_storage;
5452
    $transfer = $transfer->get_from_storage;
5440
    isnt( $transfer->datearrived, undef );
5453
    isnt( $transfer->datearrived, undef );
5441
    $hold = $hold->get_from_storage;
5454
    $hold = $hold->get_from_storage;
Lines 5478-5491 subtest 'AddIssue records staff who checked out item if appropriate' => sub { Link Here
5478
    my $dt_from = dt_from_string();
5491
    my $dt_from = dt_from_string();
5479
    my $dt_to   = dt_from_string()->add( days => 7 );
5492
    my $dt_to   = dt_from_string()->add( days => 7 );
5480
5493
5481
    my $issue_1 = AddIssue( $patron->unblessed, $item_1->barcode, $dt_to, undef, $dt_from );
5494
    my $issue_1 = AddIssue( $patron, $item_1->barcode, $dt_to, undef, $dt_from );
5482
5495
5483
    is( $issue_1->issuer, undef, "Staff who checked out the item not recorded when RecordStaffUserOnCheckout turned off" );
5496
    is( $issue_1->issuer, undef, "Staff who checked out the item not recorded when RecordStaffUserOnCheckout turned off" );
5484
5497
5485
    t::lib::Mocks::mock_preference('RecordStaffUserOnCheckout', 1);
5498
    t::lib::Mocks::mock_preference('RecordStaffUserOnCheckout', 1);
5486
5499
5487
    my $issue_2 =
5500
    my $issue_2 =
5488
      AddIssue( $patron->unblessed, $item_2->barcode, $dt_to, undef, $dt_from );
5501
      AddIssue( $patron, $item_2->barcode, $dt_to, undef, $dt_from );
5489
5502
5490
    is( $issue_2->issuer->borrowernumber, $issuer->borrowernumber, "Staff who checked out the item recorded when RecordStaffUserOnCheckout turned on" );
5503
    is( $issue_2->issuer->borrowernumber, $issuer->borrowernumber, "Staff who checked out the item recorded when RecordStaffUserOnCheckout turned on" );
5491
};
5504
};
Lines 5513-5521 subtest "Item's onloan value should be set if checked out item is checked out to Link Here
5513
        }
5526
        }
5514
    );
5527
    );
5515
5528
5516
    AddIssue( $patron_1->unblessed, $item->barcode );
5529
    AddIssue( $patron_1, $item->barcode );
5517
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after initial checkout" );
5530
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after initial checkout" );
5518
    AddIssue( $patron_2->unblessed, $item->barcode );
5531
    AddIssue( $patron_2, $item->barcode );
5519
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after second checkout" );
5532
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after second checkout" );
5520
};
5533
};
5521
5534
Lines 5592-5598 subtest "SendCirculationAlert" => sub { Link Here
5592
    })->store;
5605
    })->store;
5593
5606
5594
    # Checkout an item, mark it returned, generate a notice
5607
    # Checkout an item, mark it returned, generate a notice
5595
    my $issue_1 = AddIssue( $patron->unblessed, $item->barcode);
5608
    my $issue_1 = AddIssue( $patron, $item->barcode);
5596
    MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0, { skip_record_index => 1} );
5609
    MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0, { skip_record_index => 1} );
5597
    C4::Circulation::SendCirculationAlert({
5610
    C4::Circulation::SendCirculationAlert({
5598
        type => 'CHECKIN',
5611
        type => 'CHECKIN',
Lines 5606-5612 subtest "SendCirculationAlert" => sub { Link Here
5606
    is($notice->to_address, $patron->smsalertnumber, "Letter has the correct to_address set to smsalertnumber for SMS type notices");
5619
    is($notice->to_address, $patron->smsalertnumber, "Letter has the correct to_address set to smsalertnumber for SMS type notices");
5607
5620
5608
    # Checkout an item, mark it returned, generate a notice
5621
    # Checkout an item, mark it returned, generate a notice
5609
    my $issue_2 = AddIssue( $patron->unblessed, $item->barcode);
5622
    my $issue_2 = AddIssue( $patron, $item->barcode);
5610
    MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0, { skip_record_index => 1} );
5623
    MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0, { skip_record_index => 1} );
5611
    C4::Circulation::SendCirculationAlert({
5624
    C4::Circulation::SendCirculationAlert({
5612
        type => 'CHECKIN',
5625
        type => 'CHECKIN',
Lines 5640-5646 subtest "GetSoonestRenewDate tests" => sub { Link Here
5640
        }
5653
        }
5641
    );
5654
    );
5642
    my $item = $builder->build_sample_item();
5655
    my $item = $builder->build_sample_item();
5643
    my $issue = AddIssue( $patron->unblessed, $item->barcode);
5656
    my $issue = AddIssue( $patron, $item->barcode);
5644
    my $datedue = dt_from_string( $issue->date_due() );
5657
    my $datedue = dt_from_string( $issue->date_due() );
5645
5658
5646
    # Bug 14395
5659
    # Bug 14395
(-)a/t/db_dependent/Circulation/CalcDateDue.t (-17 / +33 lines)
Lines 18-26 my $schema = Koha::Database->new->schema; Link Here
18
$schema->storage->txn_begin;
18
$schema->storage->txn_begin;
19
my $builder = t::lib::TestBuilder->new;
19
my $builder = t::lib::TestBuilder->new;
20
20
21
my $categorycode = 'B';
21
22
my $itemtype = 'MX';
22
my $library = $builder->build_object({ class => 'Koha::Libraries' })->store;
23
my $branchcode = 'FPL';
23
my $dateexpiry = '2013-01-01';
24
my $patron_category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { category_type => 'B' } })->store;
25
my $borrower = $builder->build_object(
26
    {
27
        class  => 'Koha::Patrons',
28
        value  => {
29
            categorycode => $patron_category->categorycode,
30
            dateexpiry => $dateexpiry,
31
        }
32
    }
33
)->store;
34
35
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' })->store->itemtype;
24
my $issuelength = 10;
36
my $issuelength = 10;
25
my $renewalperiod = 5;
37
my $renewalperiod = 5;
26
my $lengthunit = 'days';
38
my $lengthunit = 'days';
Lines 28-36 my $lengthunit = 'days'; Link Here
28
Koha::CirculationRules->search()->delete();
40
Koha::CirculationRules->search()->delete();
29
Koha::CirculationRules->set_rules(
41
Koha::CirculationRules->set_rules(
30
    {
42
    {
31
        categorycode => $categorycode,
43
        categorycode => $patron_category->categorycode,
32
        itemtype     => $itemtype,
44
        itemtype     => $itemtype,
33
        branchcode   => $branchcode,
45
        branchcode   => $library->branchcode,
34
        rules        => {
46
        rules        => {
35
            issuelength   => $issuelength,
47
            issuelength   => $issuelength,
36
            renewalperiod => $renewalperiod,
48
            renewalperiod => $renewalperiod,
Lines 43-55 Koha::CirculationRules->set_rules( Link Here
43
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1);
55
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1);
44
t::lib::Mocks::mock_preference('useDaysMode', 'Days');
56
t::lib::Mocks::mock_preference('useDaysMode', 'Days');
45
57
58
my $branchcode = $library->branchcode;
59
46
my $cache = Koha::Caches->get_instance();
60
my $cache = Koha::Caches->get_instance();
47
my $key   = $branchcode . "_holidays";
61
my $key   = $branchcode . "_holidays";
48
$cache->clear_from_cache($key);
62
$cache->clear_from_cache($key);
49
63
50
my $dateexpiry = '2013-01-01';
51
52
my $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
53
my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
64
my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
54
my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
65
my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
55
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
66
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
Lines 60-66 $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borr Link Here
60
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1);
71
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1);
61
t::lib::Mocks::mock_preference('useDaysMode', 'noDays');
72
t::lib::Mocks::mock_preference('useDaysMode', 'noDays');
62
73
63
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
64
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
74
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
65
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
75
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
66
is($date, $dateexpiry . 'T23:59:00', 'date expiry with useDaysMode to noDays');
76
is($date, $dateexpiry . 'T23:59:00', 'date expiry with useDaysMode to noDays');
Lines 95-101 $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borr Link Here
95
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 0);
105
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 0);
96
t::lib::Mocks::mock_preference('useDaysMode', 'Days');
106
t::lib::Mocks::mock_preference('useDaysMode', 'Days');
97
107
98
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
99
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
108
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
100
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
109
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
101
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
110
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
Lines 158-175 $calendar->delete_holiday( Link Here
158
167
159
# Now we test it does the right thing if the loan and renewal periods
168
# Now we test it does the right thing if the loan and renewal periods
160
# are a multiple of 7 days
169
# are a multiple of 7 days
161
my $dayweek_categorycode = 'K';
162
my $dayweek_itemtype = 'MX';
163
my $dayweek_branchcode = 'FPL';
164
my $dayweek_issuelength = 14;
170
my $dayweek_issuelength = 14;
165
my $dayweek_renewalperiod = 7;
171
my $dayweek_renewalperiod = 7;
166
my $dayweek_lengthunit = 'days';
172
my $dayweek_lengthunit = 'days';
167
173
174
$patron_category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { category_type => 'K' } })->store;
175
168
Koha::CirculationRules->set_rules(
176
Koha::CirculationRules->set_rules(
169
    {
177
    {
170
        categorycode => $dayweek_categorycode,
178
        categorycode => $patron_category->categorycode,
171
        itemtype     => $dayweek_itemtype,
179
        itemtype     => $itemtype,
172
        branchcode   => $dayweek_branchcode,
180
        branchcode   => $branchcode,
173
        rules        => {
181
        rules        => {
174
            issuelength   => $dayweek_issuelength,
182
            issuelength   => $dayweek_issuelength,
175
            renewalperiod => $dayweek_renewalperiod,
183
            renewalperiod => $dayweek_renewalperiod,
Lines 178-184 Koha::CirculationRules->set_rules( Link Here
178
    }
186
    }
179
);
187
);
180
188
181
my $dayweek_borrower = {categorycode => 'K', dateexpiry => $dateexpiry};
189
my $dayweek_borrower = $builder->build_object(
190
    {
191
        class  => 'Koha::Patrons',
192
        value  => {
193
            categorycode => $patron_category->categorycode,
194
            dateexpiry => $dateexpiry,
195
        }
196
    }
197
);
182
198
183
# For issues...
199
# For issues...
184
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
200
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
(-)a/t/db_dependent/Circulation/CheckIfIssuedToPatron.t (-7 / +27 lines)
Lines 66-76 my ($biblionumber2) = AddBiblio(MARC::Record->new, ''); Link Here
66
my $barcode2 = '0202';
66
my $barcode2 = '0202';
67
Koha::Item->new({ barcode => $barcode2, %item_info, biblionumber => $biblionumber2 })->store;
67
Koha::Item->new({ barcode => $barcode2, %item_info, biblionumber => $biblionumber2 })->store;
68
68
69
my $borrowernumber1 = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode})->store->borrowernumber;
69
my $patron1 = $builder->build_object(
70
my $borrowernumber2 = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode})->store->borrowernumber;
70
    {
71
# FIXME following code must be simplified to use the Koha::Patron objects
71
        class => 'Koha::Patrons'
72
my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed;
72
        value => {
73
my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed;
73
            {
74
                categorycode => $categorycode,
75
                branchcode => $branchcode
76
            }
77
        }
78
    }
79
);
80
my $patron2 = $builder->build_object(
81
    {
82
        class => 'Koha::Patrons'
83
        value => {
84
            {
85
                categorycode => $categorycode,
86
                branchcode => $branchcode
87
            }
88
        }
89
    }
90
);
91
92
my $borrowernumber1 = $patron1->borrowernumber;
93
my $borrowernumber2 = $patron2->borrowernumber;
74
94
75
my $module = Test::MockModule->new('C4::Context');
95
my $module = Test::MockModule->new('C4::Context');
76
$module->mock('userenv', sub { { branch => $branchcode } });
96
$module->mock('userenv', sub { { branch => $branchcode } });
Lines 91-97 is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' ); Link Here
91
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2);
111
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2);
92
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
112
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
93
113
94
AddIssue($borrower1, '0101');
114
AddIssue($patron1, '0101');
95
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron();
115
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron();
96
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
116
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
97
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron(undef, $biblionumber1);
117
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron(undef, $biblionumber1);
Lines 107-113 is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' ); Link Here
107
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2);
127
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2);
108
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
128
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
109
129
110
AddIssue($borrower2, '0202');
130
AddIssue($patron2, '0202');
111
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron();
131
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron();
112
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
132
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
113
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron(undef, $biblionumber1);
133
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron(undef, $biblionumber1);
(-)a/t/db_dependent/Circulation/GetPendingOnSiteCheckouts.t (-8 / +6 lines)
Lines 57-82 my ($biblionumber2) = AddBiblio(MARC::Record->new, ''); Link Here
57
my $itemnumber3 = Koha::Item->new({ barcode => '0203', %item_infos, biblionumber => $biblionumber2})->store->itemnumber;
57
my $itemnumber3 = Koha::Item->new({ barcode => '0203', %item_infos, biblionumber => $biblionumber2})->store->itemnumber;
58
58
59
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
59
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
60
my $borrowernumber = $builder->build(
60
my $patron = $builder->build_object(
61
    {   source => 'Borrower',
61
    {   class => 'Koha::Patrons',
62
        value  => { categorycode => $categorycode, branchcode => $branchcode }
62
        value  => { categorycode => $categorycode, branchcode => $branchcode }
63
    }
63
    }
64
)->{borrowernumber};
64
);
65
66
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
67
65
68
# Need to mock userenv for AddIssue
66
# Need to mock userenv for AddIssue
69
my $module = Test::MockModule->new('C4::Context');
67
my $module = Test::MockModule->new('C4::Context');
70
$module->mock('userenv', sub { { branch => $branchcode } });
68
$module->mock('userenv', sub { { branch => $branchcode } });
71
AddIssue($borrower, '0101');
69
AddIssue($patron, '0101');
72
AddIssue($borrower, '0203');
70
AddIssue($patron, '0203');
73
71
74
# Begin tests...
72
# Begin tests...
75
my $onsite_checkouts = GetPendingOnSiteCheckouts;
73
my $onsite_checkouts = GetPendingOnSiteCheckouts;
76
is( scalar @$onsite_checkouts, 0, "No pending on-site checkouts" );
74
is( scalar @$onsite_checkouts, 0, "No pending on-site checkouts" );
77
75
78
my $itemnumber4 = Koha::Item->new({ barcode => '0104', %item_infos, biblionumber => $biblionumber1})->store->itemnumber;
76
my $itemnumber4 = Koha::Item->new({ barcode => '0104', %item_infos, biblionumber => $biblionumber1})->store->itemnumber;
79
AddIssue( $borrower, '0104', undef, undef, undef, undef, { onsite_checkout => 1 } );
77
AddIssue( $patron, '0104', undef, undef, undef, undef, { onsite_checkout => 1 } );
80
$onsite_checkouts = GetPendingOnSiteCheckouts;
78
$onsite_checkouts = GetPendingOnSiteCheckouts;
81
is( scalar @$onsite_checkouts, 1, "There is 1 pending on-site checkout" );
79
is( scalar @$onsite_checkouts, 1, "There is 1 pending on-site checkout" );
82
80
(-)a/t/db_dependent/Circulation/GetTopIssues.t (-1 / +1 lines)
Lines 68-74 my $borrowernumber = Koha::Patron->new({ Link Here
68
    categorycode => $category,
68
    categorycode => $category,
69
    branchcode => $branch_1->{ branchcode }
69
    branchcode => $branch_1->{ branchcode }
70
})->store->borrowernumber;
70
})->store->borrowernumber;
71
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
71
my $borrower = Koha::Patrons->find( $borrowernumber );
72
72
73
AddIssue($borrower, 'GTI_BARCODE_001');
73
AddIssue($borrower, 'GTI_BARCODE_001');
74
AddIssue($borrower, 'GTI_BARCODE_002');
74
AddIssue($borrower, 'GTI_BARCODE_002');
(-)a/t/db_dependent/Circulation/IsItemIssued.t (-3 / +3 lines)
Lines 42-55 my $patron_category = $builder->build({ source => 'Category' }); Link Here
42
42
43
t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
43
t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
44
44
45
my $borrowernumber = Koha::Patron->new({
45
my $borrower = Koha::Patron->new({
46
    firstname =>  'my firstname',
46
    firstname =>  'my firstname',
47
    surname => 'my surname',
47
    surname => 'my surname',
48
    categorycode => $patron_category->{categorycode},
48
    categorycode => $patron_category->{categorycode},
49
    branchcode => $library->{branchcode},
49
    branchcode => $library->{branchcode},
50
})->store->borrowernumber;
50
})->store;
51
51
52
52
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
53
my $record = MARC::Record->new();
53
my $record = MARC::Record->new();
54
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
54
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '' );
55
55
(-)a/t/db_dependent/Circulation/MarkIssueReturned.t (-8 / +8 lines)
Lines 63-69 subtest 'Failure tests' => sub { Link Here
63
    is( $issue_id, undef, 'No issue_id returned' );
63
    is( $issue_id, undef, 'No issue_id returned' );
64
64
65
    # In the next call we return the item and try it another time
65
    # In the next call we return the item and try it another time
66
    $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
66
    $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
67
    eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0 ) };
67
    eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0 ) };
68
    is( $issue_id, $issue->issue_id, "Item has been returned (issue $issue_id)" );
68
    is( $issue_id, $issue->issue_id, "Item has been returned (issue $issue_id)" );
69
    eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0 ) };
69
    eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 0 ) };
Lines 98-104 subtest 'Anonymous patron tests' => sub { Link Here
98
    # Anonymous patron not set
98
    # Anonymous patron not set
99
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
99
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
100
100
101
    my $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
101
    my $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
102
102
103
    throws_ok
103
    throws_ok
104
        { C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 2 ); }
104
        { C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 2 ); }
Lines 117-123 subtest 'Anonymous patron tests' => sub { Link Here
117
        }
117
        }
118
    });
118
    });
119
    t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous->borrowernumber);
119
    t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous->borrowernumber);
120
    $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
120
    $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
121
121
122
    eval { C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 2 ) };
122
    eval { C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 2 ) };
123
    is ( $@, q||, 'AnonymousPatron is set correctly - no error expected');
123
    is ( $@, q||, 'AnonymousPatron is set correctly - no error expected');
Lines 148-161 subtest 'Manually pass a return date' => sub { Link Here
148
148
149
    my ( $issue, $issue_id );
149
    my ( $issue, $issue_id );
150
150
151
    $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
151
    $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
152
    $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, '2018-12-25', 0 );
152
    $issue_id = C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, '2018-12-25', 0 );
153
153
154
    is( $issue_id, $issue->issue_id, "Item has been returned" );
154
    is( $issue_id, $issue->issue_id, "Item has been returned" );
155
    my $old_checkout = Koha::Old::Checkouts->find( $issue_id );
155
    my $old_checkout = Koha::Old::Checkouts->find( $issue_id );
156
    is( $old_checkout->returndate, '2018-12-25 00:00:00', 'Manually passed date stored correctly' );
156
    is( $old_checkout->returndate, '2018-12-25 00:00:00', 'Manually passed date stored correctly' );
157
157
158
    $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
158
    $issue = C4::Circulation::AddIssue( $patron, $item->barcode );
159
159
160
    {
160
    {
161
        # Hiding the expected warning displayed by DBI
161
        # Hiding the expected warning displayed by DBI
Lines 185-193 subtest 'AutoRemoveOverduesRestrictions' => sub { Link Here
185
    my $item_2 = $builder->build_sample_item;
185
    my $item_2 = $builder->build_sample_item;
186
    my $item_3 = $builder->build_sample_item;
186
    my $item_3 = $builder->build_sample_item;
187
    my $five_days_ago = dt_from_string->subtract( days => 5 );
187
    my $five_days_ago = dt_from_string->subtract( days => 5 );
188
    my $checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $five_days_ago ); # overdue
188
    my $checkout_1 = AddIssue( $patron, $item_1->barcode, $five_days_ago ); # overdue
189
    my $checkout_2 = AddIssue( $patron->unblessed, $item_2->barcode, $five_days_ago ); # overdue
189
    my $checkout_2 = AddIssue( $patron, $item_2->barcode, $five_days_ago ); # overdue
190
    my $checkout_3 = AddIssue( $patron->unblessed, $item_3->barcode ); # not overdue
190
    my $checkout_3 = AddIssue( $patron, $item_3->barcode ); # not overdue
191
191
192
    Koha::Patron::Debarments::AddUniqueDebarment(
192
    Koha::Patron::Debarments::AddUniqueDebarment(
193
        {
193
        {
(-)a/t/db_dependent/Circulation/ReturnClaims.t (-3 / +3 lines)
Lines 65-71 subtest 'Test Koha::Checkout::claim_returned, do not mark as returned' => sub { Link Here
65
    t::lib::Mocks::mock_preference( 'MarkLostItemsAsReturned', q{} );
65
    t::lib::Mocks::mock_preference( 'MarkLostItemsAsReturned', q{} );
66
    my $item   = $builder->build_sample_item;
66
    my $item   = $builder->build_sample_item;
67
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
67
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
68
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
68
    my $checkout = AddIssue( $patron, $item->barcode );
69
69
70
    my $claim = $checkout->claim_returned(
70
    my $claim = $checkout->claim_returned(
71
        {
71
        {
Lines 91-97 subtest 'Test Koha::Patronn::return_claims' => sub { Link Here
91
    t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', 1 );
91
    t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', 1 );
92
    my $item   = $builder->build_sample_item;
92
    my $item   = $builder->build_sample_item;
93
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
93
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
94
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
94
    my $checkout = AddIssue( $patron, $item->barcode );
95
95
96
    $checkout->claim_returned(
96
    $checkout->claim_returned(
97
        {
97
        {
Lines 121-127 subtest 'Test Koha::Checkout::claim_returned, mark as returned' => sub { Link Here
121
    t::lib::Mocks::mock_preference( 'MarkLostItemsAsReturned', q{claim_returned} );
121
    t::lib::Mocks::mock_preference( 'MarkLostItemsAsReturned', q{claim_returned} );
122
    my $item     = $builder->build_sample_item;
122
    my $item     = $builder->build_sample_item;
123
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
123
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
124
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
124
    my $checkout = AddIssue( $patron, $item->barcode );
125
125
126
    my $claim = $checkout->claim_returned(
126
    my $claim = $checkout->claim_returned(
127
        {
127
        {
(-)a/t/db_dependent/Circulation/Returns.t (-22 / +21 lines)
Lines 86-95 subtest "AddReturn logging on statistics table (item-level_itypes=1)" => sub { Link Here
86
    # Create a branch
86
    # Create a branch
87
    $branch = $builder->build({ source => 'Branch' })->{ branchcode };
87
    $branch = $builder->build({ source => 'Branch' })->{ branchcode };
88
    # Create a borrower
88
    # Create a borrower
89
    my $borrowernumber = $builder->build({
89
    my $patron = $builder->build_object({
90
        source => 'Borrower',
90
        class => 'Koha::Patrons',
91
        value => { branchcode => $branch }
91
        value => { branchcode => $branch }
92
    })->{ borrowernumber };
92
    });
93
    # Look for the defined MARC field for biblio-level itemtype
93
    # Look for the defined MARC field for biblio-level itemtype
94
    my $rs = $schema->resultset('MarcSubfieldStructure')->search({
94
    my $rs = $schema->resultset('MarcSubfieldStructure')->search({
95
        frameworkcode => '',
95
        frameworkcode => '',
Lines 118-125 subtest "AddReturn logging on statistics table (item-level_itypes=1)" => sub { Link Here
118
        }
118
        }
119
    )->_result->update({ itype => undef });
119
    )->_result->update({ itype => undef });
120
120
121
    my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
121
    AddIssue( $patron, $item_with_itemtype->barcode );
122
    AddIssue( $borrower, $item_with_itemtype->barcode );
123
    AddReturn( $item_with_itemtype->barcode, $branch );
122
    AddReturn( $item_with_itemtype->barcode, $branch );
124
    # Test item-level itemtype was recorded on the 'statistics' table
123
    # Test item-level itemtype was recorded on the 'statistics' table
125
    my $stat = $schema->resultset('Statistic')->search({
124
    my $stat = $schema->resultset('Statistic')->search({
Lines 130-137 subtest "AddReturn logging on statistics table (item-level_itypes=1)" => sub { Link Here
130
129
131
    is( $stat->itemtype, $ilevel_itemtype,
130
    is( $stat->itemtype, $ilevel_itemtype,
132
        "item-level itype recorded on statistics for return");
131
        "item-level itype recorded on statistics for return");
133
    warning_like { AddIssue( $borrower, $item_without_itemtype->barcode ) }
132
    warning_like { AddIssue( $patron, $item_without_itemtype->barcode ) }
134
                 [qr/^item-level_itypes set but no itemtype set for item/,
133
                 [qr/^item-level_itypes set but no itemtype set for item/,
134
                 qr/^item-level_itypes set but no itemtype set for item/,
135
                 qr/^item-level_itypes set but no itemtype set for item/],
135
                 qr/^item-level_itypes set but no itemtype set for item/],
136
                 'Item without itemtype set raises warning on AddIssue';
136
                 'Item without itemtype set raises warning on AddIssue';
137
    AddReturn( $item_without_itemtype->barcode, $branch );
137
    AddReturn( $item_without_itemtype->barcode, $branch );
Lines 165-172 subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub { Link Here
165
    # Create a branch
165
    # Create a branch
166
    $branch = $builder->build({ source => 'Branch' })->{ branchcode };
166
    $branch = $builder->build({ source => 'Branch' })->{ branchcode };
167
    # Create a borrower
167
    # Create a borrower
168
    my $borrowernumber = $builder->build({
168
    my $patron = $builder->build_object({
169
        source => 'Borrower',
169
        class => 'Koha::Patrons',
170
        value => { branchcode => $branch }
170
        value => { branchcode => $branch }
171
    })->{ borrowernumber };
171
    })->{ borrowernumber };
172
    # Look for the defined MARC field for biblio-level itemtype
172
    # Look for the defined MARC field for biblio-level itemtype
Lines 198-206 subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub { Link Here
198
        }
198
        }
199
    );
199
    );
200
200
201
    my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
201
    AddIssue( $patron, $item_with_itemtype->barcode );
202
203
    AddIssue( $borrower, $item_with_itemtype->barcode );
204
    AddReturn( $item_with_itemtype->barcode, $branch );
202
    AddReturn( $item_with_itemtype->barcode, $branch );
205
    # Test item-level itemtype was recorded on the 'statistics' table
203
    # Test item-level itemtype was recorded on the 'statistics' table
206
    my $stat = $schema->resultset('Statistic')->search({
204
    my $stat = $schema->resultset('Statistic')->search({
Lines 212-218 subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub { Link Here
212
    is( $stat->itemtype, $blevel_itemtype,
210
    is( $stat->itemtype, $blevel_itemtype,
213
        "biblio-level itype recorded on statistics for return");
211
        "biblio-level itype recorded on statistics for return");
214
212
215
    AddIssue( $borrower, $item_without_itemtype->barcode );
213
    AddIssue( $patron, $item_without_itemtype->barcode );
216
    AddReturn( $item_without_itemtype->barcode, $branch );
214
    AddReturn( $item_without_itemtype->barcode, $branch );
217
    # Test biblio-level itemtype was recorded on the 'statistics' table
215
    # Test biblio-level itemtype was recorded on the 'statistics' table
218
    $stat = $schema->resultset('Statistic')->search({
216
    $stat = $schema->resultset('Statistic')->search({
Lines 250-259 subtest 'Handle ids duplication' => sub { Link Here
250
            itype => $itemtype->{itemtype},
248
            itype => $itemtype->{itemtype},
251
        }
249
        }
252
    );
250
    );
253
    my $patron = $builder->build({source => 'Borrower'});
251
    my $patron = $builder->build_object(
254
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
252
        { class => 'Koha::Patrons'}
253
    );
255
254
256
    my $original_checkout = AddIssue( $patron->unblessed, $item->barcode, dt_from_string->subtract( days => 50 ) );
255
    my $original_checkout = AddIssue( $patron, $item->barcode, dt_from_string->subtract( days => 50 ) );
257
    my $issue_id = $original_checkout->issue_id;
256
    my $issue_id = $original_checkout->issue_id;
258
    my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id });
257
    my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id });
259
    is( $account_lines->count, 1, '1 account line should exist for this issue_id' );
258
    is( $account_lines->count, 1, '1 account line should exist for this issue_id' );
Lines 280-286 subtest 'Handle ids duplication' => sub { Link Here
280
    is( $messages->{WasReturned}, 0, 'messages should have the WasReturned flag set to 0' );
279
    is( $messages->{WasReturned}, 0, 'messages should have the WasReturned flag set to 0' );
281
    is( $messages->{DataCorrupted}, 1, 'messages should have the DataCorrupted flag set to 1' );
280
    is( $messages->{DataCorrupted}, 1, 'messages should have the DataCorrupted flag set to 1' );
282
281
283
    $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id });
282
    $account_lines = Koha::Account::Lines->search({ borrowernumber => $borrower->{borrowernumber}, issue_id => $issue_id });
284
    is( $account_lines->count, 0, 'No account lines should exist for this issue_id, patron should not have been charged' );
283
    is( $account_lines->count, 0, 'No account lines should exist for this issue_id, patron should not have been charged' );
285
284
286
    is( Koha::Checkouts->find( $issue_id )->issue_id, $issue_id, 'The issues entry should not have been removed' );
285
    is( Koha::Checkouts->find( $issue_id )->issue_id, $issue_id, 'The issues entry should not have been removed' );
Lines 289-296 subtest 'Handle ids duplication' => sub { Link Here
289
subtest 'BlockReturnOfLostItems' => sub {
288
subtest 'BlockReturnOfLostItems' => sub {
290
    plan tests => 4;
289
    plan tests => 4;
291
    my $item = $builder->build_sample_item;
290
    my $item = $builder->build_sample_item;
292
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
291
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
293
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
292
    my $checkout = AddIssue( $patron, $item->barcode );
294
293
295
    # Mark the item as lost
294
    # Mark the item as lost
296
    $item->itemlost(1)->store;
295
    $item->itemlost(1)->store;
Lines 314-320 subtest 'Checkin of an item claimed as returned should generate a message' => su Link Here
314
    t::lib::Mocks::mock_preference('ClaimReturnedLostValue', 1);
313
    t::lib::Mocks::mock_preference('ClaimReturnedLostValue', 1);
315
    my $item = $builder->build_sample_item;
314
    my $item = $builder->build_sample_item;
316
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
315
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
317
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
316
    my $checkout = AddIssue( $patron, $item->barcode );
318
317
319
    $checkout->claim_returned({ created_by => $patron->id });
318
    $checkout->claim_returned({ created_by => $patron->id });
320
319
Lines 331-342 subtest 'BranchTransferLimitsType' => sub { Link Here
331
330
332
    my $item = $builder->build_sample_item;
331
    my $item = $builder->build_sample_item;
333
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
332
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
334
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
333
    my $checkout = AddIssue( $patron, $item->barcode );
335
    my ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
334
    my ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
336
    is( $doreturn, 1, 'AddReturn should have checkin the item if BranchTransferLimitsType=ccode');
335
    is( $doreturn, 1, 'AddReturn should have checkin the item if BranchTransferLimitsType=ccode');
337
336
338
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
337
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
339
    $checkout = AddIssue( $patron->unblessed, $item->barcode );
338
    $checkout = AddIssue( $patron, $item->barcode );
340
    ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
339
    ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
341
    is( $doreturn, 1, 'AddReturn should have checkin the item if BranchTransferLimitsType=itemtype');
340
    is( $doreturn, 1, 'AddReturn should have checkin the item if BranchTransferLimitsType=itemtype');
342
};
341
};
Lines 350-356 subtest 'Backdated returns should reduce fine if needed' => sub { Link Here
350
    my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
349
    my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
351
    my $item = $builder->build_sample_item;
350
    my $item = $builder->build_sample_item;
352
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
351
    my $patron = $builder->build_object({class => 'Koha::Patrons'});
353
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
352
    my $checkout = AddIssue( $patron, $item->barcode );
354
    my $fine = Koha::Account::Line->new({
353
    my $fine = Koha::Account::Line->new({
355
        issue_id => $checkout->id,
354
        issue_id => $checkout->id,
356
        borrowernumber => $patron->id,
355
        borrowernumber => $patron->id,
(-)a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t (-4 / +3 lines)
Lines 55-61 my $patron = $builder->build_object({ Link Here
55
        categorycode => $patron_category->{categorycode},
55
        categorycode => $patron_category->{categorycode},
56
    },
56
    },
57
});
57
});
58
my $patron_unblessed = $patron->unblessed;
59
58
60
my $item = $builder->build_sample_item(
59
my $item = $builder->build_sample_item(
61
    {
60
    {
Lines 85-91 t::lib::Mocks::mock_userenv({ patron => $patron }); Link Here
85
t::lib::Mocks::mock_preference('AllowTooManyOverride', 0);
84
t::lib::Mocks::mock_preference('AllowTooManyOverride', 0);
86
85
87
# Add onsite checkout
86
# Add onsite checkout
88
C4::Circulation::AddIssue( $patron_unblessed, $item->barcode, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
87
C4::Circulation::AddIssue( $patron, $item->barcode, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
89
88
90
my ( $impossible, $messages );
89
my ( $impossible, $messages );
91
t::lib::Mocks::mock_preference('SwitchOnSiteCheckouts', 0);
90
t::lib::Mocks::mock_preference('SwitchOnSiteCheckouts', 0);
Lines 96-102 t::lib::Mocks::mock_preference('SwitchOnSiteCheckouts', 1); Link Here
96
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $item->barcode );
95
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $item->barcode );
97
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'If SwitchOnSiteCheckouts, switch the on-site checkout' );
96
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'If SwitchOnSiteCheckouts, switch the on-site checkout' );
98
is( exists $impossible->{TOO_MANY}, '', 'If SwitchOnSiteCheckouts, switch the on-site checkout' );
97
is( exists $impossible->{TOO_MANY}, '', 'If SwitchOnSiteCheckouts, switch the on-site checkout' );
99
C4::Circulation::AddIssue( $patron_unblessed, $item->barcode, undef, undef, undef, undef, { switch_onsite_checkout => 1 } );
98
C4::Circulation::AddIssue( $patron, $item->barcode, undef, undef, undef, undef, { switch_onsite_checkout => 1 } );
100
my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
99
my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
101
is( $issue->onsite_checkout, 0, 'The issue should have been switched to a regular checkout' );
100
is( $issue->onsite_checkout, 0, 'The issue should have been switched to a regular checkout' );
102
my $five_days_after = dt_from_string->add( days => 5 )->set( hour => 23, minute => 59, second => 0 );
101
my $five_days_after = dt_from_string->add( days => 5 )->set( hour => 23, minute => 59, second => 0 );
Lines 111-117 my $another_item = $builder->build_sample_item( Link Here
111
    }
110
    }
112
);
111
);
113
112
114
C4::Circulation::AddIssue( $patron_unblessed, $another_item->barcode, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
113
C4::Circulation::AddIssue( $patron, $another_item->barcode, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
115
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->barcode );
114
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->barcode );
116
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 1 - Switch is allowed' );
115
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 1 - Switch is allowed' );
117
is( exists $impossible->{TOO_MANY}, '', 'Specific case 1 - Switch is allowed' );
116
is( exists $impossible->{TOO_MANY}, '', 'Specific case 1 - Switch is allowed' );
(-)a/t/db_dependent/Circulation/TooMany.t (-9 / +8 lines)
Lines 39-45 our $dbh = C4::Context->dbh; Link Here
39
$dbh->do(q|DELETE FROM issues|);
39
$dbh->do(q|DELETE FROM issues|);
40
$dbh->do(q|DELETE FROM items|);
40
$dbh->do(q|DELETE FROM items|);
41
$dbh->do(q|DELETE FROM borrowers|);
41
$dbh->do(q|DELETE FROM borrowers|);
42
$dbh->do(q|DELETE FROM branches|);
42
#$dbh->do(q|DELETE FROM branches|);
43
$dbh->do(q|DELETE FROM categories|);
43
$dbh->do(q|DELETE FROM categories|);
44
$dbh->do(q|DELETE FROM accountlines|);
44
$dbh->do(q|DELETE FROM accountlines|);
45
$dbh->do(q|DELETE FROM itemtypes|);
45
$dbh->do(q|DELETE FROM itemtypes|);
Lines 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/dateexpiry.t (-9 / +11 lines)
Lines 91-115 sub calc_date_due { Link Here
91
91
92
    # this triggers the compare between expiry and due date
92
    # this triggers the compare between expiry and due date
93
93
94
    my $patron = $builder->build({
94
    my $patron = $builder->build_object(
95
        source => 'Borrower',
95
        {
96
        value  => {
96
            class  => 'Koha::Patrons',
97
            categorycode => $patron_category->{categorycode},
97
            value  => {
98
                categorycode => $patron_category->{categorycode},
99
            }
98
        }
100
        }
99
    });
101
    );
100
    my $item   = $builder->build_sample_item;
102
    my $item   = $builder->build_sample_item;
101
    my $branch = $builder->build( { source => 'Branch' } );
103
    my $branch = $builder->build( { source => 'Branch' } );
102
    my $today  = dt_from_string();
104
    my $today  = dt_from_string();
103
105
104
    # first test with empty expiry date
106
    # first test with empty expiry date
105
    # note that this expiry date will never lead to an issue btw !!
107
    # note that this expiry date will never lead to an issue btw !!
106
    $patron->{dateexpiry} = undef;
108
    $patron->dateexpiry(undef)->store;
107
    my $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
109
    my $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
108
    is( ref $d eq "DateTime" && $d->mdy() =~ /^\d+/, 1, "CalcDateDue with expiry undef" );
110
    is( ref $d eq "DateTime" && $d->mdy() =~ /^\d+/, 1, "CalcDateDue with expiry undef" );
109
111
110
    # second test expiry date==today
112
    # second test expiry date==today
111
    my $d2 = output_pref( { dt => $today, dateonly => 1, dateformat => 'sql' } );
113
    my $d2 = output_pref( { dt => $today, dateonly => 1, dateformat => 'sql' } );
112
    $patron->{dateexpiry} = $d2;
114
    $patron->dateexpiry($d2)->store;
113
    $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
115
    $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
114
    is( ref $d eq "DateTime" && DateTime->compare( $d->truncate( to => 'day' ), $today->truncate( to => 'day' ) ) == 0, 1, "CalcDateDue with expiry today" );
116
    is( ref $d eq "DateTime" && DateTime->compare( $d->truncate( to => 'day' ), $today->truncate( to => 'day' ) ) == 0, 1, "CalcDateDue with expiry today" );
115
117
Lines 117-128 sub calc_date_due { Link Here
117
    my $dur = DateTime::Duration->new( days => 1 );
119
    my $dur = DateTime::Duration->new( days => 1 );
118
    my $tomorrow = $today->clone->add_duration($dur);
120
    my $tomorrow = $today->clone->add_duration($dur);
119
    $d2 = output_pref( { dt => $tomorrow, dateonly => 1, dateformat => 'sql' } );
121
    $d2 = output_pref( { dt => $tomorrow, dateonly => 1, dateformat => 'sql' } );
120
    $patron->{dateexpiry} = $d2;
122
    $patron->dateexpiry($d2)->store;
121
    $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
123
    $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
122
    is( ref $d eq "DateTime" && $d->mdy() =~ /^\d+/, 1, "CalcDateDue with expiry tomorrow" );
124
    is( ref $d eq "DateTime" && $d->mdy() =~ /^\d+/, 1, "CalcDateDue with expiry tomorrow" );
123
125
124
    # fourth test far future
126
    # fourth test far future
125
    $patron->{dateexpiry} = '9876-12-31';
127
    $patron->dateexpiry('9876-12-31')->store;
126
    my $t1 = time;
128
    my $t1 = time;
127
    $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
129
    $d = C4::Circulation::CalcDateDue( $today, $item->effective_itemtype, $branch->{branchcode}, $patron );
128
    my $t2 = time;
130
    my $t2 = time;
(-)a/t/db_dependent/Circulation/issue.t (-13 / +11 lines)
Lines 160-166 my $borrower_id1 = Koha::Patron->new({ Link Here
160
    branchcode   => $branchcode_1
160
    branchcode   => $branchcode_1
161
})->store->borrowernumber;
161
})->store->borrowernumber;
162
my $patron_1 = Koha::Patrons->find( $borrower_id1 );
162
my $patron_1 = Koha::Patrons->find( $borrower_id1 );
163
my $borrower_1 = $patron_1->unblessed;
164
my $borrower_id2 = Koha::Patron->new({
163
my $borrower_id2 = Koha::Patron->new({
165
    firstname    => 'firstname2',
164
    firstname    => 'firstname2',
166
    surname      => 'surname2 ',
165
    surname      => 'surname2 ',
Lines 168-174 my $borrower_id2 = Koha::Patron->new({ Link Here
168
    branchcode   => $branchcode_2,
167
    branchcode   => $branchcode_2,
169
})->store->borrowernumber;
168
})->store->borrowernumber;
170
my $patron_2 = Koha::Patrons->find( $borrower_id2 );
169
my $patron_2 = Koha::Patrons->find( $borrower_id2 );
171
my $borrower_2 = $patron_2->unblessed;
172
170
173
t::lib::Mocks::mock_userenv({ patron => $patron_1 });
171
t::lib::Mocks::mock_userenv({ patron => $patron_1 });
174
172
Lines 178-186 t::lib::Mocks::mock_userenv({ patron => $patron_1 }); Link Here
178
my $query = " SELECT count(*) FROM issues";
176
my $query = " SELECT count(*) FROM issues";
179
my $sth = $dbh->prepare($query);
177
my $sth = $dbh->prepare($query);
180
$sth->execute;
178
$sth->execute;
181
my $countissue = $sth -> fetchrow_array;
179
my $countissue = $sth->fetchrow_array;
182
is ($countissue ,0, "there is no issue");
180
is ($countissue ,0, "there is no issue");
183
my $issue1 = C4::Circulation::AddIssue( $borrower_1, $barcode_1, $daysago10,0, $today, '' );
181
my $issue1 = C4::Circulation::AddIssue( $patron_1, $barcode_1, $daysago10, 0, $today, '' );
184
is( ref $issue1, 'Koha::Checkout',
182
is( ref $issue1, 'Koha::Checkout',
185
       'AddIssue returns a Koha::Checkout object' );
183
       'AddIssue returns a Koha::Checkout object' );
186
my $datedue1 = dt_from_string( $issue1->date_due() );
184
my $datedue1 = dt_from_string( $issue1->date_due() );
Lines 191-201 like( Link Here
191
);
189
);
192
my $issue_id1 = $issue1->issue_id;
190
my $issue_id1 = $issue1->issue_id;
193
191
194
my $issue2 = C4::Circulation::AddIssue( $borrower_1, 'nonexistent_barcode' );
192
my $issue2 = C4::Circulation::AddIssue( $patron_1, 'nonexistent_barcode' );
195
is( $issue2, undef, "AddIssue returns undef if no datedue is specified" );
193
is( $issue2, undef, "AddIssue returns undef if no datedue is specified" );
196
194
197
$sth->execute;
195
$sth->execute;
198
$countissue = $sth -> fetchrow_array;
196
$countissue = $sth->fetchrow_array;
199
is ($countissue,1,"1 issues have been added");
197
is ($countissue,1,"1 issues have been added");
200
198
201
#Test AddIssuingCharge
199
#Test AddIssuingCharge
Lines 263-269 subtest 'Show that AddRenewal respects OpacRenewalBranch and interface' => sub { Link Here
263
            my $item = $builder->build_sample_item(
261
            my $item = $builder->build_sample_item(
264
                { library => $item_library->branchcode, itype => $itemtype } );
262
                { library => $item_library->branchcode, itype => $itemtype } );
265
            my $opac_renew_issue =
263
            my $opac_renew_issue =
266
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
264
              C4::Circulation::AddIssue( $patron, $item->barcode );
267
265
268
            AddRenewal( $patron->borrowernumber, $item->itemnumber,
266
            AddRenewal( $patron->borrowernumber, $item->itemnumber,
269
                "Stavromula", $datedue1, $daysago10 );
267
                "Stavromula", $datedue1, $daysago10 );
Lines 281-287 subtest 'Show that AddRenewal respects OpacRenewalBranch and interface' => sub { Link Here
281
            my $item = $builder->build_sample_item(
279
            my $item = $builder->build_sample_item(
282
                { library => $item_library->branchcode, itype => $itemtype } );
280
                { library => $item_library->branchcode, itype => $itemtype } );
283
            my $opac_renew_issue =
281
            my $opac_renew_issue =
284
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
282
              C4::Circulation::AddIssue( $patron, $item->barcode );
285
283
286
            AddRenewal( $patron->borrowernumber, $item->itemnumber,
284
            AddRenewal( $patron->borrowernumber, $item->itemnumber,
287
                "Stavromula", $datedue1, $daysago10 );
285
                "Stavromula", $datedue1, $daysago10 );
Lines 298-304 subtest 'Show that AddRenewal respects OpacRenewalBranch and interface' => sub { Link Here
298
296
299
my @renewcount;
297
my @renewcount;
300
#Test GetRenewCount
298
#Test GetRenewCount
301
my $issue3 = C4::Circulation::AddIssue( $borrower_1, $barcode_1 );
299
my $issue3 = C4::Circulation::AddIssue( $patron_1, $barcode_1 );
302
#Without anything in DB
300
#Without anything in DB
303
@renewcount = C4::Circulation::GetRenewCount();
301
@renewcount = C4::Circulation::GetRenewCount();
304
is_deeply(
302
is_deeply(
Lines 372-378 my $return = $dbh->selectrow_hashref("SELECT DATE(returndate) AS return_date, CU Link Here
372
ok( $return->{return_date} eq $return->{today}, "Item returned with no return date specified has todays date" );
370
ok( $return->{return_date} eq $return->{today}, "Item returned with no return date specified has todays date" );
373
371
374
$dbh->do("DELETE FROM old_issues");
372
$dbh->do("DELETE FROM old_issues");
375
C4::Circulation::AddIssue( $borrower_1, $barcode_1, $daysago10, 0, $today );
373
C4::Circulation::AddIssue( $patron_1, $barcode_1, $daysago10, 0, $today );
376
AddReturn($barcode_1, undef, undef, dt_from_string('2014-04-01 23:42'));
374
AddReturn($barcode_1, undef, undef, dt_from_string('2014-04-01 23:42'));
377
$return = $dbh->selectrow_hashref("SELECT * FROM old_issues LIMIT 1" );
375
$return = $dbh->selectrow_hashref("SELECT * FROM old_issues LIMIT 1" );
378
ok( $return->{returndate} eq '2014-04-01 23:42:00', "Item returned with a return date of '2014-04-01 23:42' has that return date" );
376
ok( $return->{returndate} eq '2014-04-01 23:42:00', "Item returned with a return date of '2014-04-01 23:42' has that return date" );
Lines 458-464 $item2 = Koha::Items->find( $itemnumber2 ); Link Here
458
ok( $item2->location eq 'CART', q{UpdateItemLocationOnCheckin updates location value from 'GEN' with setting "_ALL_: CART" when transfer filled} );
456
ok( $item2->location eq 'CART', q{UpdateItemLocationOnCheckin updates location value from 'GEN' with setting "_ALL_: CART" when transfer filled} );
459
457
460
ok( $item2->permanent_location eq 'GEN', q{UpdateItemLocationOnCheckin does not update permanent_location value from 'GEN' with setting "_ALL_: CART"} );
458
ok( $item2->permanent_location eq 'GEN', q{UpdateItemLocationOnCheckin does not update permanent_location value from 'GEN' with setting "_ALL_: CART"} );
461
AddIssue( $borrower_1, 'barcode_4', $daysago10,0, $today, '' );
459
AddIssue( $patron_1, 'barcode_4', $daysago10,0, $today, '' );
462
$item2 = Koha::Items->find( $itemnumber2 );
460
$item2 = Koha::Items->find( $itemnumber2 );
463
ok( $item2->location eq 'GEN', q{Location updates from 'CART' to permanent location on issue} );
461
ok( $item2->location eq 'GEN', q{Location updates from 'CART' to permanent location on issue} );
464
462
Lines 507-513 my $reserve_id = AddReserve( Link Here
507
    }
505
    }
508
);
506
);
509
ok( $reserve_id, 'The reserve should have been inserted' );
507
ok( $reserve_id, 'The reserve should have been inserted' );
510
AddIssue( $borrower_2, $barcode_1, dt_from_string, 'cancel' );
508
AddIssue( $patron_2, $barcode_1, dt_from_string, 'cancel' );
511
my $hold = Koha::Holds->find( $reserve_id );
509
my $hold = Koha::Holds->find( $reserve_id );
512
is( $hold, undef, 'The reserve should have been correctly cancelled' );
510
is( $hold, undef, 'The reserve should have been correctly cancelled' );
513
511
Lines 530-536 my $unseen_library = $builder->build_object( { class => 'Koha::Libraries' } ); Link Here
530
my $unseen_patron  = $builder->build_object( { class => 'Koha::Patrons' } );
528
my $unseen_patron  = $builder->build_object( { class => 'Koha::Patrons' } );
531
my $unseen_item = $builder->build_sample_item(
529
my $unseen_item = $builder->build_sample_item(
532
    { library => $unseen_library->branchcode, itype => $itemtype } );
530
    { library => $unseen_library->branchcode, itype => $itemtype } );
533
my $unseen_issue = C4::Circulation::AddIssue( $unseen_patron->unblessed, $unseen_item->barcode );
531
my $unseen_issue = C4::Circulation::AddIssue( $unseen_patron, $unseen_item->barcode );
534
532
535
# Does an unseen renewal increment the issue's count
533
# Does an unseen renewal increment the issue's count
536
my ( $unseen_before ) = ( C4::Circulation::GetRenewCount( $unseen_patron->borrowernumber, $unseen_item->itemnumber ) )[3];
534
my ( $unseen_before ) = ( C4::Circulation::GetRenewCount( $unseen_patron->borrowernumber, $unseen_item->itemnumber ) )[3];
(-)a/t/db_dependent/Circulation/maxsuspensiondays.t (-9 / +8 lines)
Lines 42-54 Koha::CirculationRules->set_rules( Link Here
42
    }
42
    }
43
);
43
);
44
44
45
my $borrowernumber = Koha::Patron->new({
45
my $patron = Koha::Patron->new({
46
    firstname =>  'my firstname',
46
    firstname =>  'my firstname',
47
    surname => 'my surname',
47
    surname => 'my surname',
48
    categorycode => $patron_category->{categorycode},
48
    categorycode => $patron_category->{categorycode},
49
    branchcode => $branchcode,
49
    branchcode => $branchcode,
50
})->store->borrowernumber;
50
})->store;
51
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
52
51
53
my $record = MARC::Record->new();
52
my $record = MARC::Record->new();
54
$record->append_fields(
53
$record->append_fields(
Lines 74-82 $dbh->do('DELETE FROM repeatable_holidays'); Link Here
74
my $daysago20 = dt_from_string->add_duration(DateTime::Duration->new(days => -20));
73
my $daysago20 = dt_from_string->add_duration(DateTime::Duration->new(days => -20));
75
my $daysafter40 = dt_from_string->add_duration(DateTime::Duration->new(days => 40));
74
my $daysafter40 = dt_from_string->add_duration(DateTime::Duration->new(days => 40));
76
75
77
AddIssue( $borrower, $barcode, $daysago20 );
76
AddIssue( $patron, $barcode, $daysago20 );
78
AddReturn( $barcode, $branchcode );
77
AddReturn( $barcode, $branchcode );
79
my $debarments = GetDebarments({borrowernumber => $borrower->{borrowernumber}});
78
my $debarments = GetDebarments({borrowernumber => $patron->borrowernumber});
80
is(
79
is(
81
    $debarments->[0]->{expiration},
80
    $debarments->[0]->{expiration},
82
    output_pref({ dt => $daysafter40, dateformat => 'iso', dateonly => 1 }),
81
    output_pref({ dt => $daysafter40, dateformat => 'iso', dateonly => 1 }),
Lines 97-105 Koha::CirculationRules->set_rules( Link Here
97
);
96
);
98
97
99
my $daysafter10 = dt_from_string->add_duration(DateTime::Duration->new(days => 10));
98
my $daysafter10 = dt_from_string->add_duration(DateTime::Duration->new(days => 10));
100
AddIssue( $borrower, $barcode, $daysago20 );
99
AddIssue( $patron, $barcode, $daysago20 );
101
AddReturn( $barcode, $branchcode );
100
AddReturn( $barcode, $branchcode );
102
$debarments = GetDebarments({borrowernumber => $borrower->{borrowernumber}});
101
$debarments = GetDebarments({borrowernumber => $patron->borrowernumber});
103
is(
102
is(
104
    $debarments->[0]->{expiration},
103
    $debarments->[0]->{expiration},
105
    output_pref({ dt => $daysafter10, dateformat => 'iso', dateonly => 1 }),
104
    output_pref({ dt => $daysafter10, dateformat => 'iso', dateonly => 1 }),
Lines 127-133 subtest "suspension_chargeperiod" => sub { Link Here
127
126
128
    my $last_year = dt_from_string->clone->subtract( years => 1 );
127
    my $last_year = dt_from_string->clone->subtract( years => 1 );
129
    my $today = dt_from_string;
128
    my $today = dt_from_string;
130
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron->unblessed, $item->unblessed, $last_year, $today );
129
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron, $item, $last_year, $today );
131
    is( $new_debar_dt->truncate( to => 'day' ),
130
    is( $new_debar_dt->truncate( to => 'day' ),
132
        $today->clone->add( days => 365 / 15 * 7 )->truncate( to => 'day' ) );
131
        $today->clone->add( days => 365 / 15 * 7 )->truncate( to => 'day' ) );
133
132
Lines 153-159 subtest "maxsuspensiondays" => sub { Link Here
153
152
154
    my $last_year = dt_from_string->clone->subtract( years => 1 );
153
    my $last_year = dt_from_string->clone->subtract( years => 1 );
155
    my $today = dt_from_string;
154
    my $today = dt_from_string;
156
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron->unblessed, $item->unblessed, $last_year, $today );
155
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron, $item, $last_year, $today );
157
    is( $new_debar_dt->truncate( to => 'day' ),
156
    is( $new_debar_dt->truncate( to => 'day' ),
158
        $today->clone->add( days => 333 )->truncate( to => 'day' ) );
157
        $today->clone->add( days => 333 )->truncate( to => 'day' ) );
159
};
158
};
(-)a/t/db_dependent/Circulation/transferbook.t (-3 / +8 lines)
Lines 116-124 subtest 'transfer already at destination' => sub { Link Here
116
        }
116
        }
117
    );
117
    );
118
118
119
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' })->store->itemtype;
119
    my $item = $builder->build_sample_item(
120
    my $item = $builder->build_sample_item(
120
        {
121
        {
121
            library => $library->branchcode,
122
            library => $library->branchcode,
123
            itype => $itemtype
122
        }
124
        }
123
    );
125
    );
124
126
Lines 169-175 subtest 'transfer already at destination' => sub { Link Here
169
    is( $dotransfer, 0, 'Do not transfer recalled item, it has already arrived' );
171
    is( $dotransfer, 0, 'Do not transfer recalled item, it has already arrived' );
170
    is( $messages->{RecallPlacedAtHoldingBranch}, 1, "We found the recall");
172
    is( $messages->{RecallPlacedAtHoldingBranch}, 1, "We found the recall");
171
173
172
    my $item2 = $builder->build_object({ class => 'Koha::Items' }); # this item will have a different holding branch to the pickup branch
174
    $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' })->store->itemtype;
175
    my $item2 = $builder->build_object({ class => 'Koha::Items', value => { itype => $itemtype } }); # this item will have a different holding branch to the pickup branch
173
    $recall = Koha::Recall->new(
176
    $recall = Koha::Recall->new(
174
        {   biblio_id         => $item2->biblionumber,
177
        {   biblio_id         => $item2->biblionumber,
175
            item_id           => $item2->itemnumber,
178
            item_id           => $item2->itemnumber,
Lines 196-209 subtest 'transfer an issued item' => sub { Link Here
196
        }
199
        }
197
    );
200
    );
198
201
202
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' })->store->itemtype;
199
    my $item = $builder->build_sample_item(
203
    my $item = $builder->build_sample_item(
200
        {
204
        {
201
            library => $library->branchcode,
205
            library => $library->branchcode,
206
            itype => $itemtype
202
        }
207
        }
203
    );
208
    );
204
209
205
    my $dt_to = dt_from_string();
210
    my $dt_to = dt_from_string();
206
    my $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to );
211
    my $issue = AddIssue( $patron, $item->barcode, $dt_to );
207
212
208
    # We are making sure there is no regression, feel free to change the behavior if needed.
213
    # We are making sure there is no regression, feel free to change the behavior if needed.
209
    # * WasReturned does not seem like a variable that should contain a borrowernumber
214
    # * WasReturned does not seem like a variable that should contain a borrowernumber
Lines 217-223 subtest 'transfer an issued item' => sub { Link Here
217
    is( $messages->{WasReturned}, $patron->borrowernumber, 'transferbook should have return a WasReturned flag is the item was issued before the transferbook call');
222
    is( $messages->{WasReturned}, $patron->borrowernumber, 'transferbook should have return a WasReturned flag is the item was issued before the transferbook call');
218
223
219
    # Reset issue
224
    # Reset issue
220
    $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to );
225
    $issue = AddIssue( $patron, $item->barcode, $dt_to );
221
226
222
    # We are making sure there is no regression, feel free to change the behavior if needed.
227
    # We are making sure there is no regression, feel free to change the behavior if needed.
223
    # * Contrary to the POD, if ignore_reserves is not passed (or is false), any item reserve
228
    # * Contrary to the POD, if ignore_reserves is not passed (or is false), any item reserve
(-)a/t/db_dependent/Circulation_holdsqueue.t (-2 / +2 lines)
Lines 58-64 subtest 'AddIssue() and AddReturn() real-time holds queue tests' => sub { Link Here
58
    } );
58
    } );
59
59
60
    $action = 'AddIssue';
60
    $action = 'AddIssue';
61
    AddIssue( $patron->unblessed, $item->barcode, );
61
    AddIssue( $patron, $item->barcode, );
62
62
63
    $action = 'AddReturn';
63
    $action = 'AddReturn';
64
    AddReturn( $item->barcode );
64
    AddReturn( $item->barcode );
Lines 66-72 subtest 'AddIssue() and AddReturn() real-time holds queue tests' => sub { Link Here
66
    t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
66
    t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
67
67
68
    $action = 'AddIssue';
68
    $action = 'AddIssue';
69
    AddIssue( $patron->unblessed, $item->barcode, );
69
    AddIssue( $patron, $item->barcode, );
70
70
71
    $action = 'AddReturn';
71
    $action = 'AddReturn';
72
    AddReturn( $item->barcode );
72
    AddReturn( $item->barcode );
(-)a/t/db_dependent/DecreaseLoanHighHolds.t (-1 / +1 lines)
Lines 118-124 my $orig_due = C4::Circulation::CalcDateDue( Link Here
118
    dt_from_string(),
118
    dt_from_string(),
119
    $item->effective_itemtype,
119
    $item->effective_itemtype,
120
    $patron->branchcode,
120
    $patron->branchcode,
121
    $patron->unblessed
121
    $patron
122
);
122
);
123
123
124
t::lib::Mocks::mock_preference( 'decreaseLoanHighHolds',               1 );
124
t::lib::Mocks::mock_preference( 'decreaseLoanHighHolds',               1 );
(-)a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t (-3 / +3 lines)
Lines 104-110 is( $is, 1, "Items availability: both of 2 items are available" ); Link Here
104
$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
104
$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
105
is( $is, 0, "Item cannot be held, 2 items available" );
105
is( $is, 0, "Item cannot be held, 2 items available" );
106
106
107
my $issue1 = AddIssue( $patron2->unblessed, $item1->barcode );
107
my $issue1 = AddIssue( $patron2, $item1->barcode );
108
108
109
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
109
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
110
is( $is, 1, "Items availability: one item is available" );
110
is( $is, 1, "Items availability: one item is available" );
Lines 112-118 is( $is, 1, "Items availability: one item is available" ); Link Here
112
$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
112
$is = IsAvailableForItemLevelRequest( $item1, $patron1 );
113
is( $is, 0, "Item cannot be held, 1 item available" );
113
is( $is, 0, "Item cannot be held, 1 item available" );
114
114
115
AddIssue( $patron2->unblessed, $item2->barcode );
115
AddIssue( $patron2, $item2->barcode );
116
116
117
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
117
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } );
118
is( $is, 0, "Items availability: none of items are available" );
118
is( $is, 0, "Items availability: none of items are available" );
Lines 379-385 subtest 'Check holds availability with different item types' => sub { Link Here
379
    $is = IsAvailableForItemLevelRequest( $item5, $patron1 );
379
    $is = IsAvailableForItemLevelRequest( $item5, $patron1 );
380
    is( $is, 0, "Item5 cannot be requested to hold: 2 items, Item4 available, Item5 restricted" );
380
    is( $is, 0, "Item5 cannot be requested to hold: 2 items, Item4 available, Item5 restricted" );
381
381
382
    AddIssue( $patron2->unblessed, $item4->barcode );
382
    AddIssue( $patron2, $item4->barcode );
383
383
384
    $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblio2->biblionumber, patron => $patron1 } );
384
    $is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblio2->biblionumber, patron => $patron1 } );
385
    is( $is, 0, "Items availability: 2 items, one allowed by smart rule and checked out, another one not allowed to be held by smart rule" );
385
    is( $is, 0, "Items availability: 2 items, one allowed by smart rule and checked out, another one not allowed to be held by smart rule" );
(-)a/t/db_dependent/Holds/RevertWaitingStatus.t (-3 / +2 lines)
Lines 82-90 foreach my $borrowernumber (@borrowernumbers) { Link Here
82
}
82
}
83
83
84
ModReserveAffect( $itemnumber, $borrowernumbers[0] );
84
ModReserveAffect( $itemnumber, $borrowernumbers[0] );
85
my $patron = Koha::Patrons->find( $borrowernumbers[1] )->unblessed;
85
my $patron = Koha::Patrons->find( $borrowernumbers[1] );
86
C4::Circulation::AddIssue( $patron,
86
C4::Circulation::AddIssue( $patron, $item_barcode, undef, 'revert' );
87
    $item_barcode, my $datedue, my $cancelreserve = 'revert' );
88
87
89
my $priorities = $dbh->selectall_arrayref(
88
my $priorities = $dbh->selectall_arrayref(
90
    "SELECT priority FROM reserves ORDER BY priority ASC");
89
    "SELECT priority FROM reserves ORDER BY priority ASC");
(-)a/t/db_dependent/ILSDI_Services.t (-26 / +24 lines)
Lines 325-333 subtest 'Holds test' => sub { Link Here
325
325
326
    t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 );
326
    t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 );
327
327
328
    my $patron = $builder->build({
328
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
329
        source => 'Borrower',
330
    });
331
329
332
    my $item = $builder->build_sample_item(
330
    my $item = $builder->build_sample_item(
333
        {
331
        {
Lines 336-342 subtest 'Holds test' => sub { Link Here
336
    );
334
    );
337
335
338
    my $query = CGI->new;
336
    my $query = CGI->new;
339
    $query->param( 'patron_id', $patron->{borrowernumber});
337
    $query->param( 'patron_id', $patron->borrowernumber);
340
    $query->param( 'bib_id', $item->biblionumber);
338
    $query->param( 'bib_id', $item->biblionumber);
341
339
342
    my $reply = C4::ILSDI::Services::HoldTitle( $query );
340
    my $reply = C4::ILSDI::Services::HoldTitle( $query );
Lines 347-353 subtest 'Holds test' => sub { Link Here
347
    my $hold = $builder->build({
345
    my $hold = $builder->build({
348
        source => 'Reserve',
346
        source => 'Reserve',
349
        value => {
347
        value => {
350
            borrowernumber => $patron->{borrowernumber},
348
            borrowernumber => $patron->borrowernumber,
351
            biblionumber => $item->biblionumber,
349
            biblionumber => $item->biblionumber,
352
            itemnumber => $item->itemnumber
350
            itemnumber => $item->itemnumber
353
        }
351
        }
Lines 359-365 subtest 'Holds test' => sub { Link Here
359
    my $biblio_with_no_item = $builder->build_sample_biblio;
357
    my $biblio_with_no_item = $builder->build_sample_biblio;
360
358
361
    $query = CGI->new;
359
    $query = CGI->new;
362
    $query->param( 'patron_id', $patron->{borrowernumber});
360
    $query->param( 'patron_id', $patron->borrowernumber);
363
    $query->param( 'bib_id', $biblio_with_no_item->biblionumber);
361
    $query->param( 'bib_id', $biblio_with_no_item->biblionumber);
364
362
365
    $reply = C4::ILSDI::Services::HoldTitle( $query );
363
    $reply = C4::ILSDI::Services::HoldTitle( $query );
Lines 374-389 subtest 'Holds test' => sub { Link Here
374
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
372
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
375
    Koha::CirculationRules->set_rule(
373
    Koha::CirculationRules->set_rule(
376
        {
374
        {
377
            categorycode => $patron->{categorycode},
375
            categorycode => $patron->categorycode,
378
            itemtype     => $item2->{itype},
376
            itemtype     => $item2->{itype},
379
            branchcode   => $patron->{branchcode},
377
            branchcode   => $patron->branchcode,
380
            rule_name    => 'reservesallowed',
378
            rule_name    => 'reservesallowed',
381
            rule_value   => 1,
379
            rule_value   => 1,
382
        }
380
        }
383
    );
381
    );
384
382
385
    $query = CGI->new;
383
    $query = CGI->new;
386
    $query->param( 'patron_id', $patron->{borrowernumber});
384
    $query->param( 'patron_id', $patron->borrowernumber);
387
    $query->param( 'bib_id', $item2->biblionumber);
385
    $query->param( 'bib_id', $item2->biblionumber);
388
    $query->param( 'item_id', $item2->itemnumber);
386
    $query->param( 'item_id', $item2->itemnumber);
389
387
Lines 392-407 subtest 'Holds test' => sub { Link Here
392
390
393
    Koha::CirculationRules->set_rule(
391
    Koha::CirculationRules->set_rule(
394
        {
392
        {
395
            categorycode => $patron->{categorycode},
393
            categorycode => $patron->categorycode,
396
            itemtype     => $item2->{itype},
394
            itemtype     => $item2->{itype},
397
            branchcode   => $patron->{branchcode},
395
            branchcode   => $patron->branchcode,
398
            rule_name    => 'reservesallowed',
396
            rule_name    => 'reservesallowed',
399
            rule_value   => 0,
397
            rule_value   => 0,
400
        }
398
        }
401
    );
399
    );
402
400
403
    $query = CGI->new;
401
    $query = CGI->new;
404
    $query->param( 'patron_id', $patron->{borrowernumber});
402
    $query->param( 'patron_id', $patron->borrowernumber);
405
    $query->param( 'bib_id', $item2->biblionumber);
403
    $query->param( 'bib_id', $item2->biblionumber);
406
    $query->param( 'item_id', $item2->itemnumber);
404
    $query->param( 'item_id', $item2->itemnumber);
407
405
Lines 433-448 subtest 'Holds test' => sub { Link Here
433
431
434
    Koha::CirculationRules->set_rule(
432
    Koha::CirculationRules->set_rule(
435
        {
433
        {
436
            categorycode => $patron->{categorycode},
434
            categorycode => $patron->categorycode,
437
            itemtype     => $item3->{itype},
435
            itemtype     => $item3->{itype},
438
            branchcode   => $patron->{branchcode},
436
            branchcode   => $patron->branchcode,
439
            rule_name    => 'reservesallowed',
437
            rule_name    => 'reservesallowed',
440
            rule_value   => 10,
438
            rule_value   => 10,
441
        }
439
        }
442
    );
440
    );
443
441
444
    $query = CGI->new;
442
    $query = CGI->new;
445
    $query->param( 'patron_id', $patron->{borrowernumber});
443
    $query->param( 'patron_id', $patron->borrowernumber);
446
    $query->param( 'bib_id', $item4->biblionumber);
444
    $query->param( 'bib_id', $item4->biblionumber);
447
    $query->param( 'item_id', $item4->itemnumber);
445
    $query->param( 'item_id', $item4->itemnumber);
448
446
Lines 450-461 subtest 'Holds test' => sub { Link Here
450
    is( $reply->{code}, 'damaged', "Item is damaged" );
448
    is( $reply->{code}, 'damaged', "Item is damaged" );
451
449
452
    my $module = Test::MockModule->new('C4::Context');
450
    my $module = Test::MockModule->new('C4::Context');
453
    $module->mock('userenv', sub { { patron => $patron } });
451
    $module->mock('userenv', sub { { patron => $patron->unblessed } });
454
    my $issue = C4::Circulation::AddIssue($patron, $item3->barcode);
452
    my $issue = C4::Circulation::AddIssue($patron, $item3->barcode);
455
    t::lib::Mocks::mock_preference( 'AllowHoldsOnPatronsPossessions', '0' );
453
    t::lib::Mocks::mock_preference( 'AllowHoldsOnPatronsPossessions', '0' );
456
454
457
    $query = CGI->new;
455
    $query = CGI->new;
458
    $query->param( 'patron_id', $patron->{borrowernumber});
456
    $query->param( 'patron_id', $patron->borrowernumber);
459
    $query->param( 'bib_id', $item3->biblionumber);
457
    $query->param( 'bib_id', $item3->biblionumber);
460
    $query->param( 'item_id', $item3->itemnumber);
458
    $query->param( 'item_id', $item3->itemnumber);
461
    $query->param( 'pickup_location', $origin_branch->{branchcode});
459
    $query->param( 'pickup_location', $origin_branch->{branchcode});
Lines 511-518 subtest 'Holds test for branch transfer limits' => sub { Link Here
511
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' );
509
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' );
512
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
510
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
513
511
514
    my $patron = $builder->build({
512
    my $patron = $builder->build_object({
515
        source => 'Borrower',
513
        class => 'Koha::Patrons',
516
    });
514
    });
517
515
518
    my $origin_branch = $builder->build(
516
    my $origin_branch = $builder->build(
Lines 556-562 subtest 'Holds test for branch transfer limits' => sub { Link Here
556
554
557
    my $query = CGI->new;
555
    my $query = CGI->new;
558
    $query->param( 'pickup_location', $pickup_branch->{branchcode} );
556
    $query->param( 'pickup_location', $pickup_branch->{branchcode} );
559
    $query->param( 'patron_id', $patron->{borrowernumber});
557
    $query->param( 'patron_id', $patron->borrowernumber);
560
    $query->param( 'bib_id', $item->biblionumber);
558
    $query->param( 'bib_id', $item->biblionumber);
561
    $query->param( 'item_id', $item->itemnumber);
559
    $query->param( 'item_id', $item->itemnumber);
562
560
Lines 570-583 subtest 'Holds test for branch transfer limits' => sub { Link Here
570
568
571
    $reply = C4::ILSDI::Services::HoldItem( $query );
569
    $reply = C4::ILSDI::Services::HoldItem( $query );
572
    is( $reply->{code}, undef, "Item hold, Item can be transferred" );
570
    is( $reply->{code}, undef, "Item hold, Item can be transferred" );
573
    my $hold = Koha::Holds->search({ itemnumber => $item->itemnumber, borrowernumber => $patron->{borrowernumber} })->next;
571
    my $hold = Koha::Holds->search({ itemnumber => $item->itemnumber, borrowernumber => $patron->borrowernumber })->next;
574
    is( $hold->branchcode, $pickup_branch->{branchcode}, 'The library id is correctly set' );
572
    is( $hold->branchcode, $pickup_branch->{branchcode}, 'The library id is correctly set' );
575
573
576
    Koha::Holds->search()->delete();
574
    Koha::Holds->search()->delete();
577
575
578
    $reply = C4::ILSDI::Services::HoldTitle( $query );
576
    $reply = C4::ILSDI::Services::HoldTitle( $query );
579
    is( $reply->{code}, undef, "Record hold, Item con be transferred" );
577
    is( $reply->{code}, undef, "Record hold, Item con be transferred" );
580
    $hold = Koha::Holds->search({ biblionumber => $item->biblionumber, borrowernumber => $patron->{borrowernumber} })->next;
578
    $hold = Koha::Holds->search({ biblionumber => $item->biblionumber, borrowernumber => $patron->borrowernumber })->next;
581
    is( $hold->branchcode, $pickup_branch->{branchcode}, 'The library id is correctly set' );
579
    is( $hold->branchcode, $pickup_branch->{branchcode}, 'The library id is correctly set' );
582
580
583
    $schema->storage->txn_rollback;
581
    $schema->storage->txn_rollback;
Lines 723-729 subtest 'RenewHold' => sub { Link Here
723
    $cgi->param( item_id   => $item->itemnumber );
721
    $cgi->param( item_id   => $item->itemnumber );
724
722
725
    t::lib::Mocks::mock_userenv( { patron => $patron } );    # For AddIssue
723
    t::lib::Mocks::mock_userenv( { patron => $patron } );    # For AddIssue
726
    my $checkout = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
724
    my $checkout = C4::Circulation::AddIssue( $patron, $item->barcode );
727
725
728
    # Everything is ok
726
    # Everything is ok
729
    my $reply = C4::ILSDI::Services::RenewLoan($cgi);
727
    my $reply = C4::ILSDI::Services::RenewLoan($cgi);
Lines 826-836 subtest 'GetPatronInfo paginated loans' => sub { Link Here
826
    my $module = Test::MockModule->new('C4::Context');
824
    my $module = Test::MockModule->new('C4::Context');
827
    $module->mock('userenv', sub { { branch => $library->branchcode } });
825
    $module->mock('userenv', sub { { branch => $library->branchcode } });
828
    my $date_due = Koha::DateUtils::dt_from_string()->add(weeks => 2);
826
    my $date_due = Koha::DateUtils::dt_from_string()->add(weeks => 2);
829
    my $issue1 = C4::Circulation::AddIssue($patron->unblessed, $item1->barcode, $date_due);
827
    my $issue1 = C4::Circulation::AddIssue($patron, $item1->barcode, $date_due);
830
    my $date_due1 = Koha::DateUtils::dt_from_string( $issue1->date_due );
828
    my $date_due1 = Koha::DateUtils::dt_from_string( $issue1->date_due );
831
    my $issue2 = C4::Circulation::AddIssue($patron->unblessed, $item2->barcode, $date_due);
829
    my $issue2 = C4::Circulation::AddIssue($patron, $item2->barcode, $date_due);
832
    my $date_due2 = Koha::DateUtils::dt_from_string( $issue2->date_due );
830
    my $date_due2 = Koha::DateUtils::dt_from_string( $issue2->date_due );
833
    my $issue3 = C4::Circulation::AddIssue($patron->unblessed, $item3->barcode, $date_due);
831
    my $issue3 = C4::Circulation::AddIssue($patron, $item3->barcode, $date_due);
834
    my $date_due3 = Koha::DateUtils::dt_from_string( $issue3->date_due );
832
    my $date_due3 = Koha::DateUtils::dt_from_string( $issue3->date_due );
835
833
836
    my $cgi = CGI->new;
834
    my $cgi = CGI->new;
(-)a/t/db_dependent/Illrequests.t (-1 / +1 lines)
Lines 1602-1608 subtest 'Checking in hook' => sub { Link Here
1602
    t::lib::Mocks::mock_preference('CirculateILL', 1);
1602
    t::lib::Mocks::mock_preference('CirculateILL', 1);
1603
1603
1604
    # Add an issue
1604
    # Add an issue
1605
    AddIssue( $patron->unblessed, $item->barcode );
1605
    AddIssue( $patron, $item->barcode );
1606
    # Make the item withdrawn so checking-in is rejected
1606
    # Make the item withdrawn so checking-in is rejected
1607
    t::lib::Mocks::mock_preference('BlockReturnOfWithdrawnItems', 1);
1607
    t::lib::Mocks::mock_preference('BlockReturnOfWithdrawnItems', 1);
1608
    $item->set({ withdrawn => 1 })->store;
1608
    $item->set({ withdrawn => 1 })->store;
(-)a/t/db_dependent/Koha/Account/Line.t (-9 / +18 lines)
Lines 511-522 subtest 'Renewal related tests' => sub { Link Here
511
            class => 'Koha::Checkouts',
511
            class => 'Koha::Checkouts',
512
            value => {
512
            value => {
513
                itemnumber      => $item->itemnumber,
513
                itemnumber      => $item->itemnumber,
514
                borrowernumber  => $patron->borrowernumber,
514
                onsite_checkout => 0,
515
                onsite_checkout => 0,
515
                renewals_count  => 99,
516
                renewals_count  => 99,
516
                auto_renew      => 0
517
                auto_renew      => 0
517
            }
518
            }
518
        }
519
        }
519
    );
520
    );
521
520
    my $line = Koha::Account::Line->new(
522
    my $line = Koha::Account::Line->new(
521
    {
523
    {
522
        borrowernumber    => $patron->borrowernumber,
524
        borrowernumber    => $patron->borrowernumber,
Lines 701-707 subtest 'checkout() tests' => sub { Link Here
701
    my $account = $patron->account;
703
    my $account = $patron->account;
702
704
703
    t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode });
705
    t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode });
704
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
706
    my $checkout = AddIssue( $patron, $item->barcode );
705
707
706
    my $line = $account->add_debit({
708
    my $line = $account->add_debit({
707
        amount    => 10,
709
        amount    => 10,
Lines 814-827 subtest "void() tests" => sub { Link Here
814
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
816
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
815
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
817
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
816
818
817
    my $borrower = Koha::Patron->new( {
819
    my $staff = $builder->build_object({ class => 'Koha::Patrons' });
818
        cardnumber => 'dariahall',
820
    t::lib::Mocks::mock_userenv({ patron => $staff });
819
        surname => 'Hall',
821
820
        firstname => 'Daria',
822
    my $borrower = $builder->build_object(
821
    } );
823
        {
822
    $borrower->categorycode( $categorycode );
824
            class => 'Koha::Patrons',
823
    $borrower->branchcode( $branchcode );
825
            value => {
824
    $borrower->store;
826
                cardnumber => 'dariahall',
827
                surname => 'Hall',
828
                firstname => 'Daria',
829
                categorycode => $categorycode,
830
                branchcode => $branchcode,
831
            }
832
        }
833
    );
825
834
826
    my $account = Koha::Account->new({ patron_id => $borrower->id });
835
    my $account = Koha::Account->new({ patron_id => $borrower->id });
827
836
(-)a/t/db_dependent/Koha/Biblio.t (-5 / +5 lines)
Lines 857-864 subtest 'current_checkouts() and old_checkouts() tests' => sub { Link Here
857
857
858
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
858
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
859
859
860
    my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' })->unblessed;
860
    my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' });
861
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' })->unblessed;
861
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
862
862
863
    my $item_1 = $builder->build_sample_item;
863
    my $item_1 = $builder->build_sample_item;
864
    my $item_2 = $builder->build_sample_item({ biblionumber => $item_1->biblionumber });
864
    my $item_2 = $builder->build_sample_item({ biblionumber => $item_1->biblionumber });
Lines 997-1003 subtest 'Recalls tests' => sub { Link Here
997
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has more existing recall(s) than recalls_per_record" );
997
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has more existing recall(s) than recalls_per_record" );
998
998
999
    $recall1->set_cancelled;
999
    $recall1->set_cancelled;
1000
    C4::Circulation::AddIssue( $patron1->unblessed, $item2->barcode );
1000
    C4::Circulation::AddIssue( $patron1, $item2->barcode );
1001
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has already checked out an item attached to this biblio" );
1001
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has already checked out an item attached to this biblio" );
1002
1002
1003
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if on_shelf_recalls = all and items are still available" );
1003
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if on_shelf_recalls = all and items are still available" );
Lines 1016-1023 subtest 'Recalls tests' => sub { Link Here
1016
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if no items are checked out" );
1016
    is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if no items are checked out" );
1017
1017
1018
    $recall2->set_cancelled;
1018
    $recall2->set_cancelled;
1019
    C4::Circulation::AddIssue( $patron2->unblessed, $item2->barcode );
1019
    C4::Circulation::AddIssue( $patron2, $item2->barcode );
1020
    C4::Circulation::AddIssue( $patron2->unblessed, $item1->barcode );
1020
    C4::Circulation::AddIssue( $patron2, $item1->barcode );
1021
    is( $biblio->can_be_recalled({ patron => $patron1 }), 2, "Can recall two items" );
1021
    is( $biblio->can_be_recalled({ patron => $patron1 }), 2, "Can recall two items" );
1022
1022
1023
    $item1->update({ withdrawn => 1 });
1023
    $item1->update({ withdrawn => 1 });
(-)a/t/db_dependent/Koha/Items.t (-10 / +10 lines)
Lines 298-304 subtest 'store' => sub { Link Here
298
                }
298
                }
299
            );
299
            );
300
300
301
            C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
301
            C4::Circulation::AddIssue( $patron, $item->barcode );
302
302
303
            # Simulate item marked as lost
303
            # Simulate item marked as lost
304
            $item->itemlost(3)->store;
304
            $item->itemlost(3)->store;
Lines 382-388 subtest 'store' => sub { Link Here
382
            );
382
            );
383
383
384
            my $issue =
384
            my $issue =
385
              C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
385
              C4::Circulation::AddIssue( $patron, $item->barcode );
386
386
387
            # Simulate item marked as lost
387
            # Simulate item marked as lost
388
            $item->itemlost(1)->store;
388
            $item->itemlost(1)->store;
Lines 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;
(-)a/t/db_dependent/Koha/Object.t (-1 / +3 lines)
Lines 973-978 subtest 'unblessed_all_relateds' => sub { Link Here
973
    my $patron = Koha::Patron->new($patron_data)->store;
973
    my $patron = Koha::Patron->new($patron_data)->store;
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_object({ class => 'Koha::ItemTypes' })->store->itemtype;
976
    my $item = $builder->build_object(
977
    my $item = $builder->build_object(
977
        {
978
        {
978
            class => 'Koha::Items',
979
            class => 'Koha::Items',
Lines 982-992 subtest 'unblessed_all_relateds' => sub { Link Here
982
                biblionumber  => $biblio->biblionumber,
983
                biblionumber  => $biblio->biblionumber,
983
                itemlost      => 0,
984
                itemlost      => 0,
984
                withdrawn     => 0,
985
                withdrawn     => 0,
986
                itype         => $itemtype,
985
            }
987
            }
986
        }
988
        }
987
    );
989
    );
988
990
989
    my $issue = AddIssue( $patron->unblessed, $item->barcode, DateTime->now->subtract( days => 1 ) );
991
    my $issue = AddIssue( $patron, $item->barcode, DateTime->now->subtract( days => 1 ) );
990
    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
991
    my $overdue = $overdues->next->unblessed_all_relateds;
993
    my $overdue = $overdues->next->unblessed_all_relateds;
992
    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 1509-1519 subtest 'overdues' => sub { Link Here
1509
1505
1510
    t::lib::Mocks::mock_preference({ branchcode => $library->{branchcode} });
1506
    t::lib::Mocks::mock_preference({ branchcode => $library->{branchcode} });
1511
1507
1508
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
1509
1512
    AddIssue( $patron, $item_1->barcode, DateTime->now->subtract( days => 1 ) );
1510
    AddIssue( $patron, $item_1->barcode, DateTime->now->subtract( days => 1 ) );
1513
    AddIssue( $patron, $item_2->barcode, DateTime->now->subtract( days => 5 ) );
1511
    AddIssue( $patron, $item_2->barcode, DateTime->now->subtract( days => 5 ) );
1514
    AddIssue( $patron, $item_3->barcode );
1512
    AddIssue( $patron, $item_3->barcode );
1515
1513
1516
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
1517
    my $overdues = $patron->overdues;
1514
    my $overdues = $patron->overdues;
1518
    is( $overdues->count, 2, 'Patron should have 2 overdues');
1515
    is( $overdues->count, 2, 'Patron should have 2 overdues');
1519
    is( $overdues->next->itemnumber, $item_1->itemnumber, 'The issue should be returned in the same order as they have been done, first is correct' );
1516
    is( $overdues->next->itemnumber, $item_1->itemnumber, 'The issue should be returned in the same order as they have been done, first is correct' );
(-)a/t/db_dependent/Koha/Plugins/Circulation_hooks.t (-2 / +2 lines)
Lines 75-85 subtest 'after_circ_action() hook tests' => sub { Link Here
75
    subtest 'AddIssue' => sub {
75
    subtest 'AddIssue' => sub {
76
        plan tests => 2;
76
        plan tests => 2;
77
77
78
        warning_like { AddIssue( $patron->unblessed, $item_1->barcode ); }
78
        warning_like { AddIssue( $patron, $item_1->barcode ); }
79
        qr/after_circ_action called with action: checkout, ref: Koha::Checkout type: issue/,
79
        qr/after_circ_action called with action: checkout, ref: Koha::Checkout type: issue/,
80
          'AddIssue calls the after_circ_action hook';
80
          'AddIssue calls the after_circ_action hook';
81
81
82
        warning_like { AddIssue( $patron->unblessed, $item_2->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } ); }
82
        warning_like { AddIssue( $patron, $item_2->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } ); }
83
        qr/after_circ_action called with action: checkout, ref: Koha::Checkout type: onsite_checkout/,
83
        qr/after_circ_action called with action: checkout, ref: Koha::Checkout type: onsite_checkout/,
84
          'AddIssue calls the after_circ_action hook (onsite_checkout case)';
84
          'AddIssue calls the after_circ_action hook (onsite_checkout case)';
85
    };
85
    };
(-)a/t/db_dependent/Koha/Pseudonymization.t (-2 / +2 lines)
Lines 84-90 subtest 'Koha::Anonymized::Transactions tests' => sub { Link Here
84
    t::lib::Mocks::mock_preference( 'Pseudonymization', 0 );
84
    t::lib::Mocks::mock_preference( 'Pseudonymization', 0 );
85
    my $item = $builder->build_sample_item;
85
    my $item = $builder->build_sample_item;
86
    t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch });
86
    t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch });
87
    AddIssue( $patron->unblessed, $item->barcode, dt_from_string );
87
    AddIssue( $patron, $item->barcode, dt_from_string );
88
    AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string );
88
    AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string );
89
    my $pseudonymized= Koha::PseudonymizedTransactions->search(
89
    my $pseudonymized= Koha::PseudonymizedTransactions->search(
90
        { itemnumber => $item->itemnumber } )->next;
90
        { itemnumber => $item->itemnumber } )->next;
Lines 96-102 subtest 'Koha::Anonymized::Transactions tests' => sub { Link Here
96
    );
96
    );
97
    $item = $builder->build_sample_item;
97
    $item = $builder->build_sample_item;
98
    t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch });
98
    t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch });
99
    AddIssue( $patron->unblessed, $item->barcode, dt_from_string );
99
    AddIssue( $patron, $item->barcode, dt_from_string );
100
    AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string );
100
    AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string );
101
    my $statistic = Koha::Statistics->search( { itemnumber => $item->itemnumber } )->next;
101
    my $statistic = Koha::Statistics->search( { itemnumber => $item->itemnumber } )->next;
102
    $pseudonymized = Koha::PseudonymizedTransactions->search( { itemnumber => $item->itemnumber } )->next;
102
    $pseudonymized = Koha::PseudonymizedTransactions->search( { itemnumber => $item->itemnumber } )->next;
(-)a/t/db_dependent/Koha/Template/Plugin/CirculationRules.t (-1 / +1 lines)
Lines 74-80 my $item = $builder->build_sample_item( Link Here
74
    }
74
    }
75
);
75
);
76
76
77
my $issue = AddIssue( $patron->unblessed, $item->barcode );
77
my $issue = AddIssue( $patron, $item->barcode );
78
78
79
my $rules = $plugin->Renewals( $patron->id, $item->id );
79
my $rules = $plugin->Renewals( $patron->id, $item->id );
80
80
(-)a/t/db_dependent/Letters/TemplateToolkit.t (-35 / +59 lines)
Lines 63-69 my $mocked_datetime = Test::MockModule->new('DateTime'); Link Here
63
$mocked_datetime->mock( 'now', sub { return $now_value->clone; } );
63
$mocked_datetime->mock( 'now', sub { return $now_value->clone; } );
64
64
65
my $library = $builder->build( { source => 'Branch' } );
65
my $library = $builder->build( { source => 'Branch' } );
66
my $patron  = $builder->build( { source => 'Borrower' } );
66
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
67
67
my $patron2 = $builder->build( { source => 'Borrower' } );
68
my $patron2 = $builder->build( { source => 'Borrower' } );
68
69
69
my $item = $builder->build_sample_item();
70
my $item = $builder->build_sample_item();
Lines 71-77 my $hold = $builder->build_object( Link Here
71
    {
72
    {
72
        class => 'Koha::Holds',
73
        class => 'Koha::Holds',
73
        value => {
74
        value => {
74
            borrowernumber => $patron->{borrowernumber},
75
            borrowernumber => $patron->borrowernumber,
75
            biblionumber   => $item->biblionumber
76
            biblionumber   => $item->biblionumber
76
        }
77
        }
77
    }
78
    }
Lines 109-155 $prepared_letter = GetPreparedLetter( Link Here
109
        module      => 'test',
110
        module      => 'test',
110
        letter_code => 'TEST_PATRON',
111
        letter_code => 'TEST_PATRON',
111
        tables      => {
112
        tables      => {
112
            borrowers => $patron->{borrowernumber},
113
            borrowers => $patron->borrowernumber,
113
        },
114
        },
114
    )
115
    )
115
);
116
);
116
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with scalar for content' );
117
is( $prepared_letter->{content}, $patron->borrowernumber, 'Patron object used correctly with scalar for content' );
117
is( $prepared_letter->{title}, $patron->{firstname}, 'Patron object used correctly with scalar for title' );
118
is( $prepared_letter->{title}, $patron->firstname, 'Patron object used correctly with scalar for title' );
118
119
119
$prepared_letter = GetPreparedLetter(
120
$prepared_letter = GetPreparedLetter(
120
    (
121
    (
121
        module      => 'test',
122
        module      => 'test',
122
        letter_code => 'TEST_PATRON',
123
        letter_code => 'TEST_PATRON',
123
        tables      => {
124
        tables      => {
124
            borrowers => $patron,
125
            borrowers => $patron->unblessed,
125
        },
126
        },
126
    )
127
    )
127
);
128
);
128
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with hashref for content' );
129
is( $prepared_letter->{content}, $patron->borrowernumber, 'Patron object used correctly with hashref for content' );
129
is( $prepared_letter->{title}, $patron->{firstname}, 'Patron object used correctly with hashref for title' );
130
is( $prepared_letter->{title}, $patron->firstname, 'Patron object used correctly with hashref for title' );
130
131
131
$prepared_letter = GetPreparedLetter(
132
$prepared_letter = GetPreparedLetter(
132
    (
133
    (
133
        module      => 'test',
134
        module      => 'test',
134
        letter_code => 'TEST_PATRON',
135
        letter_code => 'TEST_PATRON',
135
        tables      => {
136
        tables      => {
136
            borrowers => [ $patron->{borrowernumber} ],
137
            borrowers => [ $patron->borrowernumber ],
137
        },
138
        },
138
    )
139
    )
139
);
140
);
140
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with arrayref for content' );
141
is( $prepared_letter->{content}, $patron->borrowernumber, 'Patron object used correctly with arrayref for content' );
141
is( $prepared_letter->{title}, $patron->{firstname}, 'Patron object used correctly with arrayref for title' );
142
is( $prepared_letter->{title}, $patron->firstname, 'Patron object used correctly with arrayref for title' );
142
143
143
$prepared_letter = GetPreparedLetter(
144
$prepared_letter = GetPreparedLetter(
144
    (
145
    (
145
        module      => 'test',
146
        module      => 'test',
146
        letter_code => 'TEST_PATRON',
147
        letter_code => 'TEST_PATRON',
147
        objects      => {
148
        objects      => {
148
            borrower => scalar Koha::Patrons->find( $patron->{borrowernumber} ),
149
            borrower => scalar Koha::Patrons->find( $patron->borrowernumber ),
149
        },
150
        },
150
    )
151
    )
151
);
152
);
152
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly as object' );
153
is( $prepared_letter->{content}, $patron->borrowernumber, 'Patron object used correctly as object' );
153
154
154
$sth->execute( "TEST_BIBLIO", "[% biblio.title %]", "[% biblio.id %]" );
155
$sth->execute( "TEST_BIBLIO", "[% biblio.title %]", "[% biblio.id %]" );
155
$prepared_letter = GetPreparedLetter(
156
$prepared_letter = GetPreparedLetter(
Lines 209-215 $prepared_letter = GetPreparedLetter( Link Here
209
        module      => 'test',
210
        module      => 'test',
210
        letter_code => 'TEST_HOLD',
211
        letter_code => 'TEST_HOLD',
211
        tables      => {
212
        tables      => {
212
            reserves => { borrowernumber => $patron->{borrowernumber}, biblionumber => $item->biblionumber },
213
            reserves => { borrowernumber => $patron->borrowernumber, biblionumber => $item->biblionumber },
213
        },
214
        },
214
    )
215
    )
215
);
216
);
Lines 222-228 eval { Link Here
222
            module      => 'test',
223
            module      => 'test',
223
            letter_code => 'TEST_HOLD',
224
            letter_code => 'TEST_HOLD',
224
            tables      => {
225
            tables      => {
225
                reserves => [ $patron->{borrowernumber}, $item->biblionumber ],
226
                reserves => [ $patron->borrowernumber, $item->biblionumber ],
226
            },
227
            },
227
        )
228
        )
228
    )
229
    )
Lines 237-243 $prepared_letter = GetPreparedLetter( Link Here
237
        letter_code => 'TEST_HOLD',
238
        letter_code => 'TEST_HOLD',
238
        tables      => {
239
        tables      => {
239
            'branches'    => $library,
240
            'branches'    => $library,
240
            'borrowers'   => $patron,
241
            'borrowers'   => $patron->unblessed,
241
            'biblio'      => $item->biblionumber,
242
            'biblio'      => $item->biblionumber,
242
            'biblioitems' => $item->biblioitemnumber,
243
            'biblioitems' => $item->biblioitemnumber,
243
            'reserves'    => $hold->unblessed,
244
            'reserves'    => $hold->unblessed,
Lines 311-322 subtest 'regression tests' => sub { Link Here
311
    plan tests => 8;
312
    plan tests => 8;
312
313
313
    my $library = $builder->build( { source => 'Branch' } );
314
    my $library = $builder->build( { source => 'Branch' } );
314
    my $patron  = $builder->build( { source => 'Borrower' } );
315
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' })->store->itemtype;
316
315
    my $item1 = $builder->build_sample_item(
317
    my $item1 = $builder->build_sample_item(
316
        {
318
        {
317
            barcode        => 'a_t_barcode',
319
            barcode        => 'a_t_barcode',
318
            library        => $library->{branchcode},
320
            library        => $library->{branchcode},
319
            itype          => 'BK',
321
            itype          => $itemtype,
320
            itemcallnumber => 'itemcallnumber1',
322
            itemcallnumber => 'itemcallnumber1',
321
        }
323
        }
322
    );
324
    );
Lines 326-332 subtest 'regression tests' => sub { Link Here
326
        {
328
        {
327
            barcode        => 'another_t_barcode',
329
            barcode        => 'another_t_barcode',
328
            library        => $library->{branchcode},
330
            library        => $library->{branchcode},
329
            itype          => 'BK',
331
            itype          => $itemtype,
330
            itemcallnumber => 'itemcallnumber2',
332
            itemcallnumber => 'itemcallnumber2',
331
        }
333
        }
332
    );
334
    );
Lines 336-342 subtest 'regression tests' => sub { Link Here
336
        {
338
        {
337
            barcode        => 'another_t_barcode_3',
339
            barcode        => 'another_t_barcode_3',
338
            library        => $library->{branchcode},
340
            library        => $library->{branchcode},
339
            itype          => 'BK',
341
            itype          => $itemtype,
340
            itemcallnumber => 'itemcallnumber3',
342
            itemcallnumber => 'itemcallnumber3',
341
        }
343
        }
342
    );
344
    );
Lines 356-362 Dear <<borrowers.firstname>> <<borrowers.surname>>, Link Here
356
The order <<aqorders.ordernumber>> (<<biblio.title>>) has been received.
358
The order <<aqorders.ordernumber>> (<<biblio.title>>) has been received.
357
Your library.
359
Your library.
358
        |;
360
        |;
359
        my $params = { code => $code, branchcode => $branchcode, tables => { branches => $library, borrowers => $patron, biblio => $biblio1, aqorders => $order } };
361
        my $params = { code => $code, branchcode => $branchcode, tables => { branches => $library, borrowers => $patron->unblessed, biblio => $biblio1, aqorders => $order } };
360
        my $letter = process_letter( { template => $template, %$params });
362
        my $letter = process_letter( { template => $template, %$params });
361
        my $tt_template = q|
363
        my $tt_template = q|
362
Dear [% borrower.firstname %] [% borrower.surname %],
364
Dear [% borrower.firstname %] [% borrower.surname %],
Lines 430-445 Notes: [% article_request.patron_notes %] Link Here
430
        my $checkout_code = 'CHECKOUT';
432
        my $checkout_code = 'CHECKOUT';
431
        my $checkin_code = 'CHECKIN';
433
        my $checkin_code = 'CHECKIN';
432
434
435
#        my $message_attr_1 = $builder->build_object(
436
#            {
437
#                class => 'Koha::MessageAttribute',
438
#                value => { message_name => "Item_Checkout", takes_days => 0 }
439
#            }
440
#        )->store;
441
#
442
#        my $message_attr_2 = $builder->build_object(
443
#            {
444
#                class => 'Koha::MessageAttribute',
445
#                value => { message_name => "Item_Check_in", takes_days => 0 }
446
#            }
447
#        )->store;
448
433
        my $dbh = C4::Context->dbh;
449
        my $dbh = C4::Context->dbh;
434
        # Enable notification for CHECKOUT - Things are hardcoded here but should work with default data
450
        # Enable notification for CHECKOUT - Things are hardcoded here but should work with default data
435
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 6 );
451
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|,
452
            undef, $patron->borrowernumber, 6 );
436
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
453
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
437
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
454
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
455
438
        # Enable notification for CHECKIN - Things are hardcoded here but should work with default data
456
        # Enable notification for CHECKIN - Things are hardcoded here but should work with default data
439
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 5 );
457
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|,
458
            undef, $patron->borrowernumber, 5);
440
        $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
459
        $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
441
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
460
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
442
461
462
443
        # historic syntax
463
        # historic syntax
444
        my $checkout_template = q|
464
        my $checkout_template = q|
445
The following items have been checked out:
465
The following items have been checked out:
Lines 460-470 Thank you for visiting <<branches.branchname>>. Link Here
460
480
461
        C4::Circulation::AddIssue( $patron, $item1->{barcode} );
481
        C4::Circulation::AddIssue( $patron, $item1->{barcode} );
462
        my $first_checkout_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
482
        my $first_checkout_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
483
463
        C4::Circulation::AddIssue( $patron, $item2->{barcode} );
484
        C4::Circulation::AddIssue( $patron, $item2->{barcode} );
464
        my $second_checkout_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
485
        my $second_checkout_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
465
486
466
        AddReturn( $item1->{barcode} );
487
        AddReturn( $item1->{barcode} );
467
        my $first_checkin_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
488
        my $first_checkin_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
489
468
        AddReturn( $item2->{barcode} );
490
        AddReturn( $item2->{barcode} );
469
        my $second_checkin_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
491
        my $second_checkin_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
470
492
Lines 490-500 Thank you for visiting [% branch.branchname %]. Link Here
490
512
491
        C4::Circulation::AddIssue( $patron, $item1->{barcode} );
513
        C4::Circulation::AddIssue( $patron, $item1->{barcode} );
492
        my $first_checkout_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
514
        my $first_checkout_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
515
493
        C4::Circulation::AddIssue( $patron, $item2->{barcode} );
516
        C4::Circulation::AddIssue( $patron, $item2->{barcode} );
494
        my $second_checkout_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
517
        my $second_checkout_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
495
518
496
        AddReturn( $item1->{barcode} );
519
        AddReturn( $item1->{barcode} );
497
        my $first_checkin_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
520
        my $first_checkin_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
521
498
        AddReturn( $item2->{barcode} );
522
        AddReturn( $item2->{barcode} );
499
        my $second_checkin_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
523
        my $second_checkin_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
500
524
Lines 512-518 Thank you for visiting [% branch.branchname %]. Link Here
512
536
513
        my $dbh = C4::Context->dbh;
537
        my $dbh = C4::Context->dbh;
514
        # Enable notification for DUEDGST - Things are hardcoded here but should work with default data
538
        # Enable notification for DUEDGST - Things are hardcoded here but should work with default data
515
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 1 );
539
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->borrowernumber, 1 );
516
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
540
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
517
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
541
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
518
542
Lines 541-547 You have [% count %] items due Link Here
541
        my $reserve_id1 = C4::Reserves::AddReserve(
565
        my $reserve_id1 = C4::Reserves::AddReserve(
542
            {
566
            {
543
                branchcode     => $library->{branchcode},
567
                branchcode     => $library->{branchcode},
544
                borrowernumber => $patron->{borrowernumber},
568
                borrowernumber => $patron->borrowernumber,
545
                biblionumber   => $biblio1->{biblionumber},
569
                biblionumber   => $biblio1->{biblionumber},
546
                notes          => "a note",
570
                notes          => "a note",
547
                itemnumber     => $item1->{itemnumber},
571
                itemnumber     => $item1->{itemnumber},
Lines 550-556 You have [% count %] items due Link Here
550
        my $reserve_id2 = C4::Reserves::AddReserve(
574
        my $reserve_id2 = C4::Reserves::AddReserve(
551
            {
575
            {
552
                branchcode     => $library->{branchcode},
576
                branchcode     => $library->{branchcode},
553
                borrowernumber => $patron->{borrowernumber},
577
                borrowernumber => $patron->borrowernumber,
554
                biblionumber   => $biblio1->{biblionumber},
578
                biblionumber   => $biblio1->{biblionumber},
555
                notes          => "a note",
579
                notes          => "a note",
556
                itemnumber     => $item1->{itemnumber},
580
                itemnumber     => $item1->{itemnumber},
Lines 559-565 You have [% count %] items due Link Here
559
        my $reserve_id3 = C4::Reserves::AddReserve(
583
        my $reserve_id3 = C4::Reserves::AddReserve(
560
            {
584
            {
561
                branchcode     => $library->{branchcode},
585
                branchcode     => $library->{branchcode},
562
                borrowernumber => $patron->{borrowernumber},
586
                borrowernumber => $patron->borrowernumber,
563
                biblionumber   => $biblio2->{biblionumber},
587
                biblionumber   => $biblio2->{biblionumber},
564
                notes          => "another note",
588
                notes          => "another note",
565
                itemnumber     => $item2->{itemnumber},
589
                itemnumber     => $item2->{itemnumber},
Lines 707-719 EOF Link Here
707
731
708
        my $checkout = C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
732
        my $checkout = C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
709
        $checkout->set( { timestamp => $now, issuedate => $one_minute_ago } )->store;
733
        $checkout->set( { timestamp => $now, issuedate => $one_minute_ago } )->store;
710
        my $first_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
734
        my $first_slip = C4::Members::IssueSlip( $branchcode, $patron->borrowernumber );
711
735
712
        $checkout = C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
736
        $checkout = C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
713
        $checkout->set( { timestamp => $now, issuedate => $now } )->store;
737
        $checkout->set( { timestamp => $now, issuedate => $now } )->store;
714
        my $yesterday = dt_from_string->subtract( days => 1 );
738
        my $yesterday = dt_from_string->subtract( days => 1 );
715
        C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue
739
        C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue
716
        my $second_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
740
        my $second_slip = C4::Members::IssueSlip( $branchcode, $patron->borrowernumber );
717
741
718
        # Cleanup
742
        # Cleanup
719
        AddReturn( $item1->{barcode} );
743
        AddReturn( $item1->{barcode} );
Lines 767-778 EOF Link Here
767
791
768
        $checkout = C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
792
        $checkout = C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
769
        $checkout->set( { timestamp => $now, issuedate => $one_minute_ago } )->store;
793
        $checkout->set( { timestamp => $now, issuedate => $one_minute_ago } )->store;
770
        my $first_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
794
        my $first_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->borrowernumber );
771
795
772
        $checkout = C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
796
        $checkout = C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
773
        $checkout->set( { timestamp => $now, issuedate => $now } )->store;
797
        $checkout->set( { timestamp => $now, issuedate => $now } )->store;
774
        C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue
798
        C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue
775
        my $second_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
799
        my $second_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->borrowernumber );
776
800
777
        # There is too many line breaks generated by the historic syntax
801
        # There is too many line breaks generated by the historic syntax
778
        $second_slip->{content} =~ s|</p>\n\n\n<p>|</p>\n\n<p>|s;
802
        $second_slip->{content} =~ s|</p>\n\n\n<p>|</p>\n\n<p>|s;
Lines 845-851 EOF Link Here
845
        my $letter = C4::Overdues::parse_overdues_letter(
869
        my $letter = C4::Overdues::parse_overdues_letter(
846
            {
870
            {
847
                letter_code => $code,
871
                letter_code => $code,
848
                borrowernumber => $patron->{borrowernumber},
872
                borrowernumber => $patron->borrowernumber,
849
                branchcode  => $library->{branchcode},
873
                branchcode  => $library->{branchcode},
850
                items       => \@items,
874
                items       => \@items,
851
                substitute  => {
875
                substitute  => {
Lines 903-909 EOF Link Here
903
        my $tt_letter = C4::Overdues::parse_overdues_letter(
927
        my $tt_letter = C4::Overdues::parse_overdues_letter(
904
            {
928
            {
905
                letter_code => $code,
929
                letter_code => $code,
906
                borrowernumber => $patron->{borrowernumber},
930
                borrowernumber => $patron->borrowernumber,
907
                branchcode  => $library->{branchcode},
931
                branchcode  => $library->{branchcode},
908
                items       => \@items,
932
                items       => \@items,
909
                substitute  => {
933
                substitute  => {
Lines 930-940 EOF Link Here
930
        $dbh->do("DELETE FROM message_queue");
954
        $dbh->do("DELETE FROM message_queue");
931
955
932
        # Enable notification for CHECKOUT - Things are hardcoded here but should work with default data
956
        # Enable notification for CHECKOUT - Things are hardcoded here but should work with default data
933
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 6 );
957
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->borrowernumber, 6 );
934
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
958
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
935
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
959
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
936
        # Enable notification for CHECKIN - Things are hardcoded here but should work with default data
960
        # Enable notification for CHECKIN - Things are hardcoded here but should work with default data
937
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 5 );
961
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->borrowernumber, 5 );
938
        $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
962
        $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
939
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
963
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
940
964
(-)a/t/db_dependent/Members/GetAllIssues.t (-2 / +2 lines)
Lines 66-73 my $borrowernumber1 = Link Here
66
  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
66
  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
67
my $borrowernumber2 =
67
my $borrowernumber2 =
68
  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
68
  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
69
my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed;
69
my $borrower1 = Koha::Patrons->find( $borrowernumber1 );
70
my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed;
70
my $borrower2 = Koha::Patrons->find( $borrowernumber2 );
71
71
72
my $module = Test::MockModule->new('C4::Context');
72
my $module = Test::MockModule->new('C4::Context');
73
$module->mock( 'userenv', sub { { branch => $branchcode } } );
73
$module->mock( 'userenv', sub { { branch => $branchcode } } );
(-)a/t/db_dependent/Members/IssueSlip.t (-3 / +3 lines)
Lines 118-124 my $itemnumber2 = $builder->build_sample_item({ biblionumber => $biblionumber2, Link Here
118
118
119
my $borrowernumber =
119
my $borrowernumber =
120
  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
120
  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
121
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
121
my $borrower = Koha::Patrons->find( $borrowernumber );
122
122
123
my $module = Test::MockModule->new('C4::Context');
123
my $module = Test::MockModule->new('C4::Context');
124
$module->mock( 'userenv', sub { { branch => $branchcode } } );
124
$module->mock( 'userenv', sub { { branch => $branchcode } } );
Lines 164-170 EOS Link Here
164
164
165
        # Set timestamps to the same value to avoid a different order
165
        # Set timestamps to the same value to avoid a different order
166
        Koha::Checkouts->search(
166
        Koha::Checkouts->search(
167
            { borrowernumber => $borrower->{borrowernumber} }
167
            { borrowernumber => $borrower->borrowernumber }
168
        )->update( { timestamp => dt_from_string } );
168
        )->update( { timestamp => dt_from_string } );
169
169
170
        $expected_slip = <<EOS;
170
        $expected_slip = <<EOS;
Lines 237-243 EOS Link Here
237
237
238
        # Set timestamps to the same value to avoid a different order
238
        # Set timestamps to the same value to avoid a different order
239
        Koha::Checkouts->search(
239
        Koha::Checkouts->search(
240
            { borrowernumber => $borrower->{borrowernumber} }
240
            { borrowernumber => $borrower->borrowernumber }
241
        )->update( { timestamp => dt_from_string } );
241
        )->update( { timestamp => dt_from_string } );
242
242
243
        $expected_slip = <<EOS;
243
        $expected_slip = <<EOS;
(-)a/t/db_dependent/Patron/Borrower_Discharge.t (-34 / +32 lines)
Lines 43-72 my $another_library = $builder->build({ source => 'Branch' }); Link Here
43
my $itemtype        = $builder->build({ source => 'Itemtype' })->{itemtype};
43
my $itemtype        = $builder->build({ source => 'Itemtype' })->{itemtype};
44
44
45
C4::Context->_new_userenv('xxx');
45
C4::Context->_new_userenv('xxx');
46
my $patron = $builder->build({
46
my $patron = $builder->build_object({
47
    source => 'Borrower',
47
    class => 'Koha::Patrons',
48
    value => {
48
    value => {
49
        branchcode => $library->{branchcode},
49
        branchcode => $library->{branchcode},
50
        flags      => 1, # superlibrarian
50
        flags      => 1, # superlibrarian
51
    }
51
    }
52
});
52
});
53
my $p = Koha::Patrons->find( $patron->{borrowernumber} );
53
t::lib::Mocks::mock_userenv({ patron => $patron });
54
t::lib::Mocks::mock_userenv({ patron => $p });
55
54
56
my $patron2 = $builder->build({
55
my $patron2 = $builder->build_object({
57
    source => 'Borrower',
56
    class => 'Koha::Patrons',
58
    value => {
57
    value => {
59
        branchcode => $library->{branchcode},
58
        branchcode => $library->{branchcode},
60
    }
59
    }
61
});
60
});
62
my $patron3 = $builder->build({
61
my $patron3 = $builder->build_object({
63
    source => 'Borrower',
62
    class => 'Koha::Patrons',
64
    value => {
63
    value => {
65
        branchcode => $another_library->{branchcode},
64
        branchcode => $another_library->{branchcode},
66
        flags => undef,
65
        flags => undef,
67
    }
66
    }
68
});
67
});
69
my $p3 = Koha::Patrons->find( $patron3->{borrowernumber} );
70
68
71
# Discharge not possible with issues
69
# Discharge not possible with issues
72
my ( $biblionumber ) = AddBiblio( MARC::Record->new, '');
70
my ( $biblionumber ) = AddBiblio( MARC::Record->new, '');
Lines 81-117 $builder->build_sample_item( Link Here
81
);
79
);
82
80
83
AddIssue( $patron, $barcode );
81
AddIssue( $patron, $barcode );
84
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->{borrowernumber} }), 0, 'A patron with issues cannot be discharged' );
82
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 0, 'A patron with issues cannot be discharged' );
85
83
86
is( Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} }), undef, 'No request done if patron has issues' );
84
is( Koha::Patron::Discharge::request({ borrowernumber => $patron->borrowernumber }), undef, 'No request done if patron has issues' );
87
is( Koha::Patron::Discharge::discharge({ borrowernumber => $patron->{borrowernumber} }), undef, 'No discharge done if patron has issues' );
85
is( Koha::Patron::Discharge::discharge({ borrowernumber => $patron->borrowernumber }), undef, 'No discharge done if patron has issues' );
88
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request' );
86
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request' );
89
is_deeply( [ Koha::Patron::Discharge::get_validated ], [], 'There is no validated discharge' );
87
is_deeply( [ Koha::Patron::Discharge::get_validated ], [], 'There is no validated discharge' );
90
88
91
AddReturn( $barcode );
89
AddReturn( $barcode );
92
90
93
# Discharge possible without issue
91
# Discharge possible without issue
94
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->{borrowernumber} }), 1, 'A patron without issues can be discharged' );
92
is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 1, 'A patron without issues can be discharged' );
95
93
96
is(Koha::Patron::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
94
is(Koha::Patron::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number");
97
95
98
# Verify that the user is not discharged anymore if the restriction has been lifted
96
# Verify that the user is not discharged anymore if the restriction has been lifted
99
Koha::Patron::Discharge::discharge( { borrowernumber => $patron->{borrowernumber} } );
97
Koha::Patron::Discharge::discharge( { borrowernumber => $patron->borrowernumber } );
100
Koha::Patron::Discharge::discharge( { borrowernumber => $patron2->{borrowernumber} } );
98
Koha::Patron::Discharge::discharge( { borrowernumber => $patron2->borrowernumber } );
101
Koha::Patron::Discharge::discharge( { borrowernumber => $patron3->{borrowernumber} } );
99
Koha::Patron::Discharge::discharge( { borrowernumber => $patron3->borrowernumber } );
102
is( Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->{borrowernumber} } ), 1, 'The patron has been discharged' );
100
is( Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->borrowernumber } ), 1, 'The patron has been discharged' );
103
is( Koha::Patrons->find( $patron->{borrowernumber} )->is_debarred, '9999-12-31', 'The patron has been debarred after discharge' );
101
is( Koha::Patrons->find( $patron->borrowernumber )->is_debarred, '9999-12-31', 'The patron has been debarred after discharge' );
104
is( scalar( Koha::Patron::Discharge::get_validated ),             3,            'There are 3 validated discharges' );
102
is( scalar( Koha::Patron::Discharge::get_validated ),             3,            'There are 3 validated discharges' );
105
is( scalar( Koha::Patron::Discharge::get_validated( { borrowernumber => $patron->{borrowernumber} } ) ), 1, 'There is 1 validated discharge for a given patron' );
103
is( scalar( Koha::Patron::Discharge::get_validated( { borrowernumber => $patron->borrowernumber } ) ), 1, 'There is 1 validated discharge for a given patron' );
106
is( scalar( Koha::Patron::Discharge::get_validated( { branchcode => $library->{branchcode} } ) ), 2, 'There is 2 validated discharges for a given branchcode' );    # This is not used in the code yet
104
is( scalar( Koha::Patron::Discharge::get_validated( { branchcode => $library->{branchcode} } ) ), 2, 'There is 2 validated discharges for a given branchcode' );    # This is not used in the code yet
107
Koha::Patron::Debarments::DelUniqueDebarment( { 'borrowernumber' => $patron->{borrowernumber}, 'type' => 'DISCHARGE' } );
105
Koha::Patron::Debarments::DelUniqueDebarment( { 'borrowernumber' => $patron->borrowernumber, 'type' => 'DISCHARGE' } );
108
ok( !Koha::Patrons->find( $patron->{borrowernumber} )->is_debarred, 'The debarment has been lifted' );
106
ok( !Koha::Patrons->find( $patron->borrowernumber )->is_debarred, 'The debarment has been lifted' );
109
ok( !Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->{borrowernumber} } ), 'The patron is not discharged after the restriction has been lifted' );
107
ok( !Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->borrowernumber } ), 'The patron is not discharged after the restriction has been lifted' );
110
108
111
# Verify that the discharge works multiple times
109
# Verify that the discharge works multiple times
112
Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} });
110
Koha::Patron::Discharge::request({ borrowernumber => $patron->borrowernumber });
113
is(scalar( Koha::Patron::Discharge::get_pendings ), 1, 'There is a pending discharge request (second time)');
111
is(scalar( Koha::Patron::Discharge::get_pendings ), 1, 'There is a pending discharge request (second time)');
114
Koha::Patron::Discharge::discharge( { borrowernumber => $patron->{borrowernumber} } );
112
Koha::Patron::Discharge::discharge( { borrowernumber => $patron->borrowernumber } );
115
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request (second time)');
113
is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request (second time)');
116
114
117
# Check if PDF::FromHTML is installed.
115
# Check if PDF::FromHTML is installed.
Lines 119-135 my $check = eval { require PDF::FromHTML; }; Link Here
119
117
120
# Tests for if PDF::FromHTML is installed
118
# Tests for if PDF::FromHTML is installed
121
if ($check) {
119
if ($check) {
122
    isnt( Koha::Patron::Discharge::generate_as_pdf({ borrowernumber => $patron->{borrowernumber} }), undef, "Temporary PDF generated." );
120
    isnt( Koha::Patron::Discharge::generate_as_pdf({ borrowernumber => $patron->borrowernumber }), undef, "Temporary PDF generated." );
123
}
121
}
124
# Tests for if PDF::FromHTML is not installed
122
# Tests for if PDF::FromHTML is not installed
125
else {
123
else {
126
    warning_like { Koha::Patron::Discharge::generate_as_pdf({ borrowernumber => $patron->{borrowernumber}, testing => 1 }) }
124
    warning_like { Koha::Patron::Discharge::generate_as_pdf({ borrowernumber => $patron->borrowernumber, testing => 1 }) }
127
          [ qr/Can't locate PDF\/FromHTML.pm in \@INC/ ],
125
          [ qr/Can't locate PDF\/FromHTML.pm in \@INC/ ],
128
          "Expected failure because of missing PDF::FromHTML.";
126
          "Expected failure because of missing PDF::FromHTML.";
129
}
127
}
130
128
131
# FIXME Should be a Koha::Object object
129
# FIXME Should be a Koha::Object object
132
is( ref(Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} })), 'Koha::Schema::Result::Discharge', 'Discharge request sent' );
130
is( ref(Koha::Patron::Discharge::request({ borrowernumber => $patron->borrowernumber })), 'Koha::Schema::Result::Discharge', 'Discharge request sent' );
133
131
134
subtest 'search_limited' => sub {
132
subtest 'search_limited' => sub {
135
    plan tests => 4;
133
    plan tests => 4;
Lines 138-154 subtest 'search_limited' => sub { Link Here
138
    my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2' } )->store;
136
    my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2' } )->store;
139
    # $patron and $patron2 are from the same library, $patron3 from another one
137
    # $patron and $patron2 are from the same library, $patron3 from another one
140
    # Logged in user is $patron, superlibrarian
138
    # Logged in user is $patron, superlibrarian
141
    t::lib::Mocks::mock_userenv({ patron => $p });
139
    t::lib::Mocks::mock_userenv({ patron => $patron });
142
    Koha::Library::Group->new({ parent_id => $group_1->id,  branchcode => $patron->{branchcode} })->store();
140
    Koha::Library::Group->new({ parent_id => $group_1->id,  branchcode => $patron->branchcode })->store();
143
    Koha::Library::Group->new({ parent_id => $group_2->id,  branchcode => $patron3->{branchcode} })->store();
141
    Koha::Library::Group->new({ parent_id => $group_2->id,  branchcode => $patron3->branchcode })->store();
144
    Koha::Patron::Discharge::request({ borrowernumber => $patron->{borrowernumber} });
142
    Koha::Patron::Discharge::request({ borrowernumber => $patron->borrowernumber });
145
    Koha::Patron::Discharge::request({ borrowernumber => $patron2->{borrowernumber} });
143
    Koha::Patron::Discharge::request({ borrowernumber => $patron2->borrowernumber });
146
    Koha::Patron::Discharge::request({ borrowernumber => $patron3->{borrowernumber} });
144
    Koha::Patron::Discharge::request({ borrowernumber => $patron3->borrowernumber });
147
    is( scalar( Koha::Patron::Discharge::get_pendings), 3, 'With permission, all discharges are visible' );
145
    is( scalar( Koha::Patron::Discharge::get_pendings), 3, 'With permission, all discharges are visible' );
148
    is( Koha::Patron::Discharge::count({pending => 1}), 3, 'With permission, all discharges are visible' );
146
    is( Koha::Patron::Discharge::count({pending => 1}), 3, 'With permission, all discharges are visible' );
149
147
150
    # With patron 3 logged in, only discharges from their group are visible
148
    # With patron 3 logged in, only discharges from their group are visible
151
    t::lib::Mocks::mock_userenv({ patron => $p3 });
149
    t::lib::Mocks::mock_userenv({ patron => $patron3 });
152
    is( scalar( Koha::Patron::Discharge::get_pendings), 1, 'Without permission, only discharge from our group are visible' );
150
    is( scalar( Koha::Patron::Discharge::get_pendings), 1, 'Without permission, only discharge from our group are visible' );
153
    is( Koha::Patron::Discharge::count({pending => 1}), 1, 'Without permission, only discharge from our group are visible' );
151
    is( Koha::Patron::Discharge::count({pending => 1}), 1, 'Without permission, only discharge from our group are visible' );
154
};
152
};
(-)a/t/db_dependent/Patron/Borrower_PrevCheckout.t (-3 / +3 lines)
Lines 297-303 my $cpvmappings = [ Link Here
297
test_it($cpvmappings, "PreIssue");
297
test_it($cpvmappings, "PreIssue");
298
298
299
# Issue item_1 to $patron:
299
# Issue item_1 to $patron:
300
my $patron_get_mem = Koha::Patrons->find( $patron->{borrowernumber} )->unblessed;
300
my $patron_get_mem = Koha::Patrons->find( $patron->{borrowernumber} );
301
BAIL_OUT("Issue failed")
301
BAIL_OUT("Issue failed")
302
    unless AddIssue($patron_get_mem, $item_1->{barcode});
302
    unless AddIssue($patron_get_mem, $item_1->{barcode});
303
303
Lines 382-388 my $new_item = $builder->build_sample_item->unblessed; Link Here
382
my $prev_item = $builder->build_sample_item->unblessed;
382
my $prev_item = $builder->build_sample_item->unblessed;
383
# Second is Checked Out
383
# Second is Checked Out
384
BAIL_OUT("CanBookBeIssued Issue failed")
384
BAIL_OUT("CanBookBeIssued Issue failed")
385
    unless AddIssue($patron->unblessed, $prev_item->{barcode});
385
    unless AddIssue($patron, $prev_item->{barcode});
386
386
387
# Mappings
387
# Mappings
388
my $CBBI_mappings = [
388
my $CBBI_mappings = [
Lines 445-451 subtest 'Check previous checkouts for serial' => sub { Link Here
445
    my $item1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
445
    my $item1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
446
    my $item2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
446
    my $item2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
447
447
448
    AddIssue($patron->unblessed, $item1->barcode);
448
    AddIssue($patron, $item1->barcode);
449
449
450
    is($patron->do_check_for_previous_checkout($item1->unblessed), 1, 'Check only one item if bibliographic record is serial');
450
    is($patron->do_check_for_previous_checkout($item1->unblessed), 1, 'Check only one item if bibliographic record is serial');
451
    is($patron->do_check_for_previous_checkout($item2->unblessed), 0, 'Check only one item if bibliographic record is serial');
451
    is($patron->do_check_for_previous_checkout($item2->unblessed), 0, 'Check only one item if bibliographic record is serial');
(-)a/t/db_dependent/SIP/ILS.t (-4 / +4 lines)
Lines 260-266 subtest checkout => sub { Link Here
260
    t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode, flags => 1 });
260
    t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode, flags => 1 });
261
261
262
    my $item = $builder->build_sample_item({
262
    my $item = $builder->build_sample_item({
263
        library       => $library->branchcode,
263
        library => $library->branchcode,
264
    });
264
    });
265
265
266
    Koha::CirculationRules->set_rules(
266
    Koha::CirculationRules->set_rules(
Lines 279-294 subtest checkout => sub { Link Here
279
        }
279
        }
280
    );
280
    );
281
281
282
    AddIssue( $patron->unblessed, $item->barcode, undef, 0 );
282
    AddIssue( $patron, $item->barcode, undef, 0 );
283
    my $checkout = $item->checkout;
283
    my $checkout = $item->checkout;
284
    ok( defined($checkout), "Checkout added");
284
    ok( defined($checkout), "Checkout added");
285
    is( $checkout->renewals_count, 0, "Correct renewals");
285
    is( $checkout->renewals_count, 0, "Correct renewals");
286
286
287
    my $ils = C4::SIP::ILS->new({ id => $library->branchcode });
287
    my $ils = C4::SIP::ILS->new({ id => $library->branchcode });
288
    my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
288
    my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
289
    my $transaction = $ils->checkout($patron->cardnumber,$item->barcode,undef,undef);
289
    my $transaction = $ils->checkout($patron->cardnumber, $item->barcode);
290
290
291
    is( $transaction->{screen_msg},"Item already checked out to you: renewing item.","We get a success message when issue is renewed");
291
    is( $transaction->{screen_msg},"Item already checked out to you: renewing item.", "We get a success message when issue is renewed");
292
292
293
    $checkout->discard_changes();
293
    $checkout->discard_changes();
294
    is( $checkout->renewals_count, 1, "Renewals has been reduced");
294
    is( $checkout->renewals_count, 1, "Renewals has been reduced");
(-)a/t/db_dependent/rollingloans.t (-5 / +5 lines)
Lines 62-77 SKIP: { Link Here
62
}
62
}
63
63
64
sub try_issue {
64
sub try_issue {
65
    my ($cardnumber, $item ) = @_;
65
    my ($cardnumber, $item_barcode ) = @_;
66
    my $issuedate = '2011-05-16';
66
    my $issuedate = '2011-05-16';
67
    my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } );
67
    my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } );
68
    my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued( $patron, $item );
68
    my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued( $patron, $item_barcode );
69
    my $issue = AddIssue($patron->unblessed, $item, undef, 0, $issuedate);
69
    my $issue = AddIssue($patron, $item_barcode, undef, 0, $issuedate);
70
    return dt_from_string( $issue->date_due );
70
    return dt_from_string( $issue->date_due );
71
}
71
}
72
72
73
sub try_return {
73
sub try_return {
74
    my $barcode = shift;
74
    my $item_barcode = shift;
75
    my ($ret, $messages, $iteminformation, $borrower) = AddReturn($barcode);
75
    my ($ret, $messages, $iteminformation, $borrower) = AddReturn($item_barcode);
76
    return $ret;
76
    return $ret;
77
}
77
}
(-)a/t/db_dependent/selenium/regressions.t (-2 / +1 lines)
Lines 176-182 subtest 'Display circulation table correctly' => sub { Link Here
176
        }
176
        }
177
    );
177
    );
178
178
179
    C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
179
    C4::Circulation::AddIssue( $patron, $item->barcode );
180
180
181
    my $mainpage = $s->base_url . q|mainpage.pl|;
181
    my $mainpage = $s->base_url . q|mainpage.pl|;
182
    $driver->get($mainpage . q|?logout.x=1|);
182
    $driver->get($mainpage . q|?logout.x=1|);
183
- 

Return to bug 32496