[open-ils-commits] r16364 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Apr 30 16:49:34 EDT 2010
Author: erickson
Date: 2010-04-30 16:49:28 -0400 (Fri, 30 Apr 2010)
New Revision: 16364
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
Log:
added support for update the fund on an LID after the debits have been created. added a .dry_run version of open-ils.acq.lineitem_detail.cud.batch[.dry_run] to allow the caller to check the fund warning percents
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm 2010-04-30 20:39:29 UTC (rev 16363)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm 2010-04-30 20:49:28 UTC (rev 16364)
@@ -1555,17 +1555,33 @@
}
);
+__PACKAGE__->register_method(
+ method => 'lineitem_detail_CUD_batch',
+ api_name => 'open-ils.acq.lineitem_detail.cud.batch.dry_run',
+ stream => 1,
+ signature => {
+ desc => q/
+ Dry run version of open-ils.acq.lineitem_detail.cud.batch.
+ In dry_run mode, updated fund_debit's the exceed the warning
+ percent return an event.
+ /
+ }
+);
+
+
sub lineitem_detail_CUD_batch {
my($self, $conn, $auth, $li_details, $create_debits) = @_;
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);
+ my $dry_run = ($self->api_name =~ /dry_run/o);
$mgr->total(scalar(@$li_details));
my $li;
my %li_cache;
+ my $fund_cache = {};
my $evt;
for my $lid (@$li_details) {
@@ -1584,7 +1600,7 @@
}
} elsif($lid->ischanged) {
- $e->update_acq_lineitem_detail($lid) or return $e->die_event;
+ return $evt if $evt = handle_changed_lid($e, $lid, $dry_run, $fund_cache);
} elsif($lid->isdeleted) {
delete_lineitem_detail($mgr, $lid) or return $e->die_event;
@@ -1598,7 +1614,33 @@
return $mgr->respond_complete;
}
+sub handle_changed_lid {
+ my($e, $lid, $dry_run, $fund_cache) = @_;
+ my $orig_lid = $e->retrieve_acq_lineitem_detail($lid->id) or return $e->die_event;
+
+ # updating the fund, so update the debit
+ if($orig_lid->fund_debit and $orig_lid->fund != $lid->fund) {
+
+ my $debit = $e->retrieve_acq_fund_debit($orig_lid->fund_debit);
+ my $new_fund = $$fund_cache{$lid->fund} =
+ $$fund_cache{$lid->fund} || $e->retrieve_acq_fund($lid->fund);
+
+ # check the thresholds
+ return $e->die_event if
+ fund_exceeds_balance_percent($new_fund, $debit->amount, $e, "stop");
+ return $e->die_event if $dry_run and
+ fund_exceeds_balance_percent($new_fund, $debit->amount, $e, "warning");
+
+ $debit->fund($new_fund->id);
+ $e->update_acq_fund_debit($debit) or return $e->die_event;
+ }
+
+ $e->update_acq_lineitem_detail($lid) or return $e->die_event;
+ return undef;
+}
+
+
__PACKAGE__->register_method(
method => 'receive_po_api',
api_name => 'open-ils.acq.purchase_order.receive'
More information about the open-ils-commits
mailing list