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::DiscreteCalendar->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 (-40 / +36 lines)
Lines 37-42 use C4::Reserves; Link Here
37
use C4::Overdues qw(UpdateFine CalcFine);
37
use C4::Overdues qw(UpdateFine CalcFine);
38
use Koha::DateUtils;
38
use Koha::DateUtils;
39
use Koha::Database;
39
use Koha::Database;
40
use Koha::DiscreteCalendar;
40
use Koha::IssuingRules;
41
use Koha::IssuingRules;
41
use Koha::Checkouts;
42
use Koha::Checkouts;
42
use Koha::Patrons;
43
use Koha::Patrons;
Lines 53-60 my $dbh = C4::Context->dbh; Link Here
53
$dbh->{RaiseError} = 1;
54
$dbh->{RaiseError} = 1;
54
55
55
my $cache = Koha::Caches->get_instance();
56
my $cache = Koha::Caches->get_instance();
56
$dbh->do(q|DELETE FROM special_holidays|);
57
$dbh->do(q|DELETE FROM repeatable_holidays|);
58
$cache->clear_from_cache('single_holidays');
57
$cache->clear_from_cache('single_holidays');
59
58
60
# Start with a clean slate
59
# Start with a clean slate
Lines 1727-1742 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
1727
    );
1726
    );
1728
    $rule->store();
1727
    $rule->store();
1729
1728
1730
    my $five_days_ago = dt_from_string->subtract( days => 5 );
1729
    my $in_five_days = dt_from_string->add( days => 5 );
1731
    # We want to charge 2 days every day, without grace
1730
    # We want to charge 2 days every day, without grace
1732
    # With 5 days of overdue: 5 * Z
1731
    # With 5 days of overdue: 5 * Z
1733
    my $expected_expiration = dt_from_string->add( days => ( 5 * 2 ) / 1 );
1732
    my $expected_expiration = dt_from_string->add( days => 5 + ( 5 * 2 ) / 1 );
1734
    test_debarment_on_checkout(
1733
    test_debarment_on_checkout(
1735
        {
1734
        {
1736
            item            => $item_1,
1735
            item            => $item_1,
1737
            library         => $library,
1736
            library         => $library,
1738
            patron          => $patron,
1737
            patron          => $patron,
1739
            due_date        => $five_days_ago,
1738
            return_date     => $in_five_days,
1740
            expiration_date => $expected_expiration,
1739
            expiration_date => $expected_expiration,
1741
        }
1740
        }
1742
    );
1741
    );
Lines 1744-1756 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
1744
    # We want to charge 2 days every 2 days, without grace
1743
    # We want to charge 2 days every 2 days, without grace
1745
    # With 5 days of overdue: (5 * 2) / 2
1744
    # With 5 days of overdue: (5 * 2) / 2
1746
    $rule->suspension_chargeperiod(2)->store;
1745
    $rule->suspension_chargeperiod(2)->store;
1747
    $expected_expiration = dt_from_string->add( days => floor( 5 * 2 ) / 2 );
1746
    $expected_expiration = dt_from_string->add( days => 5 + floor( 5 * 2 ) / 2 );
1748
    test_debarment_on_checkout(
1747
    test_debarment_on_checkout(
1749
        {
1748
        {
1750
            item            => $item_1,
1749
            item            => $item_1,
1751
            library         => $library,
1750
            library         => $library,
1752
            patron          => $patron,
1751
            patron          => $patron,
1753
            due_date        => $five_days_ago,
1752
            return_date     => $in_five_days,
1754
            expiration_date => $expected_expiration,
1753
            expiration_date => $expected_expiration,
1755
        }
1754
        }
1756
    );
1755
    );
Lines 1759-1771 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
1759
    # With 5 days of overdue: ((5-1) / 3 ) * 2
1758
    # With 5 days of overdue: ((5-1) / 3 ) * 2
1760
    $rule->suspension_chargeperiod(3)->store;
1759
    $rule->suspension_chargeperiod(3)->store;
1761
    $rule->firstremind(1)->store;
1760
    $rule->firstremind(1)->store;
1762
    $expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) );
1761
    $expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 1 ) / 3 ) * 2 ) );
1763
    test_debarment_on_checkout(
1762
    test_debarment_on_checkout(
1764
        {
1763
        {
1765
            item            => $item_1,
1764
            item            => $item_1,
1766
            library         => $library,
1765
            library         => $library,
1767
            patron          => $patron,
1766
            patron          => $patron,
1768
            due_date        => $five_days_ago,
1767
            return_date     => $in_five_days,
1769
            expiration_date => $expected_expiration,
1768
            expiration_date => $expected_expiration,
1770
        }
1769
        }
1771
    );
1770
    );
Lines 1778-1842 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
1778
    t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed');
1777
    t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed');
1779
1778
1780
    # Adding a holiday 2 days ago
1779
    # Adding a holiday 2 days ago
1781
    my $calendar = C4::Calendar->new(branchcode => $library->{branchcode});
1780
    my $calendar = Koha::DiscreteCalendar->new( { branchcode => $library->{branchcode} } );
