Bug 22006: Handle undefined itemnumber for Koha::Account::Line->item

If there is no item linked to an account line, the ->item method should return undef.
Without this patch it explodes with:
Carp::croak('DBIC result _type  isn\'t of the _type Item') called at /home/vagrant/kohaclone/Koha/Object.pm line 102

Exists since the introduction of this method by bug 12001

Reported on bug 19489 comment 18.

Test plan:
  prove t/db_dependent/Koha/Account/Lines.t
must return green

Signed-off-by: Pierre-Marc Thibault <pierre-marc.thibault@inLibro.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 6c8089b40f)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 07cd6560b5)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2018-12-14 16:15:24 -03:00 committed by Lucas Gass
parent 9b29c0ed84
commit abaefea418
1 changed files with 1 additions and 0 deletions

View File

@ -47,6 +47,7 @@ Return the item linked to this account line if exists
sub item {
my ( $self ) = @_;
my $rs = $self->_result->itemnumber;
return unless $rs;
return Koha::Item->_new_from_dbic( $rs );
}