Bug 29495: (follow-up) Use 'item' relationship
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 18 Nov 2021 15:47:02 +0000 (15:47 +0000)
committerFridolin Somers <fridolin.somers@biblibre.com>
Tue, 18 Jan 2022 00:55:55 +0000 (14:55 -1000)
This patch adds the missing 'item' relationship in
Checkouts::ReturnClaim and then uses it from the resolve method.

This improve the reliability of the resolution code so it works when the
item has already been checked in (without having to check
Old::Checkouts).

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Koha/Checkouts/ReturnClaim.pm
Koha/Schema/Result/ReturnClaim.pm

index ebbfd41..7dc5a26 100644 (file)
@@ -101,6 +101,20 @@ sub patron {
     return Koha::Patron->_new_from_dbic( $borrower ) if $borrower;
 }
 
+=head3 item
+
+  my $item = $claim->item;
+
+Return the return claim item
+
+=cut
+
+sub item {
+    my ( $self ) = @_;
+    my $item_rs = $self->_result->item;
+    return Koha::Item->_new_from_dbic( $item_rs );
+}
+
 =head3 resolve
 
     $claim->resolve(
@@ -137,7 +151,7 @@ sub resolve {
             )->store;
 
             if ( defined $params->{new_lost_status} ) {
-                $self->checkout->item->itemlost( $params->{new_lost_status} )->store;
+                $self->item->itemlost( $params->{new_lost_status} )->store;
             }
         }
     );
index 4e2c56c..9e67c7f 100644 (file)
@@ -316,6 +316,21 @@ __PACKAGE__->belongs_to(
     },
 );
 
+=head2 item
+
+Type: belongs_to
+
+Related object: L<Koha::Schema::Result::Item>
+
+=cut
+
+__PACKAGE__->belongs_to(
+  "item",
+  "Koha::Schema::Result::Item",
+  { itemnumber => "itemnumber" },
+  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
+);
+
 sub koha_objects_class {
     'Koha::Checkouts::ReturnClaims';
 }