1782
    my $two_days_ago = dt_from_string->subtract( days => 2 );
1781
    my $in_two_days = dt_from_string->add( days => 2 );
1783
    $calendar->insert_single_holiday(
1782
    $calendar->edit_holiday( {
1784
        day             => $two_days_ago->day,
1783
        title           => 'holidayTest+2d',
1785
        month           => $two_days_ago->month,
1784
        holiday_type    => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},,
1786
        year            => $two_days_ago->year,
1785
        start_date      => $in_two_days,
1787
        title           => 'holidayTest-2d',
1786
        end_date        => $in_two_days,
1788
        description     => 'holidayDesc 2 days ago'
1787
    } );
1789
    );
1790
    # With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday)
1788
    # With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday)
1791
    $expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) );
1789
    $expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) );
1792
    test_debarment_on_checkout(
1790
    test_debarment_on_checkout(
1793
        {
1791
        {
1794
            item            => $item_1,
1792
            item            => $item_1,
1795
            library         => $library,
1793
            library         => $library,
1796
            patron          => $patron,
1794
            patron          => $patron,
1797
            due_date        => $five_days_ago,
1795
            return_date     => $in_five_days,
1798
            expiration_date => $expected_expiration,
1796
            expiration_date => $expected_expiration,
1799
        }
1797
        }
1800
    );
1798
    );
1801
1799
1802
    # Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped
1800
    # Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped
1803
    my $two_days_ahead = dt_from_string->add( days => 2 );
1801
    my $in_seven_days = dt_from_string->add( days => 7 );
1804
    $calendar->insert_single_holiday(
1802
    $calendar->edit_holiday( {
1805
        day             => $two_days_ahead->day,
1803
        title           => 'holidayTest+7d',
1806
        month           => $two_days_ahead->month,
1804
        holiday_type    => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
1807
        year            => $two_days_ahead->year,
1805
        start_date      => $in_seven_days,
1808
        title           => 'holidayTest+2d',
1806
        end_date        => $in_seven_days,
1809
        description     => 'holidayDesc 2 days ahead'
1807
    } );
1810
    );
1811
1808
1812
    # Same as above, but we should skip D+2
1809
    # Same as above, but we should skip D+2
1813
    $expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 );
1810
    $expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 );
1814
    test_debarment_on_checkout(
1811
    test_debarment_on_checkout(
1815
        {
1812
        {
1816
            item            => $item_1,
1813
            item            => $item_1,
1817
            library         => $library,
1814
            library         => $library,
1818
            patron          => $patron,
1815
            patron          => $patron,
1819
            due_date        => $five_days_ago,
1816
            return_date     => $in_five_days,
1820
            expiration_date => $expected_expiration,
1817
            expiration_date => $expected_expiration,
1821
        }
1818
        }
1822
    );
1819
    );
1823
1820
1824
    # Adding another holiday, day of expiration date
1821
    # Adding another holiday, day of expiration date
1825
    my $expected_expiration_dt = dt_from_string($expected_expiration);
1822
    my $expected_expiration_dt = dt_from_string($expected_expiration);
1826
    $calendar->insert_single_holiday(
1823
    $calendar->edit_holiday( {
1827
        day             => $expected_expiration_dt->day,
1824
        title           => 'holidayTest+expected_expiration',
1828
        month           => $expected_expiration_dt->month,
1825
        holiday_type    => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
1829
        year            => $expected_expiration_dt->year,
1826
        start_date      => $expected_expiration_dt,
1830
        title           => 'holidayTest_exp',
1827
        end_date        => $expected_expiration_dt,
1831
        description     => 'holidayDesc on expiration date'
1828
    } );
1832
    );
1829
1833
    # Expiration date will be the day after
1830
    # Expiration date will be the day after
1834
    test_debarment_on_checkout(
1831
    test_debarment_on_checkout(
1835
        {
1832
        {
1836
            item            => $item_1,
1833
            item            => $item_1,
1837
            library         => $library,
1834
            library         => $library,
1838
            patron          => $patron,
1835
            patron          => $patron,
1839
            due_date        => $five_days_ago,
1836
            return_date     => $in_five_days,
1840
            expiration_date => $expected_expiration_dt->clone->add( days => 1 ),
1837
            expiration_date => $expected_expiration_dt->clone->add( days => 1 ),
1841
        }
1838
        }
1842
    );
1839
    );
Lines 1847-1853 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
1847
            library         => $library,
1844
            library         => $library,
1848
            patron          => $patron,
1845
            patron          => $patron,
1849
            return_date     => dt_from_string->add(days => 5),
1846
            return_date     => dt_from_string->add(days => 5),
1850
            expiration_date => dt_from_string->add(days => 5 + (5 * 2 - 1) ),
1847
            expiration_date => dt_from_string->add(days => 5 + (5 * 2 - 1) + 1 ), # We add an extra +1 because of the holiday
1851
        }
1848
        }
1852
    );
1849
    );
1853
};
1850
};
1854
- 

Return to bug 17015