[open-ils-commits] r17284 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Aug 20 10:11:29 EDT 2010
Author: erickson
Date: 2010-08-20 10:11:27 -0400 (Fri, 20 Aug 2010)
New Revision: 17284
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm
trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
Log:
propagate estimated price to created copy as copy price (aka list price or replacement price); propagate invoiced amount to created copy as copy cost (aka library cost); caveats and consderations noted in the code.
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm 2010-08-20 14:11:27 UTC (rev 17283)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm 2010-08-20 14:11:27 UTC (rev 17284)
@@ -163,11 +163,11 @@
my $lineitem = $e->retrieve_acq_lineitem($entry->lineitem) or return $e->die_event;
for my $debit (@$debits) {
-
# revert to the original estimated amount re-encumber
$debit->encumbrance('t');
$debit->amount($lineitem->estimated_unit_price());
$e->update_acq_fund_debit($debit) or return $e->die_event;
+ update_copy_cost($e, $debit) or return $e->die_event; # clear the cost
}
return undef;
@@ -188,15 +188,44 @@
}
for my $debit (@$debits) {
- $debit->amount(entry_amount_per_item($entry));
+ my $amount = entry_amount_per_item($entry);
+ $debit->amount($amount);
$debit->encumbrance('f');
$e->update_acq_fund_debit($debit) or return $e->die_event;
+
+ # TODO: this does not reflect ancillary charges, like taxes, etc.
+ # We may need a way to indicate whether the amount attached to an
+ # invoice_item should be prorated and included in the copy cost.
+ # Note that acq.invoice_item_type.prorate does not necessarily
+ # mean a charge should be included in the copy price, only that
+ # it should spread accross funds.
+ update_copy_cost($e, $debit, $amount) or return $e->die_event;
}
return undef;
}
+# update the linked copy to reflect the amount paid for the item
+# returns true on success, false on error
+sub update_copy_cost {
+ my ($e, $debit, $amount) = @_;
+ my $lid = $e->search_acq_lineitem_detail([
+ {fund_debit => $debit->id},
+ {flesh => 1, flesh_fields => {acqlid => ['eg_copy_id']}}
+ ])->[0];
+
+ if($lid and my $copy = $lid->eg_copy_id) {
+ defined $amount and $copy->cost($amount) or $copy->clear_cost;
+ $copy->editor($e->requestor->id);
+ $copy->edit_date('now');
+ $e->update_asset_copy($copy) or return 0;
+ }
+
+ return 1;
+}
+
+
sub entry_amount_per_item {
my $entry = shift;
return $entry->amount_paid if $U->is_true($entry->billed_per_item);
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm 2010-08-20 14:11:27 UTC (rev 17283)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm 2010-08-20 14:11:27 UTC (rev 17284)
@@ -986,7 +986,7 @@
$volume = create_volume($mgr, $li, $lid) or return 0;
$mgr->cache($org, "cn.$bibid.$label", $volume);
}
- create_copy($mgr, $volume, $lid) or return 0;
+ create_copy($mgr, $volume, $lid, $li) or return 0;
}
return { li => $li, new_bib => $new_bib };
@@ -1034,7 +1034,7 @@
}
sub create_copy {
- my($mgr, $volume, $lid) = @_;
+ my($mgr, $volume, $lid, $li) = @_;
my $copy = Fieldmapper::asset::copy->new;
$copy->isnew(1);
$copy->loan_duration(2);
@@ -1046,6 +1046,10 @@
$copy->circ_lib($volume->owning_lib);
$copy->circ_modifier($lid->circ_modifier);
+ # AKA list price. We might need a $li->list_price field since
+ # estimated price is not necessarily the same as list price
+ $copy->price($li->estimated_unit_price);
+
my $evt = OpenILS::Application::Cat::AssetCommon->create_copy($mgr->editor, $volume, $copy);
if($evt) {
$mgr->editor->event($evt);
More information about the open-ils-commits
mailing list