<field reporter:label="Phone" name="phone" reporter:datatype="text" />
<field reporter:label="Fax Phone" name="fax_phone" reporter:datatype="text" />
<field reporter:label="Default Claim Policy" name="default_claim_policy" reporter:datatype="link" />
+ <field reporter:label="Default # Copies" name="default_copy_count" reporter:datatype="int" />
</fields>
<links>
<link field="currency_type" reltype="has_a" key="code" map="" class="acqct"/>
$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);
}
$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;
# 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(
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),
--- /dev/null
+
+BEGIN;
+
+ALTER TABLE acq.provider
+ ADD COLUMN default_copy_count INTEGER NOT NULL DEFAULT 0;
+
+COMMIT;
--- /dev/null
+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.