Bug 22006: Handle undefined itemnumber for Koha::Account::Line->item
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 14 Dec 2018 19:15:24 +0000 (16:15 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 18 Jan 2019 20:32:54 +0000 (20:32 +0000)
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>
Koha/Account/Line.pm

index 529b625..df5d98b 100644 (file)
@@ -50,6 +50,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 );
 }