Bug 32942: (QA follow-up) Moving Suggestion->STATUS check to Suggestion::store
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 40ca7aa06c
)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
parent
84863736a4
commit
8ea062497a
3 changed files with 60 additions and 4 deletions
49
Koha/Exceptions/Suggestion.pm
Normal file
49
Koha/Exceptions/Suggestion.pm
Normal file
|
@ -0,0 +1,49 @@
|
|||
package Koha::Exceptions::Suggestion;
|
||||
|
||||
# This file is part of Koha.
|
||||
#
|
||||
# Koha is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Koha is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||
|
||||
use Modern::Perl;
|
||||
|
||||
use Koha::Exception;
|
||||
|
||||
use Exception::Class (
|
||||
'Koha::Exceptions::Suggestion' => {
|
||||
isa => 'Koha::Exception',
|
||||
},
|
||||
'Koha::Exceptions::Suggestion::StatusForbidden' => {
|
||||
isa => 'Koha::Exceptions::Suggestion',
|
||||
description => 'This status is forbidden, check authorised values "SUGGEST"',
|
||||
fields => ['STATUS']
|
||||
}
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Koha::Exceptions::Suggestion - Base class for Suggestion exceptions
|
||||
|
||||
=head1 Exceptions
|
||||
|
||||
=head2 Koha::Exceptions::Suggestion
|
||||
|
||||
Generic Suggestion exception
|
||||
|
||||
=head2 Koha::Exceptions::Suggestion::StatusIsUnknown
|
||||
|
||||
Exception to be used when a purchase suggestion tries to be saved and the status doesn't belong to the list of authorised_values.
|
||||
|
||||
=cut
|
||||
|
||||
1;
|
|
@ -93,10 +93,6 @@ sub add {
|
|||
|
||||
my $body = $c->req->json;
|
||||
|
||||
# FIXME: This should be handled in Koha::Suggestion->store
|
||||
$body->{'status'} = 'ASKED'
|
||||
unless defined $body->{'status'};
|
||||
|
||||
my $overrides = $c->stash('koha.overrides');
|
||||
|
||||
unless ( $overrides->{any} ) {
|
||||
|
|
|
@ -25,6 +25,8 @@ use C4::Letters;
|
|||
use Koha::Database;
|
||||
use Koha::DateUtils qw( dt_from_string );
|
||||
use Koha::Patrons;
|
||||
use Koha::AuthorisedValues;
|
||||
use Koha::Exceptions::Suggestion;
|
||||
|
||||
use base qw(Koha::Object);
|
||||
|
||||
|
@ -49,6 +51,15 @@ sub store {
|
|||
my ($self) = @_;
|
||||
|
||||
$self->STATUS("ASKED") unless $self->STATUS;
|
||||
my @status_constants = qw(ASKED CHECKED ACCEPTED REJECTED);
|
||||
Koha::Exceptions::Suggestion::StatusForbidden->throw( STATUS => $self->STATUS )
|
||||
unless ( grep { $self->STATUS eq $_ } @status_constants )
|
||||
|| Koha::AuthorisedValues->search(
|
||||
{
|
||||
category => 'SUGGEST_STATUS',
|
||||
authorised_value => $self->STATUS
|
||||
}
|
||||
)->count;
|
||||
|
||||
$self->branchcode(undef) if defined $self->branchcode && $self->branchcode eq '';
|
||||
unless ( $self->suggesteddate() ) {
|
||||
|
|
Loading…
Reference in a new issue