From 1d1c1b6bbbc40341b5fec2a5cdc8125805550f11 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 8 Aug 2013 09:06:12 -0400 Subject: [PATCH] LP1209291 vandelay item import defaults Signed-off-by: Bill Erickson --- .../src/perlmods/lib/OpenILS/Application/Vandelay.pm | 18 +++++++++--------- Open-ILS/src/sql/Pg/999.functions.global.sql | 18 ++++++++++++++++++ .../XXXX.schema.vandelay-item-import-defaults.sql | 17 +++++++++++++++++ 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm index 0524ea0b45..1c98be2ac5 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm @@ -1610,9 +1610,9 @@ sub import_record_asset_list_impl { ); # if any items have no call_number label and a value should be - # applied automatically (via org settings), keep a record-level - # copy handy so we can use the same call number for all such copies - my $auto_callnumber; + # applied automatically (via org settings), we want to use the same + # call number label for every copy per org per record. + my $auto_callnumber = {}; for my $item_id (@$item_ids) { my $e = new_editor(requestor => $requestor, xact => 1); @@ -1766,7 +1766,7 @@ sub import_record_asset_list_impl { # appply defaults values from org settings as needed # if $auto_callnumber is unset, it will be set within - apply_import_item_defaults($e, $item, \$auto_callnumber); + apply_import_item_defaults($e, $item, $auto_callnumber); if($evt) { $$report_args{evt} = $evt; @@ -1866,7 +1866,7 @@ sub import_record_asset_list_impl { } sub apply_import_item_defaults { - my ($e, $item, $auto_cn_ref) = @_; + my ($e, $item, $auto_cn) = @_; my $org = $item->owning_lib || $item->circ_lib; my %c = %item_defaults_cache; @@ -1900,16 +1900,16 @@ sub apply_import_item_defaults { if ($set->('call_number.auto')) { - if (!$$auto_cn_ref) { + if (!$auto_cn->{$org}) { my $pfx = $set->('call_number.prefix') || 'VAN'; # use the ID of the first item to differentiate this # call number from others linked to the same record - $$auto_cn_ref = $pfx . $item->record . $item->id; + $auto_cn->{$org} = $pfx . $item->record . $item->id; } - $logger->info("vl: using auto call number $$auto_cn_ref"); - $item->call_number($$auto_cn_ref); + $logger->info("vl: using auto call number ".$auto_cn->{$org}); + $item->call_number($auto_cn->{$org}); } else { $logger->error("vl: no call number or default for item ".$item->id); diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 8cb6c2d34f..4ff749847b 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -1873,6 +1873,15 @@ BEGIN 'vandelay.item.circ_modifier.default', attr_set.owning_lib ); + + -- make sure the value from the org setting is still valid + PERFORM 1 FROM config.circ_modifier WHERE code = attr_set.circ_modifier; + IF NOT FOUND THEN + attr_set.import_error := 'import.item.invalid.circ_modifier'; + attr_set.error_detail := tmp_attr_set.circ_mod; + RETURN NEXT attr_set; CONTINUE; + END IF; + ELSE SELECT code INTO attr_set.circ_modifier FROM config.circ_modifier WHERE code = tmp_attr_set.circ_mod; @@ -1900,6 +1909,14 @@ BEGIN 'vandelay.item.copy_location.default', attr_set.owning_lib ); + + -- make sure the value from the org setting is still valid + PERFORM 1 FROM asset.copy_location WHERE id = attr_set.location; + IF NOT FOUND THEN + attr_set.import_error := 'import.item.invalid.location'; + attr_set.error_detail := tmp_attr_set.cs; + RETURN NEXT attr_set; CONTINUE; + END IF; ELSE -- search up the org unit tree for a matching copy location @@ -1972,6 +1989,7 @@ $$ LANGUAGE PLPGSQL; + CREATE OR REPLACE FUNCTION vandelay.ingest_bib_items ( ) RETURNS TRIGGER AS $func$ DECLARE attr_def BIGINT; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.vandelay-item-import-defaults.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.vandelay-item-import-defaults.sql index 540dce1d6d..905f9267d5 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.vandelay-item-import-defaults.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.vandelay-item-import-defaults.sql @@ -373,6 +373,15 @@ BEGIN 'vandelay.item.circ_modifier.default', attr_set.owning_lib ); + + -- make sure the value from the org setting is still valid + PERFORM 1 FROM config.circ_modifier WHERE code = attr_set.circ_modifier; + IF NOT FOUND THEN + attr_set.import_error := 'import.item.invalid.circ_modifier'; + attr_set.error_detail := tmp_attr_set.circ_mod; + RETURN NEXT attr_set; CONTINUE; + END IF; + ELSE SELECT code INTO attr_set.circ_modifier FROM config.circ_modifier WHERE code = tmp_attr_set.circ_mod; @@ -400,6 +409,14 @@ BEGIN 'vandelay.item.copy_location.default', attr_set.owning_lib ); + + -- make sure the value from the org setting is still valid + PERFORM 1 FROM asset.copy_location WHERE id = attr_set.location; + IF NOT FOUND THEN + attr_set.import_error := 'import.item.invalid.location'; + attr_set.error_detail := tmp_attr_set.cs; + RETURN NEXT attr_set; CONTINUE; + END IF; ELSE -- search up the org unit tree for a matching copy location -- 2.11.0