Bug 15010: Import patron tool creates 'duplicate' restrictions ( debarments )
authorKyle M Hall <kyle@bywatersolutions.com>
Wed, 14 Oct 2015 12:48:30 +0000 (08:48 -0400)
committerLiz Rea <wizzyrea@gmail.com>
Wed, 9 Dec 2015 21:09:16 +0000 (10:09 +1300)
If a patron has restrictions and a CSV file of patrons to be overwritten
is uploaded but has no debarred / debarredcomment columns, the a new
restriction will be added that combines all the existing restrictions (
i.e. a new debarment based on the existing borrowers.debarred
and borrowers.debarredcomment fields ).

Test Plan:
1) Create a patron with one or more restrictions
2) Import a CSV file that updates that patron, but with no debarred columns
3) Note a new restrictions is created
4) Delete the new restriction
5) Apply this patch
6) Re-import the CSV file again
7) Note that no new restriction is created
8) Add debarred and debarredcomment columns to the CSV file with a test
   date and description
9) Re-import the CSV file again
10) Note the new restriction is added to the patron

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Daniel Grobani <dgrobani@samuelmerritt.edu>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit fd123903651435c56ca14d88897e9ce4d7a38bb5)
Signed-off-by: Frédéric Demians <f.demians@tamil.fr>
(cherry picked from commit 37e7a6fe7801cacf6f89fd96b34d6b3939c9d409)
Signed-off-by: Liz Rea <wizzyrea@gmail.com>

tools/import_borrowers.pl

index 47cda2a..25cc275 100755 (executable)
@@ -278,7 +278,9 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
                 $template->param('lastinvalid'=>$borrower{'surname'}.' / '.$borrowernumber);
                 next LINE;
             }
-            if ( $borrower{debarred} ) {
+
+            # Don't add a new restriction if the existing 'combined' restriction matches this one
+            if ( $borrower{debarred} && ( ( $borrower{debarred} ne $member->{debarred} ) || ( $borrower{debarredcomment} ne $member->{debarredcomment} ) ) ) {
                 # Check to see if this debarment already exists
                 my $debarrments = GetDebarments(
                     {
@@ -298,6 +300,7 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
                     );
                 }
             }
+
             if ($extended) {
                 if ($ext_preserve) {
                     my $old_attributes = GetBorrowerAttributes($borrowernumber);