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

(-)a/C4/Circulation.pm (-2 / +2 lines)
Lines 2252-2261 sub _debar_user_on_return { Link Here
2252
            my $new_debar_dt;
2252
            my $new_debar_dt;
2253
            # Use the calendar or not to calculate the debarment date
2253
            # Use the calendar or not to calculate the debarment date
2254
            if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
2254
            if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
2255
                my $calendar = Koha::Calendar->new(
2255
                my $calendar = Koha::DiscreteCalendar->new( {
2256
                    branchcode => $branchcode,
2256
                    branchcode => $branchcode,
2257
                    days_mode  => 'Calendar'
2257
                    days_mode  => 'Calendar'
2258
                );
2258
                } );
2259
                $new_debar_dt = $calendar->addDate( $return_date, $suspension_days );
2259
                $new_debar_dt = $calendar->addDate( $return_date, $suspension_days );
2260
            }
2260
            }
2261
            else {
2261
            else {
(-)a/Koha/DiscreteCalendar.pm (-1 / +1 lines)
Lines 90-96 sub new { Link Here
90
90
91
sub _init {
91
sub _init {
92
    my $self = shift;
92
    my $self = shift;
93
    $self->{days_mode} = C4::Context->preference('useDaysMode');
93
    $self->{days_mode} ||= C4::Context->preference('useDaysMode');
94
    #If the branchcode doesn't exist we use the default calendar.
94
    #If the branchcode doesn't exist we use the default calendar.
95
    my $schema = Koha::Database->new->schema;
95
    my $schema = Koha::Database->new->schema;
96
    my $branchcode = $self->{branchcode};
96
    my $branchcode = $self->{branchcode};
(-)a/t/db_dependent/Circulation.t (-38 / +45 lines)
Lines 24-30 use POSIX qw( floor ); Link Here
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
26
26
27
use C4::Calendar;
28
use C4::Circulation;
27
use C4::Circulation;
29
use C4::Biblio;
28
use C4::Biblio;
30
use C4::Items;
29
use C4::Items;
Lines 33-38 use C4::Reserves; Link Here
33
use C4::Overdues qw(UpdateFine CalcFine);
32
use C4::Overdues qw(UpdateFine CalcFine);
34
use Koha::DateUtils;
33
use Koha::DateUtils;
35
use Koha::Database;
34
use Koha::Database;
35
use Koha::DiscreteCalendar;
36
use Koha::IssuingRules;
36
use Koha::IssuingRules;
37
use Koha::Checkouts;
37
use Koha::Checkouts;
38
use Koha::Patrons;
38
use Koha::Patrons;
Lines 1779-1794 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
1779
    );
1779
    );
1780
    $rule->store();
1780
    $rule->store();
1781
1781
1782
    my $five_days_ago = dt_from_string->subtract( days => 5 );
1782
    my $in_five_days = dt_from_string->add( days => 5 );
1783
    # We want to charge 2 days every day, without grace
1783
    # We want to charge 2 days every day, without grace
1784
    # With 5 days of overdue: 5 * Z
1784
    # With 5 days of overdue: 5 * Z
1785
    my $expected_expiration = dt_from_string->add( days => ( 5 * 2 ) / 1 );
1785
    my $expected_expiration = dt_from_string->add( days => 5 + ( 5 * 2 ) / 1 );
1786
    test_debarment_on_checkout(
1786
    test_debarment_on_checkout(
1787
        {
1787
        {
1788
            item            => $item_1,
1788
            item            => $item_1,
1789
            library         => $library,
1789
            library         => $library,
1790
            patron          => $patron,
1790
            patron          => $patron,
1791
            due_date        => $five_days_ago,
1791
            return_date     => $in_five_days,
1792
            expiration_date => $expected_expiration,
1792
            expiration_date => $expected_expiration,
1793
        }
1793
        }
1794
    );
1794
    );
Lines 1796-1808 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
1796
    # We want to charge 2 days every 2 days, without grace
1796
    # We want to charge 2 days every 2 days, without grace
1797
    # With 5 days of overdue: (5 * 2) / 2
1797
    # With 5 days of overdue: (5 * 2) / 2
1798
    $rule->suspension_chargeperiod(2)->store;
1798
    $rule->suspension_chargeperiod(2)->store;
1799
    $expected_expiration = dt_from_string->add( days => floor( 5 * 2 ) / 2 );
1799
    $expected_expiration = dt_from_string->add( days => 5 + floor( 5 * 2 ) / 2 );
1800
    test_debarment_on_checkout(
1800
    test_debarment_on_checkout(
1801
        {
1801
        {
1802
            item            => $item_1,
1802
            item            => $item_1,
1803
            library         => $library,
1803
            library         => $library,
1804
            patron          => $patron,
1804
            patron          => $patron,
1805
            due_date        => $five_days_ago,
1805
            return_date     => $in_five_days,
1806
            expiration_date => $expected_expiration,
1806
            expiration_date => $expected_expiration,
1807
        }
1807
        }
1808
    );
1808
    );
Lines 1811-1823 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
1811
    # With 5 days of overdue: ((5-1) / 3 ) * 2
1811
    # With 5 days of overdue: ((5-1) / 3 ) * 2
1812
    $rule->suspension_chargeperiod(3)->store;
1812
    $rule->suspension_chargeperiod(3)->store;
1813
    $rule->firstremind(1)->store;
1813
    $rule->firstremind(1)->store;
1814
    $expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) );
1814
    $expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 1 ) / 3 ) * 2 ) );
