From 64d321c68b2dde3b4e83fdca36c8ccf7acec8aba Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Thu, 5 Jun 2014 20:49:41 -0400 Subject: [PATCH] LP1198475: Add a new, optional, Lost and Paid copy status. 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 Signed-off-by: Kathy Lussier Signed-off-by: Rogan Hamby --- Open-ILS/src/extras/ils_events.xml | 3 ++ .../perlmods/lib/OpenILS/Application/Actor.pm | 2 +- .../lib/OpenILS/Application/Circ/Circulate.pm | 5 ++- .../lib/OpenILS/Application/Circ/Money.pm | 39 ++++++++++++++++++- .../lib/OpenILS/Application/Circ/Transit.pm | 3 +- Open-ILS/src/perlmods/lib/OpenILS/Const.pm | 1 + Open-ILS/src/perlmods/lib/OpenILS/SIP/Item.pm | 2 +- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 12 ++++++ .../Pg/t/lp1198475-lost-and-paid-status.pg | 36 +++++++++++++++++ .../XXXX.data.lost-and-paid-status.sql | 17 ++++++++ Open-ILS/xul/staff_client/server/circ/util.js | 2 + 11 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/t/lp1198475-lost-and-paid-status.pg create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.data.lost-and-paid-status.sql diff --git a/Open-ILS/src/extras/ils_events.xml b/Open-ILS/src/extras/ils_events.xml index 21d59a737f..80892ad5cf 100644 --- a/Open-ILS/src/extras/ils_events.xml +++ b/Open-ILS/src/extras/ils_events.xml @@ -918,6 +918,9 @@ Copy is marked as long-overdue + + Copy is marked as lost and paid + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index 9c9efc490d..7580733de8 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -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'; } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm index df5f2d4446..896102d3af 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm @@ -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 ); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm index 0c1493a351..040187630f 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm @@ -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 + ) + } + } + } } } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Transit.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Transit.pm index e4e021be3c..bd687c421d 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Transit.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Transit.pm @@ -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); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Const.pm b/Open-ILS/src/perlmods/lib/OpenILS/Const.pm index 4f9e5c2f30..cd82e83c5c 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Const.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Const.pm @@ -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; # --------------------------------------------------------------------- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/SIP/Item.pm b/Open-ILS/src/perlmods/lib/OpenILS/SIP/Item.pm index a2523e11a9..eb40e97ea7 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/SIP/Item.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/SIP/Item.pm @@ -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'; diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 7801cd51a7..eb9ef567fa 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -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 index 0000000000..9c5e664840 --- /dev/null +++ b/Open-ILS/src/sql/Pg/t/lp1198475-lost-and-paid-status.pg @@ -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 index 0000000000..9454de5e46 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.lost-and-paid-status.sql @@ -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'); + diff --git a/Open-ILS/xul/staff_client/server/circ/util.js b/Open-ILS/xul/staff_client/server/circ/util.js index 67472c45d1..058eb921dc 100644 --- a/Open-ILS/xul/staff_client/server/circ/util.js +++ b/Open-ILS/xul/staff_client/server/circ/util.js @@ -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 */ -- 2.43.2