From f233ad8dc5fdc1f2b783948072e59da9d68ee41b Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 3 Nov 2012 12:04:34 -0400 Subject: [PATCH] Address Launchpad Bug 793550. Check for stop fines reason of CHECKIN or RENEW before closing a circulation transaction when the balance reaches zero. Also, if the stop fines reason is LOST, then check a new ou setting, circ.lost.xact_open_on_zero, to determine if the transaction is closed or kept open. The setting is checked for the circulation copy's circ_lib. Add CircCommon->can_close_circ. Following up on Dan Wells' comments on Launchpad Bug 793550, I have moved the logic to check if the circ transaction can be closed to its own utility function in OpenILS::Application::Circ::CircCommon. This potentially consolidates the logic in one place in case we need to use it elsewhere. Instead of checking for stop fines reasons of CHECKIN and RENEW and checking for checkin time on the circ, we just check for checkin time. Both CHECKIN and RENEW should set the checkin time. Also, use the constant for stop fines reason of LOST, rather than the literal string "LOST". Signed-off-by: Jason Stephenson Signed-off-by: Dan Wells --- .../lib/OpenILS/Application/Circ/CircCommon.pm | 30 ++++++++++++++++++++++ .../perlmods/lib/OpenILS/Application/Circ/Money.pm | 8 +++--- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 19 ++++++++++++++ .../XXXX.data.coust_lost_xact_finish_on_zero.sql | 25 ++++++++++++++++++ 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.data.coust_lost_xact_finish_on_zero.sql diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm index 613447fd59..79df59d36c 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm @@ -209,4 +209,34 @@ sub extend_grace_period { return $grace_period; } +# check if a circulation transaction can be closed +# takes a CStoreEditor and a circ transaction. +# Returns 1 if the circ should be closed, 0 if not. +sub can_close_circ { + my ($class, $e, $circ) = @_; + my $can_close = 0; + + my $reason = $circ->stop_fines; + + # We definitely want to close if this circulation was + # checked in or renewed. + if ($circ->checkin_time) { + $can_close = 1; + } elsif ($reason eq OILS_STOP_FINES_LOST) { + # Check the copy circ_lib to see if they close + # transactions when lost are paid. + my $copy = $e->retrieve_asset_copy($circ->target_copy); + if ($copy) { + $can_close = !$U->is_true( + $U->ou_ancestor_setting_value( + $copy->circ_lib, + 'circ.lost.xact_open_on_zero', + $e + ) + ); + } + } + return $can_close; +} + 1; 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 f8c276d28a..eb1ac40587 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm @@ -333,9 +333,11 @@ sub make_payments { $credit += $cred; my $circ = $e->retrieve_action_circulation($transid); - if(!$circ || $circ->stop_fines) { - # If this is a circulation, we can't close the transaction - # unless stop_fines is set. + # Whether or not we close the transaction. We definitely + # close is 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)) { $trans = $e->retrieve_money_billable_transaction($transid); $trans->xact_finish("now"); if (!$e->update_money_billable_transaction($trans)) { 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 5668078c5d..394e7bcc6c 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -11840,3 +11840,22 @@ INSERT into config.org_unit_setting_type 'bool' ); +INSERT INTO config.org_unit_setting_type + (name, grp, label, description, datatype) + VALUES ( + 'circ.lost.xact_open_on_zero', + 'finance', + oils_i18n_gettext( + 'circ.lost.xact_open_on_zero', + 'Leave transaction open when lost balance equals zero', + 'coust', + 'label' + ), + oils_i18n_gettext( + 'circ.lost.xact_open_on_zero', + 'Leave transaction open when lost balance equals zero. This leaves the lost copy on the patron record when it is paid', + 'coust', + 'description' + ), + 'bool' + ); diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.coust_lost_xact_finish_on_zero.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.coust_lost_xact_finish_on_zero.sql new file mode 100644 index 0000000000..5397ef151e --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.coust_lost_xact_finish_on_zero.sql @@ -0,0 +1,25 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +INSERT INTO config.org_unit_setting_type + (name, grp, label, description, datatype) + VALUES ( + 'circ.lost.xact_open_on_zero', + 'finance', + oils_i18n_gettext( + 'circ.lost.xact_open_on_zero', + 'Leave transaction open when lost balance equals zero', + 'coust', + 'label' + ), + oils_i18n_gettext( + 'circ.lost.xact_open_on_zero', + 'Leave transaction open when lost balance equals zero. This leaves the lost copy on the patron record when it is paid', + 'coust', + 'description' + ), + 'bool' + ); + +COMMIT; -- 2.11.0