[open-ils-commits] r12910 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Sun Apr 19 19:36:29 EDT 2009
Author: erickson
Date: 2009-04-19 19:36:28 -0400 (Sun, 19 Apr 2009)
New Revision: 12910
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
Log:
more enhanced lineitem price setting. updates existing debits if necessary
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm 2009-04-19 16:50:59 UTC (rev 12909)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm 2009-04-19 23:36:28 UTC (rev 12910)
@@ -1555,4 +1555,72 @@
return 1;
}
+
+__PACKAGE__->register_method(
+ method => 'set_lineitem_price_api',
+ api_name => 'open-ils.acq.lineitem.price.set',
+ signature => {
+ desc => 'Set lineitem price. If debits already exist, update them as well',
+ params => [
+ {desc => 'Authentication token', type => 'string'},
+ {desc => 'lineitem ID', type => 'number'}
+ ],
+ return => {desc => 'status blob, Event on error'}
+ }
+);
+
+sub set_lineitem_price_api {
+ my($self, $conn, $auth, $li_id, $price, $currency) = @_;
+
+ my $e = new_editor(xact=>1, authtoken=>$auth);
+ return $e->die_event unless $e->checkauth;
+ my $mgr = OpenILS::Application::Acq::BatchManager->new(editor => $e, conn => $conn);
+
+ # XXX perms
+
+ my $li = $e->retrieve_acq_lineitem($li_id) or return $e->die_event;
+
+ # update the local attr for estimated price
+ set_lineitem_attr(
+ $mgr,
+ attr_name => 'estimated_price',
+ attr_type => 'lineitem_local_attr_definition',
+ attr_value => $price,
+ lineitem => $li_id
+ ) or return $e->die_event;
+
+ my $lid_ids = $e->search_acq_lineitem_detail(
+ {lineitem => $li_id, fund_debit => {'!=' => undef}},
+ {idlist => 1}
+ );
+
+ for my $lid_id (@$lid_ids) {
+
+ my $lid = $e->retrieve_acq_lineitem_detail([
+ $lid_id, {
+ flesh => 1, flesh_fields => {acqlid => ['fund', 'fund_debit']}}
+ ]);
+
+ # onless otherwise specified, assume currency of new price is same as currency type of the fund
+ $currency ||= $lid->fund->currency_type;
+ my $amount = $price;
+
+ if($lid->fund->currency_type ne $currency) {
+ $amount = currency_conversion($mgr, $currency, $lid->fund->currency_type, $price);
+ }
+
+ $lid->fund_debit->origin_currency_type($currency);
+ $lid->fund_debit->origin_amount($price);
+ $lid->fund_debit->amount($amount);
+
+ $e->update_acq_fund_debit($lid->fund_debit) or return $e->die_event;
+ $mgr->add_lid;
+ $mgr->respond;
+ }
+
+ $e->commit;
+ return $mgr->respond_complete;
+}
+
+
1;
More information about the open-ils-commits
mailing list