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

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

Return to bug 17015