[open-ils-commits] r10794 - in trunk/Open-ILS/src/perlmods/OpenILS/Application: . Circ

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Oct 8 15:25:01 EDT 2008


Author: erickson
Date: 2008-10-08 15:24:57 -0400 (Wed, 08 Oct 2008)
New Revision: 10794

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
Log:
extracted copy price calculation out to a shared function

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm	2008-10-08 18:53:38 UTC (rev 10793)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm	2008-10-08 19:24:57 UTC (rev 10794)
@@ -1496,5 +1496,41 @@
 }
 
 
+sub get_copy_price {
+	my($self, $e, $copy, $volume) = @_;
+
+	$copy->price(0) if $copy->price < 0;
+
+	return $copy->price if $copy->price and $copy->price > 0;
+
+
+	my $owner;
+	if(ref $volume) {
+		if($volume->id == OILS_PRECAT_CALL_NUMBER) {
+			$owner = $copy->circ_lib;
+		} else {
+			$owner = $volume->owning_lib;
+		}
+	} else {
+		if($copy->call_number == OILS_PRECAT_CALL_NUMBER) {
+			$owner = $copy->circ_lib;
+		} else {
+			$owner = $e->retrieve_asset_call_number($copy->call_number)->owning_lib;
+		}
+	}
+
+	my $default_price = $self->ou_ancestor_setting_value(
+		$owner, OILS_SETTING_DEF_ITEM_PRICE, $e) || 0;
+
+	return $default_price unless defined $copy->price;
+
+	# price is 0.  Use the default?
+    my $charge_on_0 = $self->ou_ancestor_setting_value(
+        $owner, OILS_SETTING_CHARGE_LOST_ON_ZERO, $e) || 0;
+
+	return $default_price if $charge_on_0;
+	return 0;
+}
+
 1;
 

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm	2008-10-08 18:53:38 UTC (rev 10793)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm	2008-10-08 19:24:57 UTC (rev 10794)
@@ -944,23 +944,8 @@
     # if is_percent is true then the max->amount is
     # use as a percentage of the copy price
     if ($U->is_true($max_fine_rule->is_percent)) {
-
-        my $ol = ($self->is_precat) ? 
-            $self->editor->requestor->ws_ou : $self->volume->owning_lib;
-
-        my $default_price = $U->ou_ancestor_setting_value(
-            $ol, OILS_SETTING_DEF_ITEM_PRICE, $self->editor) || 0;
-        my $charge_on_0 = $U->ou_ancestor_setting_value(
-            $ol, OILS_SETTING_CHARGE_LOST_ON_ZERO, $self->editor) || 0;
-
-        # Find the most appropriate "price" -- same definition as the
-        # LOST price.  See OpenILS::Circ::new_set_circ_lost
-        $max_amount = $self->copy->price;
-        $max_amount = $default_price unless defined $max_amount;
-        $max_amount = 0 if $max_amount < 0;
-        $max_amount = $default_price if $max_amount == 0 and $charge_on_0;
-
-        $max_amount *= $max_fine_rule->amount / 100;
+        my $price = $U->get_copy_price($self->editor, $self->copy, $self->volume);
+        $max_amount = $price * $max_fine_rule->amount / 100;
     }  
 
     return $max_amount;

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm	2008-10-08 18:53:38 UTC (rev 10793)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm	2008-10-08 19:24:57 UTC (rev 10794)
@@ -249,7 +249,7 @@
             or return $e->die_event;
 
     my $owning_lib = 
-        ($copy->call_number == OILS_PRECAT_CALL_NUMBER) ? 
+        ($copy->call_number->id == OILS_PRECAT_CALL_NUMBER) ? 
             $copy->circ_lib : $copy->call_number->owning_lib;
 
     my $circ = $e->search_action_circulation(
@@ -263,18 +263,11 @@
 
     # ---------------------------------------------------------------------
     # fetch the related org settings
-    my $default_price = $U->ou_ancestor_setting_value(
-        $owning_lib, OILS_SETTING_DEF_ITEM_PRICE, $e) || 0;
     my $proc_fee = $U->ou_ancestor_setting_value(
         $owning_lib, OILS_SETTING_LOST_PROCESSING_FEE, $e) || 0;
-    my $charge_on_0 = $U->ou_ancestor_setting_value(
-        $owning_lib, OILS_SETTING_CHARGE_LOST_ON_ZERO, $e) || 0;
     my $void_overdue = $U->ou_ancestor_setting_value(
         $owning_lib, OILS_SETTING_VOID_OVERDUE_ON_LOST, $e) || 0;
 
-    $logger->info("org settings: default price = $default_price, ".
-        "processing fee = $proc_fee, charge on 0 = $charge_on_0, void overdues = $void_overdue");
-
     # ---------------------------------------------------------------------
     # move the copy into LOST status
     $copy->status(OILS_COPY_STATUS_LOST);
@@ -282,12 +275,7 @@
     $copy->edit_date('now');
     $e->update_asset_copy($copy) or return $e->die_event;
 
-    # ---------------------------------------------------------------------
-    # determine the appropriate item price to charge and create the billing
-    my $price = $copy->price;
-    $price = $default_price unless defined $price;
-    $price = 0 if $price < 0;
-    $price = $default_price if $price == 0 and $charge_on_0;
+    my $price = $U->get_copy_price($e, $copy, $copy->call_number);
 
     if( $price > 0 ) {
         my $evt = create_bill($e, $price, 'Lost Materials', $circ->id);



More information about the open-ils-commits mailing list