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

(-)a/t/db_dependent/Circulation.t (-5 / +128 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 102;
20
use Test::More tests => 104;
21
21
22
use DateTime;
22
use DateTime;
23
23
Lines 256-264 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
256
        $biblionumber
256
        $biblionumber
257
    );
257
    );
258
258
259
260
261
262
    # Create borrowers
259
    # Create borrowers
263
    my %renewing_borrower_data = (
260
    my %renewing_borrower_data = (
264
        firstname =>  'John',
261
        firstname =>  'John',
Lines 1639-1644 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1639
    is( $debarments->[0]->{expiration}, $expected_expiration );
1636
    is( $debarments->[0]->{expiration}, $expected_expiration );
1640
};
1637
};
1641
1638
1639
subtest '_FixAccountForLostAndReturned' => sub {
1640
    plan tests => 2;
1641
1642
    # Generate test biblio
1643
    my $biblio = MARC::Record->new();
1644
    my $title  = 'Koha for Dummies';
1645
    $biblio->append_fields(
1646
        MARC::Field->new( '100', ' ', ' ', a => 'Hall, Daria' ),
1647
        MARC::Field->new( '245', ' ', ' ', a => $title ),
1648
    );
1649
1650
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
1651
1652
    my $barcode = 'KD123456789';
1653
    my $branchcode  = $library2->{branchcode};
1654
1655
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
1656
        {
1657
            homebranch       => $branchcode,
1658
            holdingbranch    => $branchcode,
1659
            barcode          => $barcode,
1660
            replacementprice => 99.00,
1661
            itype            => $itemtype
1662
        },
1663
        $biblionumber
1664
    );
1665
1666
    my $patron = $builder->build( { source => 'Borrower' } );
1667
1668
    my $accountline = Koha::Account::Line->new(
1669
        {
1670
            borrowernumber => $patron->{borrowernumber},
1671
            accounttype    => 'L',
1672
            itemnumber     => $itemnumber,
1673
            amount => 99.00,
1674
            amountoutstanding => 99.00,
1675
        }
1676
    )->store();
1677
1678
    C4::Circulation::_FixAccountForLostAndReturned( $itemnumber, $patron->{borrowernumber} );
1679
1680
    $accountline->_result()->discard_changes();
1681
1682
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee has no outstanding amount' );
1683
    is( $accountline->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )');
1684
};
1685
1686
subtest '_FixOverduesOnReturn' => sub {
1687
    plan tests => 6;
1688
1689
    # Generate test biblio
1690
    my $biblio = MARC::Record->new();
1691
    my $title  = 'Koha for Dummies';
1692
    $biblio->append_fields(
1693
        MARC::Field->new( '100', ' ', ' ', a => 'Hall, Kylie' ),
1694
        MARC::Field->new( '245', ' ', ' ', a => $title ),
1695
    );
1696
1697
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
1698
1699
    my $barcode = 'KD987654321';
1700
    my $branchcode  = $library2->{branchcode};
1701
1702
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
1703
        {
1704
            homebranch       => $branchcode,
1705
            holdingbranch    => $branchcode,
1706
            barcode          => $barcode,
1707
            replacementprice => 99.00,
1708
            itype            => $itemtype
1709
        },
1710
        $biblionumber
1711
    );
1712
1713
    my $patron = $builder->build( { source => 'Borrower' } );
1714
1715
    ## Start with basic call, should just close out the open fine
1716
    my $accountline = Koha::Account::Line->new(
1717
        {
1718
            borrowernumber => $patron->{borrowernumber},
1719
            accounttype    => 'FU',
1720
            itemnumber     => $itemnumber,
1721
            amount => 99.00,
1722
            amountoutstanding => 99.00,
1723
            lastincrement => 9.00,
1724
        }
1725
    )->store();
1726
1727
    C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $itemnumber );
1728
1729
    $accountline->_result()->discard_changes();
1730
1731
    is( $accountline->amountoutstanding, '99.000000', 'Fine has the same amount outstanding as previously' );
1732
    is( $accountline->accounttype, 'F', 'Open fine ( account type FU ) has been closed out ( account type F )');
1733
1734
1735
    ## Run again, with exemptfine enabled
1736
    $accountline->set(
1737
        {
1738
            accounttype    => 'FU',
1739
            amountoutstanding => 99.00,
1740
        }
1741
    )->store();
1742
1743
    C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $itemnumber, 1 );
1744
1745
    $accountline->_result()->discard_changes();
1746
1747
    is( $accountline->amountoutstanding, '0.000000', 'Fine has been reduced to 0' );
1748
    is( $accountline->accounttype, 'FFOR', 'Open fine ( account type FU ) has been set to fine forgiven ( account type FFOR )');
1749
1750
    ## Run again, with dropbox mode enabled
1751
    $accountline->set(
1752
        {
1753
            accounttype    => 'FU',
1754
            amountoutstanding => 99.00,
1755
        }
1756
    )->store();
1757
1758
    C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $itemnumber, 0, 1 );
1759
1760
    $accountline->_result()->discard_changes();
1761
1762
    is( $accountline->amountoutstanding, '90.000000', 'Fine has been reduced to 90' );
1763
    is( $accountline->accounttype, 'F', 'Open fine ( account type FU ) has been closed out ( account type F )');
1764
};
1765
1642
sub set_userenv {
1766
sub set_userenv {
1643
    my ( $library ) = @_;
1767
    my ( $library ) = @_;
1644
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', '');
1768
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', '');
1645
- 

Return to bug 14826