  )] );
  Exporter::export_ok_tags('all');
 
-@@ -261,6 +262,58 @@ sub NLSync {
-         $sync->update( { 'syncstatus' => 'synced' } );
-         # Update the 'synclast' attribute with the "server time" ("server_tid") returned by the method
-         $sync->update( { 'lastsync' => $response->{'server_tid'} } );
+@@ -257,10 +258,55 @@ sub NLSync {
+             # Turn off any further syncing
+             $sync->update( { 'sync' => 0 } );
+         }
+-        # Update the syncstatus to 'synced'
+-        $sync->update( { 'syncstatus' => 'synced' } );
+-        # Update the 'synclast' attribute with the "server time" ("server_tid") returned by the method
+-        $sync->update( { 'lastsync' => $response->{'server_tid'} } );
++        $sync->update( { 'syncstatus' => 'synced', 'lastsync' => $response->{'server_tid'} } );
 +    } else {
 +        # Handle error special cases
 +        my $cause = $response->result->{'melding'};

+
+            $cause = $response->result->{'melding'};
+            if ( $response->{'status'} && $response->{'status'} == 1 || ($cause && $cause =~ /Oppdaterte felt/)) {
+                # Update the syncstatus to 'synced'
+                $sync->update( { 'syncstatus' => 'synced' } );
+                # Update the 'synclast' attribute with the "server time" ("server_tid") returned by the method
+                $sync->update( { 'lastsync' => $response->{'server_tid'} } );
+            }
+        }
+
     }
     return $response;

@@ -564,6 +617,23 @@ sub _format_soap_error {

 }


 =head2 _soap_to_koha_patron

 Convert a SOAP object of type "Laaner" into a hash that can be sent to AddMember or ModMember.
@@ -635,13 +698,13 @@ sub _koha_patron_to_soap {
             SOAP::Data->name( 'fnr_hash'    => $patron_attributes->{ 'fnr' } )->type( 'string' )->type( 'string' ),
             SOAP::Data->name( 'navn'        => $patron->surname . ', ' . $patron->firstname    )->type( 'string' ),
             SOAP::Data->name( 'sist_endret' => $sync->lastsync      )->type( 'string' ),
