LP1198475: Add a new, optional, Lost and Paid copy status.
authorJason Stephenson <jason@sigio.com>
Fri, 6 Jun 2014 00:49:41 +0000 (20:49 -0400)
committerJason Stephenson <jstephenson@mvlc.org>
Mon, 14 Jul 2014 12:30:43 +0000 (08:30 -0400)
Add the Lost and Paid status to config.copy_status.

Add org_unit_settig to control if the copy status is used.

Add checks to O::A::Circ::Money::make_payments to check for LOST
status and org_unit setting and change the copy status to
Lost and Paid as appropriate.

Also add checks for Lost and Paid copy status wherever LOST copy
status is used.

Add the COPY_STATUS_LOST_AND_PAID event.

Add the event to ils_events.xml with id 7026.

Check for the event in circ/util.js in the staff client.

Add pgTAP tests for the existence of the Lost and Paid copy status
and the new org_unit setting to control if it isused.

Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Signed-off-by: Rogan Hamby <rogan.hamby@gmail.com>
Open-ILS/src/extras/ils_events.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Transit.pm
Open-ILS/src/perlmods/lib/OpenILS/Const.pm
Open-ILS/src/perlmods/lib/OpenILS/SIP/Item.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/t/lp1198475-lost-and-paid-status.pg [new file with mode: 0644]
Open-ILS/src/sql/Pg/upgrade/XXXX.data.lost-and-paid-status.sql [new file with mode: 0644]
Open-ILS/xul/staff_client/server/circ/util.js

index 21d59a7..80892ad 100644 (file)
        <event code='7025' textcode='COPY_STATUS_LONG_OVERDUE'>
                <desc xml:lang="en-US">Copy is marked as long-overdue</desc>
        </event>
+       <event code='7026' textcode='COPY_STATUS_LOST_AND_PAID'>
+               <desc xml:lang="en-US">Copy is marked as lost and paid</desc>
+       </event>
 
 
        <!-- ================================================================ -->
