Bug 32336: (QA follow-up) Use $metadata->schema
[srvgit] / Koha / Hold.pm
index 73eec43..a5a9d03 100644 (file)
@@ -85,14 +85,14 @@ sub age {
 
 =head3 suspend_hold
 
-my $hold = $hold->suspend_hold( $suspend_until_dt );
+my $hold = $hold->suspend_hold( $suspend_until );
 
 =cut
 
 sub suspend_hold {
-    my ( $self, $dt ) = @_;
+    my ( $self, $date ) = @_;
 
-    my $date = $dt ? $dt->clone()->truncate( to => 'day' )->datetime : undef;
+    $date &&= dt_from_string($date)->truncate( to => 'day' )->datetime;
 
     if ( $self->is_found ) {    # We can't suspend found holds
         if ( $self->is_waiting ) {
@@ -200,6 +200,14 @@ sub set_transfer {
     $self->found('T');
     $self->store();
 
+    Koha::Plugins->call(
+        'after_hold_action',
+        {
+            action  => 'transfer',
+            payload => { hold => $self->get_from_storage }
+        }
+    );
+
     return $self;
 }
 
@@ -257,6 +265,14 @@ sub set_waiting {
 
     $self->set($values)->store();
 
+    Koha::Plugins->call(
+        'after_hold_action',
+        {
+            action  => 'waiting',
+            payload => { hold => $self->get_from_storage }
+        }
+    );
+
     return $self;
 }
 
@@ -345,6 +361,14 @@ sub set_processing {
     $self->found('P');
     $self->store();
 
+    Koha::Plugins->call(
+        'after_hold_action',
+        {
+            action  => 'processing',
+            payload => { hold => $self->get_from_storage }
+        }
+    );
+
     return $self;
 }
 
@@ -525,6 +549,20 @@ sub item {
     return $self->{_item};
 }
 
+=head3 item_group
+
+Returns the related Koha::Biblio::ItemGroup object for this Hold
+
+=cut
+
+sub item_group {
+    my ($self) = @_;
+
+    my $item_group_rs = $self->_result->item_group;
+    return unless $item_group_rs;
+    return Koha::Biblio::ItemGroup->_new_from_dbic($item_group_rs);
+}
+
 =head3 branch
 
 Returns the related Koha::Library object for this Hold
@@ -906,6 +944,26 @@ sub to_api_mapping {
     };
 }
 
+=head3 can_update_pickup_location_opac
+
+    my $can_update_pickup_location_opac = $hold->can_update_pickup_location_opac;
+
+Returns if a hold can change pickup location from opac
+
+=cut
+
+sub can_update_pickup_location_opac {
+    my ($self) = @_;
+
+    my @statuses = split /,/, C4::Context->preference("OPACAllowUserToChangeBranch");
+    foreach my $status ( @statuses ){
+        return 1 if ($status eq 'pending' && !$self->is_found && !$self->is_suspended );
+        return 1 if ($status eq 'intransit' && $self->is_in_transit);
+        return 1 if ($status eq 'suspended' && $self->is_suspended);
+    }
+    return 0;
+}
+
 =head2 Internal methods
 
 =head3 _type