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

(-)a/Koha/Exceptions/Suggestion.pm (+49 lines)
Line 0 Link Here
1
package Koha::Exceptions::Suggestion;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Koha::Exception;
21
22
use Exception::Class (
23
    'Koha::Exceptions::Suggestion' => {
24
        isa => 'Koha::Exception',
25
    },
26
    'Koha::Exceptions::Suggestion::StatusForbidden' => {
27
        isa         => 'Koha::Exceptions::Suggestion',
28
        description => 'This status is forbidden, check authorised values "SUGGEST"',
29
	fields      => ['STATUS']
30
    }
31
);
32
33
=head1 NAME
34
35
Koha::Exceptions::Suggestion - Base class for Suggestion exceptions
36
37
=head1 Exceptions
38
39
=head2 Koha::Exceptions::Suggestion
40
41
Generic Suggestion exception
42
43
=head2 Koha::Exceptions::Suggestion::StatusIsUnknown
44
45
Exception to be used when a purchase suggestion tries to be saved and the status doesn't belong to the list of authorised_values.
46
47
=cut
48
49
1;
(-)a/Koha/REST/V1/Suggestions.pm (-4 lines)
Lines 93-102 sub add { Link Here
93
93
94
    my $body = $c->req->json;
94
    my $body = $c->req->json;
95
95
96
    # FIXME: This should be handled in Koha::Suggestion->store
97
    $body->{'status'} = 'ASKED'
98
        unless defined $body->{'status'};
99
100
    my $overrides = $c->stash('koha.overrides');
96
    my $overrides = $c->stash('koha.overrides');
101
97
102
    unless ( $overrides->{any} ) {
98
    unless ( $overrides->{any} ) {
(-)a/Koha/Suggestion.pm (-1 / +7 lines)
Lines 25-30 use C4::Letters; Link Here
25
use Koha::Database;
25
use Koha::Database;
26
use Koha::DateUtils qw( dt_from_string );
26
use Koha::DateUtils qw( dt_from_string );
27
use Koha::Patrons;
27
use Koha::Patrons;
28
use Koha::AuthorisedValues;
29
use Koha::Exceptions::Suggestion;
28
30
29
use base qw(Koha::Object);
31
use base qw(Koha::Object);
30
32
Lines 49-54 sub store { Link Here
49
    my ($self) = @_;
51
    my ($self) = @_;
50
52
51
    $self->STATUS("ASKED") unless $self->STATUS;
53
    $self->STATUS("ASKED") unless $self->STATUS;
54
    my @status_constants = qw(ASKED CHECKED ACCEPTED REJECTED);
55
    Koha::Exceptions::Suggestion::StatusForbidden->throw( STATUS => $self->STATUS )
56
	unless (grep {$self->STATUS eq $_} @status_constants)
57
	|| Koha::AuthorisedValues->search({category => 'SUGGEST_STATUS',
58
					   authorised_value => $self->STATUS})->count;
52
59
53
    $self->branchcode(undef) if defined $self->branchcode && $self->branchcode eq '';
60
    $self->branchcode(undef) if defined $self->branchcode && $self->branchcode eq '';
54
    unless ( $self->suggesteddate() ) {
61
    unless ( $self->suggesteddate() ) {
55
- 

Return to bug 32942