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

(-)a/Koha/Patron.pm (-8 / +8 lines)
Lines 960-968 sub move_to_deleted { Link Here
960
960
961
=head3 can_request_article
961
=head3 can_request_article
962
962
963
my $can_request = $borrower->can_request_article
963
    if ( $patron->can_request_article ) { ... }
964
964
965
Returns true if patron can request articles
965
Returns true if the patron can request articles. As limits apply for the patron
966
on on the same day, those completed the same day are considered as current.
966
967
967
=cut
968
=cut
968
969
Lines 972-983 sub can_request_article { Link Here
972
973
973
    return 1 unless defined $limit;
974
    return 1 unless defined $limit;
974
975
975
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
976
    my $count = Koha::ArticleRequests->search(
976
    my $compdate = dt_from_string->add( days => -1 );
977
        [   { borrowernumber => $self->borrowernumber, status => [ 'REQUESTED', 'PENDING', 'PROCESSING' ] },
977
    my $count = Koha::ArticleRequests->search([
978
            { borrowernumber => $self->borrowernumber, status => 'COMPLETED', updated_on => { '>=' => \'CAST(NOW() AS DATE)' } },
978
        { borrowernumber => $self->borrowernumber, status => ['REQUESTED','PENDING','PROCESSING'] },
979
        ]
979
        { borrowernumber => $self->borrowernumber, status => 'COMPLETED', updated_on => { '>', $dtf->format_date($compdate) }},
980
    )->count;
980
    ])->count;
981
    return $count < $limit ? 1 : 0;
981
    return $count < $limit ? 1 : 0;
982
}
982
}
983
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