1815
    test_debarment_on_checkout(
1815
    test_debarment_on_checkout(
1816
        {
1816
        {
1817
            item            => $item_1,
1817
            item            => $item_1,
1818
            library         => $library,
1818
            library         => $library,
1819
            patron          => $patron,
1819
            patron          => $patron,
1820
            due_date        => $five_days_ago,
1820
            return_date     => $in_five_days,
1821
            expiration_date => $expected_expiration,
1821
            expiration_date => $expected_expiration,
1822
        }
1822
        }
1823
    );
1823
    );
Lines 1830-1897 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
1830
    t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed');
1830
    t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed');
1831
1831
1832
    # Adding a holiday 2 days ago
1832
    # Adding a holiday 2 days ago
1833
    my $calendar = C4::Calendar->new(branchcode => $library->{branchcode});
1833
    my $calendar = Koha::DiscreteCalendar->new( { branchcode => $library->{branchcode} } );
1834
    my $two_days_ago = dt_from_string->subtract( days => 2 );
1834
    my $in_two_days = dt_from_string->add( days => 2 );
1835
    $calendar->insert_single_holiday(
1835
    $calendar->edit_holiday( {
1836
        day             => $two_days_ago->day,
1836
        title           => 'holidayTest+2d',
1837
        month           => $two_days_ago->month,
1837
        holiday_type    => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},,
1838
        year            => $two_days_ago->year,
1838
        start_date      => $in_two_days,
1839
        title           => 'holidayTest-2d',
1839
        end_date        => $in_two_days,
1840
        description     => 'holidayDesc 2 days ago'
1840
    } );
1841
    );
1842
    # With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday)
1841
    # With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday)
1843
    $expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) );
1842
    $expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) );
1844
    test_debarment_on_checkout(
1843
    test_debarment_on_checkout(
1845
        {
1844
        {
1846
            item            => $item_1,
1845
            item            => $item_1,
1847
            library         => $library,
1846
            library         => $library,
1848
            patron          => $patron,
1847
            patron          => $patron,
1849
            due_date        => $five_days_ago,
1848
            return_date     => $in_five_days,
1850
            expiration_date => $expected_expiration,
1849
            expiration_date => $expected_expiration,
1851
        }
1850
        }
1852
    );
1851
    );
1853
1852
1854
    # Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped
1853
    # Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped
1855
    my $two_days_ahead = dt_from_string->add( days => 2 );
1854
    my $in_seven_days = dt_from_string->add( days => 7 );
1856
    $calendar->insert_single_holiday(
1855
    $calendar->edit_holiday( {
1857
        day             => $two_days_ahead->day,
1856
        title           => 'holidayTest+7d',
1858
        month           => $two_days_ahead->month,
1857
        holiday_type    => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
1859
        year            => $two_days_ahead->year,
1858
        start_date      => $in_seven_days,
1860
        title           => 'holidayTest+2d',
1859
        end_date        => $in_seven_days,
1861
        description     => 'holidayDesc 2 days ahead'
1860
    } );
1862
    );
1863
1861
1864
    # Same as above, but we should skip D+2
1862
    # Same as above, but we should skip D+2
1865
    $expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 );
1863
    $expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 );
1866
    test_debarment_on_checkout(
1864
    test_debarment_on_checkout(
1867
        {
1865
        {
1868
            item            => $item_1,
1866
            item            => $item_1,
1869
            library         => $library,
1867
            library         => $library,
1870
            patron          => $patron,
1868
            patron          => $patron,
1871
            due_date        => $five_days_ago,
1869
            return_date     => $in_five_days,
1872
            expiration_date => $expected_expiration,
1870
            expiration_date => $expected_expiration,
1873
        }
1871
        }
1874
    );
1872
    );
1875
1873
1876
    # Adding another holiday, day of expiration date
1874
    # Adding another holiday, day of expiration date
1877
    my $expected_expiration_dt = dt_from_string($expected_expiration);
1875
    my $expected_expiration_dt = dt_from_string($expected_expiration);
1878
    $calendar->insert_single_holiday(
1876
    $calendar->edit_holiday( {
1879
        day             => $expected_expiration_dt->day,
1877
        title           => 'holidayTest+expected_expiration',
1880
        month           => $expected_expiration_dt->month,
1878
        holiday_type    => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
1881
        year            => $expected_expiration_dt->year,
1879
        start_date      => $expected_expiration_dt,
1882
        title           => 'holidayTest_exp',
1880
        end_date        => $expected_expiration_dt,
1883
        description     => 'holidayDesc on expiration date'
1881
    } );
1884
    );
1882
1885
    # Expiration date will be the day after
1883
    # Expiration date will be the day after
1886
    test_debarment_on_checkout(
1884
    test_debarment_on_checkout(
1887
        {
1885
        {
1888
            item            => $item_1,
1886
            item            => $item_1,
1889
            library         => $library,
1887
            library         => $library,
1890
            patron          => $patron,
1888
            patron          => $patron,
1891
            due_date        => $five_days_ago,
1889
            return_date     => $in_five_days,
1892
            expiration_date => $expected_expiration_dt->clone->add( days => 1 ),
1890
            expiration_date => $expected_expiration_dt->clone->add( days => 1 ),
1893
        }
1891
        }
1894
    );
1892
    );
1893
1894
    test_debarment_on_checkout(
1895
        {
1896
            item            => $item_1,
1897
            library         => $library,
1898
            patron          => $patron,
1899
            return_date     => dt_from_string->add(days => 5),
1900
            expiration_date => dt_from_string->add(days => 5 + (5 * 2 - 1) + 1 ), # We add an extra +1 because of the holiday
1901
        }
1902
    );
1895
};
1903
};
1896
1904
1897
subtest 'AddReturn | is_overdue' => sub {
1905
subtest 'AddReturn | is_overdue' => sub {
1898
- 

Return to bug 17015