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 => 105;
21
21
22
use DateTime;
22
use DateTime;
23
23
Lines 50-55 $dbh->{RaiseError} = 1; Link Here
50
50
51
# Start with a clean slate
51
# Start with a clean slate
52
$dbh->do('DELETE FROM issues');
52
$dbh->do('DELETE FROM issues');
53
$dbh->do('DELETE FROM borrowers');
53
54
54
my $library = $builder->build({
55
my $library = $builder->build({
55
    source => 'Branch',
56
    source => 'Branch',
Lines 259-267 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
259
        $biblionumber
260
        $biblionumber
260
    );
261
    );
261
262
262
263
264
265
    # Create borrowers
263
    # Create borrowers
266
    my %renewing_borrower_data = (
264
    my %renewing_borrower_data = (
267
        firstname =>  'John',
265
        firstname =>  'John',
Lines 1722-1728 subtest 'AddReturn | is_overdue' => sub { Link Here
1722
    AddReturn( $item->{barcode}, $library->{branchcode}, undef, 1, undef, $five_days_ago );
1720
    AddReturn( $item->{barcode}, $library->{branchcode}, undef, 1, undef, $five_days_ago );
1723
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue in dropbox mode' ); # FIXME? This is weird, the FU fine is created ( _CalculateAndUpdateFine > C4::Overdues::UpdateFine ) then remove later (in _FixOverduesOnReturn). Looks like it is a feature
1721
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue in dropbox mode' ); # FIXME? This is weird, the FU fine is created ( _CalculateAndUpdateFine > C4::Overdues::UpdateFine ) then remove later (in _FixOverduesOnReturn). Looks like it is a feature
1724
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1722
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1723
};
1724
1725
subtest '_FixAccountForLostAndReturned' => sub {
1726
    plan tests => 2;
1727
1728
    # Generate test biblio
1729
    my $biblio = MARC::Record->new();
1730
    my $title  = 'Koha for Dummies';
1731
    $biblio->append_fields(
1732
        MARC::Field->new( '100', ' ', ' ', a => 'Hall, Daria' ),
1733
        MARC::Field->new( '245', ' ', ' ', a => $title ),
1734
    );
1735
1736
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
1737
1738
    my $barcode = 'KD123456789';
1739
    my $branchcode  = $library2->{branchcode};
1740
1741
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
1742
        {
1743
            homebranch       => $branchcode,
1744
            holdingbranch    => $branchcode,
1745
            barcode          => $barcode,
1746
            replacementprice => 99.00,
1747
            itype            => $itemtype
1748
        },
1749
        $biblionumber
1750
    );
1751
1752
    my $patron = $builder->build( { source => 'Borrower' } );
1753
1754
    my $accountline = Koha::Account::Line->new(
1755
        {
1756
            borrowernumber => $patron->{borrowernumber},
1757
            accounttype    => 'L',
1758
            itemnumber     => $itemnumber,
1759
            amount => 99.00,
1760
            amountoutstanding => 99.00,
1761
        }
1762
    )->store();
1763
1764
    C4::Circulation::_FixAccountForLostAndReturned( $itemnumber, $patron->{borrowernumber} );
1765
1766
    $accountline->_result()->discard_changes();
1767
1768
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee has no outstanding amount' );
1769
    is( $accountline->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )');
1770
};
1771
1772
subtest '_FixOverduesOnReturn' => sub {
1773
    plan tests => 6;
1774
1775
    # Generate test biblio
1776
    my $biblio = MARC::Record->new();
1777
    my $title  = 'Koha for Dummies';
1778
    $biblio->append_fields(
1779
        MARC::Field->new( '100', ' ', ' ', a => 'Hall, Kylie' ),
1780
        MARC::Field->new( '245', ' ', ' ', a => $title ),
1781
    );
1782
1783
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
1784
1785
    my $barcode = 'KD987654321';
1786
    my $branchcode  = $library2->{branchcode};
1787
1788
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
1789
        {
1790
            homebranch       => $branchcode,
1791
            holdingbranch    => $branchcode,
1792
            barcode          => $barcode,
1793
            replacementprice => 99.00,
1794
            itype            => $itemtype
1795
        },
1796
        $biblionumber
1797
    );
1798
1799
    my $patron = $builder->build( { source => 'Borrower' } );
1800
1801
    ## Start with basic call, should just close out the open fine
1802
    my $accountline = Koha::Account::Line->new(
1803
        {
1804
            borrowernumber => $patron->{borrowernumber},
1805
            accounttype    => 'FU',
1806
            itemnumber     => $itemnumber,
1807
            amount => 99.00,
1808
            amountoutstanding => 99.00,
1809
            lastincrement => 9.00,
1810
        }
1811
    )->store();
1812
1813
    C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $itemnumber );
1814
1815
    $accountline->_result()->discard_changes();
1816
1817
    is( $accountline->amountoutstanding, '99.000000', 'Fine has the same amount outstanding as previously' );
1818
    is( $accountline->accounttype, 'F', 'Open fine ( account type FU ) has been closed out ( account type F )');
1819
1820
1821
    ## Run again, with exemptfine enabled
1822
    $accountline->set(
1823
        {
1824
            accounttype    => 'FU',
1825
            amountoutstanding => 99.00,
1826
        }
1827
    )->store();
1828
1829
    C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $itemnumber, 1 );
1830
1831
    $accountline->_result()->discard_changes();
1832
1833
    is( $accountline->amountoutstanding, '0.000000', 'Fine has been reduced to 0' );
1834
    is( $accountline->accounttype, 'FFOR', 'Open fine ( account type FU ) has been set to fine forgiven ( account type FFOR )');
1835
1836
    ## Run again, with dropbox mode enabled
1837
    $accountline->set(
1838
        {
1839
            accounttype    => 'FU',
1840
            amountoutstanding => 99.00,
1841
        }
1842
    )->store();
1843
1844
    C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $itemnumber, 0, 1 );
1845
1846
    $accountline->_result()->discard_changes();
1725
1847
1848
    is( $accountline->amountoutstanding, '90.000000', 'Fine has been reduced to 90' );
1849
    is( $accountline->accounttype, 'F', 'Open fine ( account type FU ) has been closed out ( account type F )');
1726
};
1850
};
1727
1851
1728
sub set_userenv {
1852
sub set_userenv {
1729
- 

Return to bug 14826