From: Galen Charlton Date: Wed, 8 Dec 2021 23:40:21 +0000 (-0500) Subject: LP#1942220: various updates to business logic X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=c0264689599b88ecdc6ac687d76ba76cbfddd6a7;p=evergreen%2Fjoelewis.git LP#1942220: various updates to business logic * set 024 ind1 correctly (i.e., to '1') when applying UPC as order identifier * add flesh_po_items_further option to PO retrieval This fleshes in any fund debits and debit invoice items associated with PO direct charges * add open-ils.acq.po_item.disencumber method This method disencumbers a PO item by setting its fund debit's amount to zero. Note that this can be done only for encumbrances; if the debit is an expenditure, it cannot be changed. * add flesh_li_details_receiver to LI retrieval * add two additional fleshing options to LI retrieval Specifically, flesh_copy_location and flesh_call_number. These take effect only when flesh_copies is also true and are used to further flesh values of items attached to line item details. * remove cancel reason if last LID of LI is received Otherwise, a sequence where a line item was cancelled but one of its items was received would have the LI end up in a received state but with a cancel reason. Signed-off-by: Galen Charlton Signed-off-by: Ruth Frasur Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm index bc273386c6..f5680f2ccb 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm @@ -1026,6 +1026,11 @@ sub retrieve_purchase_order_impl { } push (@{$flesh->{flesh_fields}->{acqpo}}, 'po_items') if $options->{flesh_po_items}; + if ($options->{flesh_po_items_further}) { + push (@{$flesh->{flesh_fields}->{acqpoi}}, 'fund_debit'); + push (@{$flesh->{flesh_fields}->{acqfdeb}}, 'invoice_items'); + $flesh->{'flesh'} = 3; + } my $args = (@{$flesh->{"flesh_fields"}->{"acqpo"}}) ? [$po_id, $flesh] : $po_id; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Lineitem.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Lineitem.pm index 60eeb59e03..45d62f86c2 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Lineitem.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Lineitem.pm @@ -188,7 +188,12 @@ sub retrieve_lineitem_impl { push(@{$fields->{acqlid}}, 'cancel_reason') if $$options{flesh_cancel_reason}; push(@{$fields->{acqlid}}, 'circ_modifier') if $$options{flesh_circ_modifier}; push(@{$fields->{acqlid}}, 'location') if $$options{flesh_location}; - push(@{$fields->{acqlid}}, 'eg_copy_id') if $$options{flesh_copies}; + if ($$options{flesh_copies}) { + push(@{$fields->{acqlid}}, 'eg_copy_id'); + push(@{$fields->{acp}}, 'call_number') if $$options{flesh_call_number}; + push(@{$fields->{acp}}, 'location') if $$options{flesh_copy_location}; + } + push(@{$fields->{acqlid}}, 'receiver') if $$options{flesh_li_details_receiver}; } if($$options{clear_marc}) { # avoid fetching marc blob diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm index 475c61f01a..e8cdf53fa0 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm @@ -623,6 +623,7 @@ sub check_lineitem_received { my $li = $mgr->editor->retrieve_acq_lineitem($li_id); $li->state('received'); + $li->clear_cancel_reason; # un-cancel on receive return update_lineitem($mgr, $li); } @@ -3483,6 +3484,47 @@ sub delete_po_item_api { return 1; } +__PACKAGE__->register_method( + method => "disencumber_po_item_api", + api_name => "open-ils.acq.po_item.disencumber", + signature => { + desc => q/Zeroes out a po_item's encumbrance/, + params => [ + {desc => "Authentication token", type => "string"}, + {desc => "po_item ID disencumber", type => "number"}, + ], + return => {desc => q/1 on success, Event on error/} + } +); + +sub disencumber_po_item_api { + my($self, $client, $auth, $po_item_id) = @_; + my $e = new_editor(authtoken => $auth, xact => 1); + return $e->die_event unless $e->checkauth; + + my $po_item = $e->retrieve_acq_po_item([ + $po_item_id, { + flesh => 1, + flesh_fields => {acqpoi => ['purchase_order', 'fund_debit']} + } + ]) or return $e->die_event; + + return $e->die_event unless + $e->allowed('CREATE_PURCHASE_ORDER', + $po_item->purchase_order->ordering_agency); + + # reduce encumbered amount to zero + my $result = disencumber_po_item($e, $po_item); + + if ($result) { + $e->rollback; + return $result; + } + + $e->commit; + return 1; +} + # 1. Removes linked fund debit from a PO item if present and still encumbered. # 2. Optionally also deletes the po_item object @@ -3514,6 +3556,29 @@ sub clear_po_item { return undef; } +# Zeroes the amount of a fund debit for a PO item if present and still +# encumbered. Note that we're intentionally still keeping the fund_debit +# around to signify that the encumbrance was manually zeroed. +# po_item is fleshed with purchase_order and fund_debit +sub disencumber_po_item { + my ($e, $po_item, $delete_item) = @_; + + if ($po_item->fund_debit) { + + if (!$U->is_true($po_item->fund_debit->encumbrance)) { + # debit has been paid. We cannot delete it. + return OpenILS::Event->new('ACQ_NOT_CANCELABLE', + note => "Debit is marked as paid: ".$po_item->fund_debit->id); + } + + # fund_debit is OK to zero out. + $po_item->fund_debit->amount(0); + $e->update_acq_fund_debit($po_item->fund_debit) + or return $e->die_event; + } + + return undef; +} __PACKAGE__->register_method( method => 'user_requests', @@ -4248,8 +4313,9 @@ sub apply_new_li_ident_attr { upc => '024' ); + my $ind1 = $attr_name eq 'upc' ? '1' : ' '; my $marc_field = MARC::Field->new( - $tags{$attr_name}, '', '','a' => $attr_value); + $tags{$attr_name}, $ind1, '','a' => $attr_value); my $li_rec = MARC::Record->new_from_xml($li->marc, 'UTF-8', 'USMARC'); $li_rec->insert_fields_ordered($marc_field);