From 3adfea21b9988ca06dc54639da271aa1b4d6b1b9 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 6 Dec 2021 15:58:50 -0500 Subject: [PATCH] LP1952931 ASN shipment notifiation Perl Test Signed-off-by: Bill Erickson --- Open-ILS/examples/fm_IDL.xml | 4 +++- .../perlmods/lib/OpenILS/Application/Acq/EDI.pm | 10 ++++++++-- .../src/perlmods/lib/OpenILS/Utils/EDIReader.pm | 2 +- Open-ILS/src/perlmods/live_t/35-acq-asn-edi.t | 16 ++++++++++++---- Open-ILS/src/sql/Pg/200.schema.acq.sql | 3 ++- .../src/sql/Pg/upgrade/XXXX.schema.acq-asn.sql | 22 ++++++++++++++++++++-- 6 files changed, 46 insertions(+), 11 deletions(-) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 993004dacb..dd16d98c81 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -9471,6 +9471,7 @@ SELECT usr, + @@ -9481,6 +9482,7 @@ SELECT usr, + @@ -9502,7 +9504,7 @@ SELECT usr, - + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm index 9ff26810bf..c5e9dbc3d1 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm @@ -22,6 +22,7 @@ my $U = 'OpenILS::Application::AppUtils'; use OpenILS::Utils::EDIReader; use Data::Dumper; +$Data::Dumper::Indent = 0; our $verbose = 0; sub new { @@ -1151,6 +1152,8 @@ sub create_shipment_notification_from_edi { my ($class, $msg_data, $provider_id, $edi_message) = @_; # $msg_data is O::U::EDIReader hash + $logger->info("ASN: " . Dumper($msg_data)); + my $e = new_editor(); my $eg_asn = Fieldmapper::acq::shipment_notification->new; @@ -1235,7 +1238,10 @@ sub extract_shipment_notification_entries { from => { jub => { acqlia => { - filter => {order_ident => 't', value => $ident} + filter => { + order_ident => 't', + attr_value => $ident + } } } }, @@ -1259,7 +1265,7 @@ sub extract_shipment_notification_entries { my $entry = Fieldmapper::acq::shipment_notification_entry->new; $entry->lineitem($li_id); - $entry->item_count($quant); + $entry->item_count($quantity); push(@entries, $entry); } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm index 076667afd1..bf8b7c3e1f 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm @@ -32,7 +32,7 @@ my %edi_fields = ( invoice_ident => qr/^BGM\+380\+([^\+]+)/, total_billed => qr/^MOA\+86:([^:]+)/, invoice_date => qr/^DTM\+137:([^:]+)/, # This is really "messge date" - package_code => qr/^GIN\+BJ\+([^:]+)/, + container_code => qr/^GIN\+BJ\+([^:]+)/, lading_number => qr/^RFF\+BM:([^:]+)/ ); diff --git a/Open-ILS/src/perlmods/live_t/35-acq-asn-edi.t b/Open-ILS/src/perlmods/live_t/35-acq-asn-edi.t index a5c728ae87..de509dd840 100755 --- a/Open-ILS/src/perlmods/live_t/35-acq-asn-edi.t +++ b/Open-ILS/src/perlmods/live_t/35-acq-asn-edi.t @@ -7,7 +7,7 @@ use OpenILS::Utils::Fieldmapper; use OpenILS::Application::Acq::EDI; $Data::Dumper::Indent = 0; -use Test::More tests => 3; +use Test::More tests => 5; diag("Tests EDI Shipment Notifications"); @@ -78,6 +78,7 @@ sub create_seed_data { $edi_account->provider(PROVIDER_ID); $edi_account->host("example.org"); $edi_account->label("ASN TEST"); + $edi_account->use_attrs('f'); # doesn't matter here BAIL_OUT("Could not create EDI account " . Dumper($e->die_event)) unless $e->create_acq_edi_account($edi_account); @@ -109,7 +110,7 @@ sub create_po { $li->provider(PROVIDER_ID); $li->estimated_unit_price('25.00'); - my $li_id = $U->simplereq('open-ils.acq', + $li_id = $U->simplereq('open-ils.acq', 'open-ils.acq.lineitem.create', $script->authtoken, $li); BAIL_OUT("Failed to create Lineitem: " . Dumper($li_id)) if $U->is_event($li_id); @@ -163,7 +164,7 @@ NAD+DP+1234567 0011::9' CPS+1' PAC+1+5' GIN+BJ+00016921002621109648' -LIN+00001++9781643857701:EN' +LIN+00001++9780307887436:EN' QTY+12:1' RFF+ON:$po_id' CNT+2:1' @@ -178,8 +179,15 @@ ASN $edi_account ); - # TODO test presence of shipment notification and entry + my $notification = $e->search_acq_shipment_notification([ + {id => {'<>' => undef}}, + {flesh => 1, flesh_fields => {acqsn => ['entries']}} + ])->[0]; + ok($notification, 'Created a notification'); + + ok($notification->entries->[0]->lineitem eq $li_id, + "Created notification for lineitem $li_id"); } main(); diff --git a/Open-ILS/src/sql/Pg/200.schema.acq.sql b/Open-ILS/src/sql/Pg/200.schema.acq.sql index e0ca2bd220..bb6b7403d3 100644 --- a/Open-ILS/src/sql/Pg/200.schema.acq.sql +++ b/Open-ILS/src/sql/Pg/200.schema.acq.sql @@ -805,7 +805,8 @@ CREATE TABLE acq.edi_message ( 'ORDRSP', 'INVOIC', 'OSTENQ', - 'OSTRPT' + 'OSTRPT', + 'DESADV' )) ); CREATE INDEX edi_message_account_status_idx ON acq.edi_message (account,status); diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq-asn.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq-asn.sql index c4458905ea..7b92e1b84b 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq-asn.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq-asn.sql @@ -8,6 +8,7 @@ CREATE TABLE acq.shipment_notification ( provider INT NOT NULL REFERENCES acq.provider (id), shipper INT NOT NULL REFERENCES acq.provider (id), recv_date TIMESTAMPTZ NOT NULL DEFAULT NOW(), + recv_method TEXT NOT NULL REFERENCES acq.invoice_method (code) DEFAULT 'EDI', container_code TEXT NOT NULL, -- vendor-supplied super-barcode lading_number TEXT, -- informational note TEXT, @@ -18,11 +19,28 @@ CREATE INDEX acq_asn_container_code_idx ON acq.shipment_notification (container_ CREATE TABLE acq.shipment_notification_entry ( id SERIAL PRIMARY KEY, - shipment_notification INT NOT NULL REFERENCES acq.invoice (id) ON DELETE CASCADE, - lineitem INT REFERENCES acq.lineitem (id) ON UPDATE CASCADE ON DELETE SET NULL, + shipment_notification INT NOT NULL REFERENCES acq.shipment_notification (id) + ON DELETE CASCADE, + lineitem INT REFERENCES acq.lineitem (id) + ON UPDATE CASCADE ON DELETE SET NULL, item_count INT NOT NULL -- How many items the provider shipped ); +/* TODO alter valid_message_type constraint */ + +ALTER TABLE acq.edi_message DROP CONSTRAINT valid_message_type; +ALTER TABLE acq.edi_message ADD CONSTRAINT valid_message_type +CHECK ( + message_type IN ( + 'ORDERS', + 'ORDRSP', + 'INVOIC', + 'OSTENQ', + 'OSTRPT', + 'DESADV' + ) +); + COMMIT; /* UNDO -- 2.11.0