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

(-)a/Koha/Patron.pm (-6 / +5 lines)
Lines 973-984 sub can_request_article { Link Here
973
973
974
    return 1 unless defined $limit;
974
    return 1 unless defined $limit;
975
975
976
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
976
    my $count = Koha::ArticleRequests->search(
977
    my $compdate = dt_from_string->add( days => -1 );
977
        [   { borrowernumber => $self->borrowernumber, status => [ 'REQUESTED', 'PENDING', 'PROCESSING' ] },
978
    my $count = Koha::ArticleRequests->search([
978
            { borrowernumber => $self->borrowernumber, status => 'COMPLETED', updated_on => { '>=' => \'DATE(NOW())' } },
979
        { borrowernumber => $self->borrowernumber, status => ['REQUESTED','PENDING','PROCESSING'] },
979
        ]
980
        { borrowernumber => $self->borrowernumber, status => 'COMPLETED', updated_on => { '>', $dtf->format_date($compdate) }},
980
    )->count;
981
    ])->count;
982
    return $count < $limit ? 1 : 0;
981
    return $count < $limit ? 1 : 0;
983
}
982
}
984
983
(-)a/t/db_dependent/Koha/Patron.t (-2 / +53 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 9;
22
use Test::More tests => 10;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::Warn;
24
use Test::Warn;
25
25
Lines 831-833 subtest 'can_request_article() tests' => sub { Link Here
831
831
832
    $schema->storage->txn_rollback;
832
    $schema->storage->txn_rollback;
833
};
833
};
834
- 
834
835
subtest 'can_request_article() tests' => sub {
836
837
    plan tests => 3;
838
839
    $schema->storage->txn_begin;
840
841
    my $category = $builder->build_object(
842
        {
843
            class => 'Koha::Patron::Categories',
844
            value => { article_request_limit => 4 }
845
        }
846
    );
847
    my $patron = $builder->build_object(
848
        {
849
            class => 'Koha::Patrons',
850
            value => { categorycode => $category->id }
851
        }
852
    );
853
854
    $builder->build_object( { class => 'Koha::ArticleRequests', value => { status => 'REQUESTED',  borrowernumber => $patron->id } } );
855
    $builder->build_object( { class => 'Koha::ArticleRequests', value => { status => 'PENDING',    borrowernumber => $patron->id } } );
856
    $builder->build_object( { class => 'Koha::ArticleRequests', value => { status => 'PROCESSING', borrowernumber => $patron->id } } );
857
    $builder->build_object( { class => 'Koha::ArticleRequests', value => { status => 'CANCELED',   borrowernumber => $patron->id } } );
858
859
    ok( $patron->can_request_article, 'Patron has 3 current requests, 4 is the limit: allowed' );
860
861
    # Completed request, same day
862
    my $completed = $builder->build_object(
863
        {
864
            class => 'Koha::ArticleRequests',
865
            value => {
866
                status         => 'COMPLETED',
867
                borrowernumber => $patron->id
868
            }
869
        }
870
    );
871
872
    ok( !$patron->can_request_article, 'Patron has 3 current requests and a completed one the same day: denied' );
873
874
    $completed->updated_on(
875
        dt_from_string->add( days => -1 )->set(
876
            hour   => 23,
877
            minute => 59,
878
            second => 59,
879
        )
880
    )->store;
881
882
    ok( $patron->can_request_article, 'Patron has 3 current requests and a completed one the day before: allowed' );
883
884
    $schema->storage->txn_rollback;
885
};

Return to bug 27945