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

(-)a/C4/Circulation.pm (-2 / +12 lines)
Lines 2246-2253 sub _debar_user_on_return { Link Here
2246
                );
2246
                );
2247
            }
2247
            }
2248
2248
2249
            my $new_debar_dt =
2249
            my $new_debar_dt;
2250
              $return_date->clone()->add_duration( $suspension_days );
2250
            # Use the calendar or not to calculate the debarment date
2251
            if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
2252
                my $calendar = Koha::Calendar->new(
2253
                    branchcode => $branchcode,
2254
                    days_mode  => 'Calendar'
2255
                );
2256
                $new_debar_dt = $calendar->addDate( $return_date, $suspension_days );
2257
            }
2258
            else {
2259
                $new_debar_dt = $return_date->clone()->add_duration($suspension_days);
2260
            }
2251
2261
2252
            Koha::Patron::Debarments::AddUniqueDebarment({
2262
            Koha::Patron::Debarments::AddUniqueDebarment({
2253
                borrowernumber => $borrower->{borrowernumber},
2263
                borrowernumber => $borrower->{borrowernumber},
(-)a/Koha/Calendar.pm (-1 / +1 lines)
Lines 47-53 sub _init { Link Here
47
          1;
47
          1;
48
    }
48
    }
49
49
50
    $self->{days_mode}       = C4::Context->preference('useDaysMode');
50
    $self->{days_mode}       ||= C4::Context->preference('useDaysMode');
51
    $self->{test}            = 0;
51
    $self->{test}            = 0;
52
    return;
52
    return;
53
}
53
}
(-)a/t/db_dependent/Circulation.t (-3 / +75 lines)
Lines 24-29 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;
27
use C4::Circulation;
28
use C4::Circulation;
28
use C4::Biblio;
29
use C4::Biblio;
29
use C4::Items;
30
use C4::Items;
Lines 48-53 my $dbh = C4::Context->dbh; Link Here
48
# Start transaction
49
# Start transaction
49
$dbh->{RaiseError} = 1;
50
$dbh->{RaiseError} = 1;
50
51
52
my $cache = Koha::Caches->get_instance();
53
$dbh->do(q|DELETE FROM special_holidays|);
54
$dbh->do(q|DELETE FROM repeatable_holidays|);
55
$cache->clear_from_cache('single_holidays');
56
51
# Start with a clean slate
57
# Start with a clean slate
52
$dbh->do('DELETE FROM issues');
58
$dbh->do('DELETE FROM issues');
53
$dbh->do('DELETE FROM borrowers');
59
$dbh->do('DELETE FROM borrowers');
Lines 1758-1764 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1758
};
1764
};
1759
1765
1760
subtest 'AddReturn + suspension_chargeperiod' => sub {
1766
subtest 'AddReturn + suspension_chargeperiod' => sub {
1761
    plan tests => 6;
1767
    plan tests => 8;
1762
1768
1763
    my $library = $builder->build( { source => 'Branch' } );
1769
    my $library = $builder->build( { source => 'Branch' } );
1764
    my $patron  = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } );
1770
    my $patron  = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } );
Lines 1863-1871 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
1863
    Koha::Patron::Debarments::DelUniqueDebarment(
1869
    Koha::Patron::Debarments::DelUniqueDebarment(
1864
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1870
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1865
1871
1866
};
1872
1873
    # We want to charge 2 days every days, with 0 day of grace (to not burn brains)
1874
    $rule->finedays(2)->store;
1875
    $rule->suspension_chargeperiod(1)->store;
1876
    $rule->firstremind(0)->store;
1877
    t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed');
1878
1879
    # Adding a holiday 2 days ago
1880
    my $calendar = C4::Calendar->new(branchcode => $library->{branchcode});
1881
    my $two_days_ago = dt_from_string->subtract( days => 2 );
1882
    $calendar->insert_single_holiday(
1883
        day             => $two_days_ago->day,
1884
        month           => $two_days_ago->month,
1885
        year            => $two_days_ago->year,
1886
        title           => 'holidayTest-2d',
1887
        description     => 'holidayDesc 2 days ago'
1888
    );
1889
1890
    # With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday)
1891
    AddIssue( $patron, $item_1->{barcode}, $five_days_ago );    # Add an overdue
1892
1893
    AddReturn( $item_1->{barcode}, $library->{branchcode},
1894
        undef, undef, dt_from_string );
1895
    $debarments = Koha::Patron::Debarments::GetDebarments(
1896
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1897
    $expected_expiration = output_pref(
1898
        {
1899
            dt         => dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) ),
1900
            dateformat => 'sql',
1901
            dateonly   => 1
1902
        }
1903
    );
1904
    is( $debarments->[0]->{expiration}, $expected_expiration );
1905
    Koha::Patron::Debarments::DelUniqueDebarment(
1906
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1867
1907
1868
1908
1909
    my $two_days_ahead = dt_from_string->add( days => 2 );
1910
    $calendar->insert_single_holiday(
1911
        day             => $two_days_ahead->day,
1912
        month           => $two_days_ahead->month,
1913
        year            => $two_days_ahead->year,
1914
        title           => 'holidayTest+2d',
1915
        description     => 'holidayDesc 2 days ahead'
1916
    );
1917
1918
    # Same as above, but we should skip D+2
1919
    AddIssue( $patron, $item_1->{barcode}, $five_days_ago );    # Add an overdue
1920
1921
    AddReturn( $item_1->{barcode}, $library->{branchcode},
1922
        undef, undef, dt_from_string );
1923
    $debarments = Koha::Patron::Debarments::GetDebarments(
1924
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1925
    $expected_expiration = output_pref(
1926
        {
1927
            dt         => dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 ),
1928
            dateformat => 'sql',
1929
            dateonly   => 1
1930
        }
1931
    );
1932
    is( $debarments->[0]->{expiration}, $expected_expiration );
1933
    Koha::Patron::Debarments::DelUniqueDebarment(
1934
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
1935
1936
};
1937
1869
subtest 'AddReturn | is_overdue' => sub {
1938
subtest 'AddReturn | is_overdue' => sub {
1870
    plan tests => 5;
1939
    plan tests => 5;
1871
1940
Lines 2163-2168 subtest 'CanBookBeIssued | is_overdue' => sub { Link Here
2163
2232
2164
};
2233
};
2165
2234
2235
2236
$schema->storage->txn_rollback;
2237
$cache->clear_from_cache('single_holidays');
2238
2166
sub set_userenv {
2239
sub set_userenv {
2167
    my ( $library ) = @_;
2240
    my ( $library ) = @_;
2168
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', '');
2241
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', '');
2169
- 

Return to bug 19204