index 9c9efc4..7580733 100644 (file)
@@ -2106,7 +2106,7 @@ sub checked_in_with_fines {
 
     my( @lost, @cr, @lo );
     for my $c (@$open) {
-        push( @lost, $c->id ) if $c->stop_fines eq 'LOST';
+        push( @lost, $c->id ) if ($c->stop_fines eq 'LOST');
         push( @cr, $c->id ) if $c->stop_fines eq 'CLAIMSRETURNED';
         push( @lo, $c->id ) if $c->stop_fines eq 'LONGOVERDUE';
     }
index df5f2d4..896102d 100644 (file)
@@ -3420,7 +3420,7 @@ sub checkin_handle_circ {
         $self->copy->circ_lib->id : $self->copy->circ_lib;
     my $stat = $U->copy_status($self->copy->status)->id;
 
-    if ($stat == OILS_COPY_STATUS_LOST) {
+    if ($stat == OILS_COPY_STATUS_LOST || $stat == OILS_COPY_STATUS_LOST_AND_PAID) {
         # we will now handle lost fines, but the copy will retain its 'lost'
         # status if it needs to transit home unless lost_immediately_available
         # is true
@@ -3668,6 +3668,9 @@ sub check_checkin_copy_status {
    return OpenILS::Event->new('COPY_STATUS_LOST', payload => $copy )
       if( $status == OILS_COPY_STATUS_LOST );
 
+    return OpenILS::Event->new('COPY_STATUS_LOST_AND_PAID', payload => $copy)
+        if ($status == OILS_COPY_STATUS_LOST_AND_PAID);
+
    return OpenILS::Event->new('COPY_STATUS_LONG_OVERDUE', payload => $copy )
       if( $status == OILS_COPY_STATUS_LONG_OVERDUE );
 
index 0c1493a..0401876 100644 (file)
@@ -29,6 +29,7 @@ use OpenILS::Utils::CStoreEditor qw/:funcs/;
 use OpenILS::Utils::Penalty;
 use Business::Stripe;
 $Data::Dumper::Indent = 0;
+use OpenILS::Const qw/:const/;
 
 sub get_processor_settings {
     my $e = shift;
@@ -466,10 +467,19 @@ sub make_payments {
             # credit
             $cred = -$cred;
             $credit += $cred;
-            my $circ = $e->retrieve_action_circulation($transid);
+            my $circ = $e->retrieve_action_circulation(
+                [
+                    $transid,
+                    {
+                        flesh => 1,
+                        flesh_fields => {circ => ['target_copy','billings']}
+                    }
+                ]
+            ); # Flesh the copy, so we can monkey with the status if
+               # necessary.
 
             # Whether or not we close the transaction. We definitely
-            # close is no circulation transaction is present,
+            # close if no circulation transaction is present,
             # otherwise we check if the circulation is in a state that
             # allows itself to be closed.
             if (!$circ || OpenILS::Application::Circ::CircCommon->can_close_circ($e, $circ)) {
@@ -481,6 +491,31 @@ sub make_payments {
                         $payment, $cc_payload
                     )
                 }
+
+                # If we have a circ, we need to check if the copy
+                # status is lost or long overdue.  If it is then we
+                # check org_unit_settings for the copy owning library
+                # and adjust and possibly adjust copy status to lost
+                # and paid.
+                if ($circ) {
+                    # We need the copy to check settings and to possibly
+                    # change its status.
+                    my $copy = $circ->target_copy();
+                    # Library where we'll check settings.
+                    my $check_lib = $copy->circ_lib();
+
+                    # check the copy status
+                    if (($copy->status() == OILS_COPY_STATUS_LOST || $copy->status() == OILS_COPY_STATUS_LONG_OVERDUE)
+                            && $U->is_true($U->ou_ancestor_setting_value($check_lib, 'circ.use_lost_paid_copy_status', $e))) {
+                        $copy->status(OILS_COPY_STATUS_LOST_AND_PAID);
+                        if (!$e->update_asset_copy($copy)) {
+                            return _recording_failure(
+                                $e, "update_asset_copy_failed()",
+                                $payment, $cc_payload
+                            )
+                        }
+                    }
+                }
             }
         }
 
index e4e021b..bd687c4 100644 (file)
@@ -226,7 +226,8 @@ sub __abort_transit {
     my $evt;
     my $hold;
 
-    if( ($transit->copy_status == OILS_COPY_STATUS_LOST and !$e->allowed('ABORT_TRANSIT_ON_LOST')) or
+    if( (($transit->copy_status == OILS_COPY_STATUS_LOST || $transit->copy_status == OILS_COPY_STATUS_LOST_AND_PAID)
+             and !$e->allowed('ABORT_TRANSIT_ON_LOST')) or
         ($transit->copy_status == OILS_COPY_STATUS_MISSING and !$e->allowed('ABORT_TRANSIT_ON_MISSING')) ) {
         $e->rollback;
         return OpenILS::Event->new('TRANSIT_ABORT_NOT_ALLOWED', copy_status => $transit->copy_status);
index 4f9e5c2..cd82e83 100644 (file)
@@ -43,6 +43,7 @@ econst OILS_COPY_STATUS_DISCARD       => 13;
 econst OILS_COPY_STATUS_DAMAGED       => 14;
 econst OILS_COPY_STATUS_ON_RESV_SHELF => 15;
 econst OILS_COPY_STATUS_LONG_OVERDUE  => 16;
+econst OILS_COPY_STATUS_LOST_AND_PAID => 17;
 
 
 # ---------------------------------------------------------------------
index a2523e1..eb40e97 100644 (file)
@@ -356,7 +356,7 @@ sub sip_circulation_status {
     return '08' if $stat == OILS_COPY_STATUS_ON_HOLDS_SHELF;
     return '09' if $stat == OILS_COPY_STATUS_RESHELVING;
     return '10' if $stat == OILS_COPY_STATUS_IN_TRANSIT;
-    return '12' if $stat == OILS_COPY_STATUS_LOST;
+    return '12' if ($stat == OILS_COPY_STATUS_LOST || $stat == OILS_COPY_STATUS_LOST_AND_PAID);
     return '13' if $stat == OILS_COPY_STATUS_MISSING;
         
     return '01';
index 7801cd5..eb9ef56 100644 (file)
@@ -324,6 +324,9 @@ INSERT INTO config.copy_status (id,name,copy_active) VALUES (15,oils_i18n_gettex
 INSERT INTO config.copy_status
     (id, name, holdable, opac_visible, copy_active, restrict_copy_delete)
     VALUES (16, oils_i18n_gettext(16, 'Long Overdue', 'ccs', 'name'), 'f', 'f', 'f', 't');
+INSERT INTO config.copy_status
+(id, name, holdable, opac_visible, copy_active, restrict_copy_delete)
+VALUES (17, 'Lost and Paid', FALSE, FALSE, FALSE, TRUE);
 
 
 SELECT SETVAL('config.copy_status_id_seq'::TEXT, 100);
@@ -5004,6 +5007,15 @@ INSERT into config.org_unit_setting_type
         'coust',
         'description'),
     'integer', null)
+,('circ.use_lost_paid_copy_status',
+ 'circ',
+ oils_i18n_gettext('circ.use_lost_paid_copy_status',
+     'Use Lost and Paid copy status',
+     'coust', 'label'),
+ oils_i18n_gettext('circ.use_lost_paid_copy_status',
+     'Use Lost and Paid copy status when lost or long overdue billing is paid',
+     'coust', 'description'),
+ 'bool')
 ;
 
 UPDATE config.org_unit_setting_type
diff --git a/Open-ILS/src/sql/Pg/t/lp1198475-lost-and-paid-status.pg b/Open-ILS/src/sql/Pg/t/lp1198475-lost-and-paid-status.pg
new file mode 100644 (file)
index 0000000..9c5e664
--- /dev/null
@@ -0,0 +1,36 @@
+\set ECHO
+\set QUIET 1
+-- Turn off echo and keep things quiet.
+
+-- Format the output for nice TAP.
+\pset format unaligned
+\pset tuples_only true
+\pset pager
+
+-- Revert all changes on failure.
+\set ON_ERROR_ROLLBACK 1
+\set ON_ERROR_STOP true
+\set QUIET 1
+
+-- Load the TAP functions.
+BEGIN;
+
+-- Plan the tests.
+SELECT plan(2);
+
+-- Run the tests.
+-- Check for Lost and Paid copy status.
+SELECT isnt_empty(
+    'SELECT * FROM config.copy_status WHERE id = 17',
+    'Lost and Paid copy status exists'
+);
+
+--Check for the org_unit setting.
+SELECT isnt_empty(
+    'SELECT * FROM config.org_unit_setting_type WHERE name = $$circ.use_lost_paid_copy_status$$',
+    'circ.use_lost_paid_copy_status exists'
+);
+
+-- Finish the tests and clean up.
+SELECT * FROM finish();
+ROLLBACK;
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.lost-and-paid-status.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.lost-and-paid-status.sql
new file mode 100644 (file)
index 0000000..9454de5
--- /dev/null
@@ -0,0 +1,17 @@
+INSERT INTO config.copy_status
+(id, name, holdable, opac_visible, copy_active, restrict_copy_delete)
+VALUES (17, 'Lost and Paid', FALSE, FALSE, FALSE, TRUE);
+
+INSERT INTO config.org_unit_setting_type
+(name, grp, label, description, datatype)
+VALUES
+('circ.use_lost_paid_copy_status',
+ 'circ',
+ oils_i18n_gettext('circ.use_lost_paid_copy_status',
+     'Use Lost and Paid copy status',
+     'coust', 'label'),
+ oils_i18n_gettext('circ.use_lost_paid_copy_status',
+     'Use Lost and Paid copy status when lost or long overdue billing is paid',
+     'coust', 'description'),
+ 'bool');
+
index 67472c4..058eb92 100644 (file)
@@ -2756,6 +2756,7 @@ circ.util.checkin_via_barcode = function(session,params,backdate,auto_print,asyn
                     7010 /* COPY_ALERT_MESSAGE */,
                     7011 /* COPY_STATUS_LOST */,
                     7025 /* COPY_STATUS_LONG_OVERDUE */, 
+                    7026 /* COPY_STATUS_LOST_AND_PAID */,
                     7012 /* COPY_STATUS_MISSING */,
                     7013 /* PATRON_EXCEEDS_FINES */
                 ] : [],
@@ -2770,6 +2771,7 @@ circ.util.checkin_via_barcode = function(session,params,backdate,auto_print,asyn
                     7010 /* COPY_ALERT_MESSAGE */,
                     7011 /* COPY_STATUS_LOST */,
                     7025 /* COPY_STATUS_LONG_OVERDUE */, 
+                    7026 /* COPY_STATUS_LOST_AND_PAID */,
                     7012 /* COPY_STATUS_MISSING */,
                     7013 /* PATRON_EXCEEDS_FINES */,
                     11103 /* TRANSIT_CHECKIN_INTERVAL_BLOCK */