From: Bill Erickson Date: Wed, 30 Jan 2013 14:36:17 +0000 (-0500) Subject: Default number of ACQ copies per provider X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b6425d785d603adb587affd7437f9289fb8cbc20;p=evergreen%2Fmasslnc.git Default number of ACQ copies per provider Acquisitions providers have a new "Default # Copies" field. When the value is set, this number of copies will be automatically added to each lineitem added to a purchase order for the provider. This takes place during PO creation from a selection list or existing bib record and when a lineitem is added to an existing purchase order. If a lineitem already has copies attached, no default copies are added. Signed-off-by: Bill Erickson Signed-off-by: Kathy Lussier --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index f6565735cb..ce82deae92 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -6834,6 +6834,7 @@ SELECT usr, + 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 47687f8e2f..e41690eafd 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Lineitem.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Lineitem.pm @@ -49,9 +49,12 @@ sub create_lineitem { $e->update_acq_picklist($picklist) or return $e->die_event; } + my $po; if($li->purchase_order) { - my $po = $e->retrieve_acq_purchase_order($li->purchase_order) - or return $e->die_event; + $po = $e->retrieve_acq_purchase_order([ + $li->purchase_order, + {flesh => 1, flesh_fields => {acqpo => ['provider']}} + ]) or return $e->die_event; return $e->die_event unless $e->allowed('MANAGE_PROVIDER', $po->ordering_agency, $po); @@ -59,7 +62,16 @@ sub create_lineitem { } $li->selector($e->requestor->id); - $e->create_acq_lineitem($li) or return $e->die_event; + $li = $e->create_acq_lineitem($li) or return $e->die_event; + + if ($po) { + # apply the default number of copies for this provider + for (1 .. $po->provider->default_copy_count) { + my $lid = Fieldmapper::acq::lineitem_detail->new; + $lid->lineitem($li->id); + $e->create_acq_lineitem_detail($lid) or return $e->die_event; + } + } $e->commit; return $li->id; 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 a297b74208..4f899b7f77 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm @@ -1792,13 +1792,63 @@ sub create_purchase_order_api { # commit before starting the asset creation $e->xact_commit; - if($li_ids and $vandelay) { - create_lineitem_list_assets($mgr, $li_ids, $vandelay, !$$args{create_assets}) or return $e->die_event; + if($li_ids) { + + if ($vandelay) { + create_lineitem_list_assets( + $mgr, $li_ids, $vandelay, !$$args{create_assets}) + or return $e->die_event; + } + + $e->xact_begin; + apply_default_copies($mgr, $po) or return $e->die_event; + $e->xact_commit; } return $mgr->respond_complete; } +# !transaction must be managed by the caller +# creates the default number of copies for each lineitem on the PO. +# when a LI already has copies attached, no default copies are added. +# without li_id, all lineitems are checked/applied +# returns 1 on success, 0 on error +sub apply_default_copies { + my ($mgr, $po, $li_id) = @_; + + my $e = $mgr->editor; + + my $provider = ref($po->provider) ? $po->provider : + $e->retrieve_acq_provider($po->provider); + + my $copy_count = $provider->default_copy_count || return 1; + + $logger->info("Applying $copy_count default copies for PO ".$po->id); + + my $li_ids = $li_id ? [$li_id] : + $e->search_acq_lineitem({ + purchase_order => $po->id, + cancel_reason => undef + }, + {idlist => 1} + ); + + for my $li_id (@$li_ids) { + + my $lid_ids = $e->search_acq_lineitem_detail( + {lineitem => $li_id}, {idlist => 1}); + + # do not apply default copies when copies already exist + next if @$lid_ids; + + for (1 .. $copy_count) { + create_lineitem_detail($mgr, lineitem => $li_id) or return 0; + } + } + + return 1; +} + __PACKAGE__->register_method( diff --git a/Open-ILS/src/sql/Pg/200.schema.acq.sql b/Open-ILS/src/sql/Pg/200.schema.acq.sql index aad60a4c2f..89c573af2f 100644 --- a/Open-ILS/src/sql/Pg/200.schema.acq.sql +++ b/Open-ILS/src/sql/Pg/200.schema.acq.sql @@ -89,6 +89,7 @@ CREATE TABLE acq.provider ( email TEXT, phone TEXT, fax_phone TEXT, + default_copy_count INT NOT NULL DEFAULT 0, default_claim_policy INT REFERENCES acq.claim_policy DEFERRABLE INITIALLY DEFERRED, CONSTRAINT provider_name_once_per_owner UNIQUE (name,owner), diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.provider_copy_count.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.provider_copy_count.sql new file mode 100644 index 0000000000..9422a8e2b3 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.provider_copy_count.sql @@ -0,0 +1,7 @@ + +BEGIN; + +ALTER TABLE acq.provider + ADD COLUMN default_copy_count INTEGER NOT NULL DEFAULT 0; + +COMMIT; diff --git a/docs/RELEASE_NOTES_NEXT/acq_default_copy_count.txt b/docs/RELEASE_NOTES_NEXT/acq_default_copy_count.txt new file mode 100644 index 0000000000..4ff5cc42d0 --- /dev/null +++ b/docs/RELEASE_NOTES_NEXT/acq_default_copy_count.txt @@ -0,0 +1,8 @@ +New Feature: Default Number of Acquisistions Copies to Order +============================================================ +Acquisitions providers have a new "Default # Copies" field. When the value +is set, this number of copies will be automatically added to each lineitem +added to a purchase order for the provider. This takes place during PO +creation from a selection list or existing bib record and when a lineitem is +added to an existing purchase order. If a lineitem already has copies +attached, no default copies are added.