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 => 103;
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 1780-1786 subtest 'AddReturn | is_overdue' => sub { Link Here
1780
    AddReturn( $item->{barcode}, $library->{branchcode}, undef, 1, undef, $five_days_ago );
1778
    AddReturn( $item->{barcode}, $library->{branchcode}, undef, 1, undef, $five_days_ago );
1781
    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
1779
    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
1782
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1780
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
1781
};
1782
1783
subtest '_FixAccountForLostAndReturned' => sub {
1784
    plan tests => 2;
1785
1786
    # Generate test biblio
1787
    my $biblio = MARC::Record->new();
1788
    my $title  = 'Koha for Dummies';
1789
    $biblio->append_fields(
1790
        MARC::Field->new( '100', ' ', ' ', a => 'Hall, Daria' ),
1791
        MARC::Field->new( '245', ' ', ' ', a => $title ),
1792
    );
1793
1794
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
1795
1796
    my $barcode = 'KD123456789';
1797
    my $branchcode  = $library2->{branchcode};
1798
1799
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
1800
        {
1801
            homebranch       => $branchcode,
1802
            holdingbranch    => $branchcode,
1803
            barcode          => $barcode,
1804
            replacementprice => 99.00,
1805
            itype            => $itemtype
1806
        },
1807
        $biblionumber
1808
    );
1809
1810
    my $patron = $builder->build( { source => 'Borrower' } );
1811
1812
    my $accountline = Koha::Account::Line->new(
1813
        {
1814
            borrowernumber => $patron->{borrowernumber},
1815
            accounttype    => 'L',
1816
            itemnumber     => $itemnumber,
1817
            amount => 99.00,
1818
            amountoutstanding => 99.00,
1819
        }
1820
    )->store();
1821
1822
    C4::Circulation::_FixAccountForLostAndReturned( $itemnumber, $patron->{borrowernumber} );
1823
1824
    $accountline->_result()->discard_changes();
1825
1826
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee has no outstanding amount' );
1827
    is( $accountline->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )');
1828
};
1829
1830
subtest '_FixOverduesOnReturn' => sub {
1831
    plan tests => 6;
1832
1833
    # Generate test biblio
1834
    my $biblio = MARC::Record->new();
1835
    my $title  = 'Koha for Dummies';
1836
    $biblio->append_fields(
1837
        MARC::Field->new( '100', ' ', ' ', a => 'Hall, Kylie' ),
1838
        MARC::Field->new( '245', ' ', ' ', a => $title ),
1839
    );
1840
1841
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
1842
1843
    my $barcode = 'KD987654321';
1844
    my $branchcode  = $library2->{branchcode};
1845
1846
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
1847
        {
1848
            homebranch       => $branchcode,
1849
            holdingbranch    => $branchcode,
1850
            barcode          => $barcode,
1851
            replacementprice => 99.00,
1852
            itype            => $itemtype
1853
        },
1854
        $biblionumber
1855
    );
1856
1857
    my $patron = $builder->build( { source => 'Borrower' } );
1858
1859
    ## Start with basic call, should just close out the open fine
1860
    my $accountline = Koha::Account::Line->new(
1861
        {
1862
            borrowernumber => $patron->{borrowernumber},
1863
            accounttype    => 'FU',
1864
            itemnumber     => $itemnumber,
1865
            amount => 99.00,
1866
            amountoutstanding => 99.00,
1867
            lastincrement => 9.00,
1868
        }
1869
    )->store();
1870
1871
    C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $itemnumber );
1872
1873
    $accountline->_result()->discard_changes();
1874
1875
    is( $accountline->amountoutstanding, '99.000000', 'Fine has the same amount outstanding as previously' );
1876
    is( $accountline->accounttype, 'F', 'Open fine ( account type FU ) has been closed out ( account type F )');
1877
1878
1879
    ## Run again, with exemptfine enabled
1880
    $accountline->set(
1881
        {
1882
            accounttype    => 'FU',
1883
            amountoutstanding => 99.00,
1884
        }
1885
    )->store();
1886
1887
    C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $itemnumber, 1 );
1888
1889
    $accountline->_result()->discard_changes();
1890
1891
    is( $accountline->amountoutstanding, '0.000000', 'Fine has been reduced to 0' );
1892
    is( $accountline->accounttype, 'FFOR', 'Open fine ( account type FU ) has been set to fine forgiven ( account type FFOR )');
1893
1894
    ## Run again, with dropbox mode enabled
1895
    $accountline->set(
1896
        {
1897
            accounttype    => 'FU',
1898
            amountoutstanding => 99.00,
1899
        }
1900
    )->store();
1901
1902
    C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $itemnumber, 0, 1 );
1903
1904
    $accountline->_result()->discard_changes();
1783
1905
1906
    is( $accountline->amountoutstanding, '90.000000', 'Fine has been reduced to 90' );
1907
    is( $accountline->accounttype, 'F', 'Open fine ( account type FU ) has been closed out ( account type F )');
1784
};
1908
};
1785
1909
1786
subtest 'Set waiting flag' => sub {
1910
subtest 'Set waiting flag' => sub {
1787
- 

Return to bug 14826