[open-ils-commits] r11039 - in branches/rel_1_2/Open-ILS/src: extras perlmods/OpenILS perlmods/OpenILS/Application/Circ
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Nov 3 12:57:25 EST 2008
Author: erickson
Date: 2008-11-03 12:57:23 -0500 (Mon, 03 Nov 2008)
New Revision: 11039
Modified:
branches/rel_1_2/Open-ILS/src/extras/ils_events.xml
branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Const.pm
Log:
backport rental/deposit item circ handling
Modified: branches/rel_1_2/Open-ILS/src/extras/ils_events.xml
===================================================================
--- branches/rel_1_2/Open-ILS/src/extras/ils_events.xml 2008-11-03 17:46:46 UTC (rev 11038)
+++ branches/rel_1_2/Open-ILS/src/extras/ils_events.xml 2008-11-03 17:57:23 UTC (rev 11039)
@@ -153,6 +153,15 @@
<event code='1231' textcode='RECORD_NOT_EMPTY'>
<desc xml:lang="en-US">The selected bib record has volumes attached</desc>
</event>
+ <event code='1232' textcode='ITEM_DEPOSIT_REQUIRED'>
+ <desc xml:lang="en-US"></desc>
+ </event>
+ <event code='1233' textcode='ITEM_RENTAL_FEE_REQUIRED'>
+ <desc xml:lang="en-US"></desc>
+ </event>
+ <event code='1234' textcode='ITEM_DEPOSIT_PAID'>
+ <desc xml:lang="en-US"></desc>
+ </event>
Modified: branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
===================================================================
--- branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm 2008-11-03 17:46:46 UTC (rev 11038)
+++ branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm 2008-11-03 17:57:23 UTC (rev 11039)
@@ -158,7 +158,7 @@
$circulator->is_checkin(1) if $api =~ /checkin/;
$circulator->check_penalty_on_renew(1) if
$circulator->is_renewal and $U->ou_ancestor_setting_value(
- $circulator->editor->requestor->ws_ou, 'circ.renew.check_penalty', $circulator->editor);
+ $circulator->circ_lib, 'circ.renew.check_penalty', $circulator->editor);
$circulator->mk_script_runner;
return circ_events($circulator) if $circulator->bail_out;
@@ -357,6 +357,10 @@
phone_renewal
desk_renewal
retarget
+ is_deposit
+ is_rental
+ deposit_billing
+ rental_billing
/;
@@ -391,8 +395,7 @@
my $self = bless( {}, $class );
$self->events([]);
- $self->editor(
- new_editor(xact => 1, authtoken => $auth) );
+ $self->editor(new_editor(xact => 1, authtoken => $auth));
unless( $self->editor->checkauth ) {
$self->bail_on_events($self->editor->event);
@@ -505,8 +508,13 @@
}
}
- $self->is_precat(1) if $self->copy
- and $self->copy->call_number == OILS_PRECAT_CALL_NUMBER;
+ if($self->copy) {
+ $self->is_precat(1) if $self->copy->call_number == OILS_PRECAT_CALL_NUMBER;
+ if($self->copy->deposit_amount and $self->copy->deposit_amount > 0) {
+ $self->is_deposit(1) if $U->is_true($self->copy->deposit);
+ $self->is_rental(1) unless $U->is_true($self->copy->deposit);
+ }
+ }
# We can't renew if there is no copy
return $self->bail_on_events(@evts) if
@@ -552,6 +560,7 @@
$self->run_patron_permit_scripts();
$self->run_copy_permit_scripts()
unless $self->is_precat or $self->is_noncat;
+ $self->check_item_deposit_events();
$self->override_events() unless
$self->is_renewal and not $self->check_penalty_on_renew;
return if $self->bail_out;
@@ -569,7 +578,36 @@
payload => $self->mk_permit_key));
}
+sub check_item_deposit_events {
+ my $self = shift;
+ $self->push_events(OpenILS::Event->new('ITEM_DEPOSIT_REQUIRED'))
+ if $self->is_deposit and not $self->is_deposit_exempt;
+ $self->push_events(OpenILS::Event->new('ITEM_RENTAL_FEE_REQUIRED'))
+ if $self->is_rental and not $self->is_rental_exempt;
+}
+# returns true if the user is not required to pay deposits
+sub is_deposit_exempt {
+ my $self = shift;
+ my $pid = (ref $self->patron->profile) ?
+ $self->patron->profile->id : $self->patron->profile;
+ my $groups = $U->ou_ancestor_setting_value(
+ $self->circ_lib, 'circ.deposit.exempt_groups', $self->editor);
+ return 1 if $groups and grep {$_ == $pid} @$groups;
+ return 0;
+}
+
+# returns true if the user is not required to pay rental fees
+sub is_rental_exempt {
+ my $self = shift;
+ my $pid = (ref $self->patron->profile) ?
+ $self->patron->profile->id : $self->patron->profile;
+ my $groups = $U->ou_ancestor_setting_value(
+ $self->circ_lib, 'circ.rental.exempt_groups', $self->editor);
+ return 1 if $groups and grep {$_ == $pid} @$groups;
+ return 0;
+}
+
sub check_captured_holds {
my $self = shift;
my $copy = $self->copy;
@@ -873,6 +911,9 @@
$self->update_copy;
return if $self->bail_out;
+ $self->apply_deposit_fee();
+ return if $self->bail_out;
+
$self->handle_checkout_holds();
return if $self->bail_out;
@@ -897,11 +938,41 @@
circ => $self->circ,
record => $record,
holds_fulfilled => $self->fulfilled_holds,
+ deposit_bill => $self->deposit_billing,
+ rental_bill => $self->rental_billing
}
)
);
}
+sub apply_deposit_fee {
+ my $self = shift;
+ my $copy = $self->copy;
+ return unless
+ ($self->is_deposit and not $self->is_deposit_exempt) or
+ ($self->is_rental and not $self->is_rental_exempt);
+
+ my $bill = Fieldmapper::money::billing->new;
+ my $amount = $copy->deposit_amount;
+ my $billing_type;
+
+ if($self->is_deposit) {
+ $billing_type = OILS_BILLING_TYPE_DEPOSIT;
+ $self->deposit_billing($bill);
+ } else {
+ $billing_type = OILS_BILLING_TYPE_RENTAL;
+ $self->rental_billing($bill);
+ }
+
+ $bill->xact($self->circ->id);
+ $bill->amount($amount);
+ $bill->note(OILS_BILLING_NOTE_SYSTEM);
+ $bill->billing_type($billing_type);
+ $self->editor->create_money_billing($bill) or $self->bail_on_events($self->editor->event);
+
+ $logger->info("circulator: charged $amount on checkout with billing type $billing_type");
+}
+
sub update_copy {
my $self = shift;
my $copy = $self->copy;
@@ -1320,6 +1391,8 @@
if ($self->circ and $self->circ->stop_fines
and $self->circ->stop_fines eq OILS_STOP_FINES_CLAIMSRETURNED);
+ $self->check_circ_deposit();
+
# handle the overridable events
$self->override_events unless $self->is_renewal;
return if $self->bail_out;
@@ -1462,6 +1535,20 @@
return;
}
+# if a deposit was payed for this item, push the event
+sub check_circ_deposit {
+ my $self = shift;
+ return unless $self->circ;
+ my $deposit = $self->editor->search_money_billing(
+ { billing_type => OILS_BILLING_TYPE_DEPOSIT,
+ xact => $self->circ->id,
+ voided => 'f'
+ }, {idlist => 1})->[0];
+
+ $self->push_events(OpenILS::Event->new(
+ 'ITEM_DEPOSIT_PAID', payload => $deposit)) if $deposit;
+}
+
sub reshelve_copy {
my $self = shift;
my $force = $self->force || shift;
Modified: branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Const.pm
===================================================================
--- branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Const.pm 2008-11-03 17:46:46 UTC (rev 11038)
+++ branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Const.pm 2008-11-03 17:57:23 UTC (rev 11039)
@@ -92,6 +92,9 @@
econst OILS_BILLING_TYPE_OVERDUE_MATERIALS => 'Overdue materials';
econst OILS_BILLING_TYPE_COLLECTION_FEE => 'Long Overdue Collection Fee';
+econst OILS_BILLING_TYPE_DEPOSIT => 'System: Deposit';
+econst OILS_BILLING_TYPE_RENTAL => 'System: Rental';
+econst OILS_BILLING_NOTE_SYSTEM => 'SYSTEM GENERATED';
More information about the open-ils-commits
mailing list