Merge branch 'bug_9824' into 3.14-master
[koha.git] / C4 / Items.pm
index 6533a68..2d2c62c 100644 (file)
@@ -1284,8 +1284,8 @@ sub GetItemsInfo {
 
         # get restricted status and description if applicable
         if ( my $code = C4::Koha::GetAuthValCode( 'items.restricted', $data->{frameworkcode} ) ) {
-            $data->{restricted}     = C4::Koha::GetKohaAuthorisedValueLib( $code, $data->{restricted} );
             $data->{restrictedopac} = C4::Koha::GetKohaAuthorisedValueLib( $code, $data->{restricted}, 1 );
+            $data->{restricted}     = C4::Koha::GetKohaAuthorisedValueLib( $code, $data->{restricted} );
         }
 
         # my stack procedures
@@ -2213,10 +2213,9 @@ sub DelItemCheck {
     if ($onloan){
         $error = "book_on_loan" 
     }
-    elsif ( !(C4::Context->userenv->{flags} & 1) and
-            C4::Context->preference("IndependantBranches") and
-           (C4::Context->userenv->{branch} ne
-             $item->{C4::Context->preference("HomeOrHoldingBranch")||'homebranch'}) )
+    elsif ( !( C4::Context->userenv->{flags} & 1 )
+        and C4::Context->preference("IndependantBranches")
+        and ( C4::Context->userenv->{branch} ne $item->{'homebranch'} ) )
     {
         $error = "not_same_branch";
     }
@@ -2254,6 +2253,7 @@ sub _koha_modify_item {
     my $query = "UPDATE items SET ";
     my @bind;
     for my $key ( keys %$item ) {
+        next if ( $key eq 'itemnumber' );
         $query.="$key=?,";
         push @bind, $item->{$key};
     }
@@ -2656,6 +2656,10 @@ sub PrepareItemrecordDisplay {
                     && $defaultvalues
                     && $defaultvalues->{'callnumber'} ) {
                     if( $itemrecord and $defaultvalues and not $itemrecord->field($subfield) ){
+                        # if the item record exists, only use default value if the item has no callnumber
+                        $defaultvalue = $defaultvalues->{callnumber};
+                    } elsif ( !$itemrecord and $defaultvalues ) {
+                        # if the item record *doesn't* exists, always use the default value
                         $defaultvalue = $defaultvalues->{callnumber};
                     }
                 }
@@ -2671,6 +2675,10 @@ sub PrepareItemrecordDisplay {
                     && $defaultvalues->{'location'} ) {
 
                     if ( $itemrecord and $defaultvalues and not $itemrecord->field($subfield) ) {
+                        # if the item record exists, only use default value if the item has no locationr
+                        $defaultvalue = $defaultvalues->{location};
+                    } elsif ( !$itemrecord and $defaultvalues ) {
+                        # if the item record *doesn't* exists, always use the default value
                         $defaultvalue = $defaultvalues->{location};
                     }
                 }
@@ -2701,7 +2709,11 @@ sub PrepareItemrecordDisplay {
                                 $authorised_lib{$branchcode} = $branchname;
                             }
                         }
+
                         $defaultvalue = C4::Context->userenv->{branch};
+                        if ( $defaultvalues and $defaultvalues->{branchcode} ) {
+                            $defaultvalue = $defaultvalues->{branchcode};
+                        }
 
                         #----- itemtypes
                     } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
@@ -2727,6 +2739,8 @@ sub PrepareItemrecordDisplay {
                             $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
                         }
 
+                        $defaultvalue = $default_source;
+
                         #---- "true" authorised value
                     } else {
                         $authorised_values_sth->execute(