[open-ils-commits] r18504 - branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Circ (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Oct 27 15:13:58 EDT 2010
Author: miker
Date: 2010-10-27 15:13:54 -0400 (Wed, 27 Oct 2010)
New Revision: 18504
Modified:
branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
Log:
Backport of r18494, r18500 and r18501 from trunk: split fine generation
Modified: branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
===================================================================
--- branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm 2010-10-27 19:09:14 UTC (rev 18503)
+++ branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm 2010-10-27 19:13:54 UTC (rev 18504)
@@ -2191,6 +2191,21 @@
OpenILS::Event->new('ASSET_COPY_NOT_FOUND'))
unless $self->copy;
+ # the renew code will have already found our circulation object
+ unless( $self->is_renewal and $self->circ ) {
+ my $circs = $self->editor->search_action_circulation(
+ { target_copy => $self->copy->id, checkin_time => undef });
+ $self->circ($$circs[0]);
+
+ # for now, just warn if there are multiple open circs on a copy
+ $logger->warn("circulator: we have ".scalar(@$circs).
+ " open circs for copy " .$self->copy->id."!!") if @$circs > 1;
+
+ # run the fine generator against this circ, if this circ is there
+ $self->generate_fines_start if (@$circs);
+ }
+
+
if( $self->checkin_check_holds_shelf() ) {
$self->bail_on_events(OpenILS::Event->new('NO_CHANGE'));
$self->hold($U->fetch_open_hold_by_copy($self->copy->id));
@@ -2206,20 +2221,6 @@
$self->push_events($self->check_copy_alert());
$self->push_events($self->check_checkin_copy_status());
- # the renew code will have already found our circulation object
- unless( $self->is_renewal and $self->circ ) {
- my $circs = $self->editor->search_action_circulation(
- { target_copy => $self->copy->id, checkin_time => undef });
- $self->circ($$circs[0]);
-
- # for now, just warn if there are multiple open circs on a copy
- $logger->warn("circulator: we have ".scalar(@$circs).
- " open circs for copy " .$self->copy->id."!!") if @$circs > 1;
- }
-
- # run the fine generator against this circ, if this circ is there
- $self->generate_fines if ($self->circ);
-
# if the circ is marked as 'claims returned', add the event to the list
$self->push_events(OpenILS::Event->new('CIRC_CLAIMS_RETURNED'))
if ($self->circ and $self->circ->stop_fines
@@ -2405,6 +2406,9 @@
unless @{$self->events};
}
+ # gather any updates to the circ after fine generation, if there was a circ
+ $self->generate_fines_finish if ($self->circ);
+
OpenILS::Utils::Penalty->calculate_penalties(
$self->editor, $self->patron->id, $self->circ_lib) if $self->patron;
@@ -2867,21 +2871,37 @@
sub generate_fines {
my $self = shift;
my $reservation = shift;
- my $evt;
- my $obt;
+ $self->generate_fines_start($reservation);
+ $self->generate_fines_finish($reservation);
+
+ return undef;
+}
+
+sub generate_fines_start {
+ my $self = shift;
+ my $reservation = shift;
+
my $id = $reservation ? $self->reservation->id : $self->circ->id;
- my $st = OpenSRF::AppSession->connect('open-ils.storage');
+ $self->{_gen_fines_req} = OpenSRF::AppSession->create('open-ils.storage')
+ ->request(
+ 'open-ils.storage.action.circulation.overdue.generate_fines',
+ undef,
+ $id
+ );
- $st->request(
- 'open-ils.storage.action.circulation.overdue.generate_fines',
- undef,
- $id
- )->wait_complete;
+ return undef;
+}
- $st->disconnect;
+sub generate_fines_finish {
+ my $self = shift;
+ my $reservation = shift;
+ my $id = $reservation ? $self->reservation->id : $self->circ->id;
+
+ $self->{_gen_fines_req}->wait_complete;
+
# refresh the circ in case the fine generator set the stop_fines field
$self->reservation($self->editor->retrieve_booking_reservation($id)) if $reservation;
$self->circ($self->editor->retrieve_action_circulation($id)) if !$reservation;
@@ -3177,26 +3197,15 @@
# Make sure there is an open circ to renew that is not
# marked as LOST, CLAIMSRETURNED, or LONGOVERDUE
my $usrid = $self->patron->id if $self->patron;
- my $circ;
- if ($usrid) {
- # If we have a patron, match them to the circ
- $circ = $self->editor->search_action_circulation(
- {target_copy => $self->copy->id, usr => $usrid, stop_fines => undef})->[0];
- } else {
- $circ = $self->editor->search_action_circulation(
- {target_copy => $self->copy->id, stop_fines => undef})->[0];
- }
+ my $circ = $self->editor->search_action_circulation({
+ target_copy => $self->copy->id,
+ ($usrid ? (usr => $usrid) : ()),
+ '-or' => [
+ {stop_fines => undef},
+ {stop_fines => OILS_STOP_FINES_MAX_FINES}
+ ]
+ })->[0];
- if(!$circ) {
- if ($usrid) {
- $circ = $self->editor->search_action_circulation(
- {target_copy => $self->copy->id, usr => $usrid, stop_fines => OILS_STOP_FINES_MAX_FINES, checkin_time => undef})->[0];
- } else {
- $circ = $self->editor->search_action_circulation(
- {target_copy => $self->copy->id, stop_fines => OILS_STOP_FINES_MAX_FINES, checkin_time => undef})->[0];
- }
- }
-
return $self->bail_on_events($self->editor->event) unless $circ;
# A user is not allowed to renew another user's items without permission
@@ -3214,6 +3223,9 @@
$self->renewal_remaining( $circ->renewal_remaining - 1 );
$self->circ($circ);
+ # Run the fine generator against the old circ
+ $self->generate_fines_start;
+
$self->run_renew_permit;
# Check the item in
More information about the open-ils-commits
mailing list