$mgr->respond;
}
+ # tell the world we activated a PO
+ $U->create_events_for_hook('acqpo.activate', $po, $po->ordering_agency);
+
return undef;
}
--- /dev/null
+package OpenILS::Application::Trigger::Reactor::GeneratePurchaseOrderJEDI;
+use base 'OpenILS::Application::Trigger::Reactor';
+use strict; use warnings;
+use OpenSRF::Utils::Logger qw/:logger/;
+
+sub ABOUT {
+ return <<ABOUT;
+
+Generates PO JEDI (JSON EDI) output for subsequent processing and EDI delivery
+
+ABOUT
+}
+
+sub handler {
+ my $self = shift;
+ my $env = shift;
+ return 1 if $self->run_TT($env);
+ return 0;
+}
+
+1;
+
--- /dev/null
+package OpenILS::Application::Trigger::Validator::Acq::PurchaseOrderEDIRequired;
+use strict; use warnings;
+use OpenSRF::Utils::Logger qw/:logger/;
+use OpenILS::Application::AppUtils;
+my $U = 'OpenILS::Application::AppUtils';
+
+sub handler {
+ my $self = shift;
+ my $env = shift;
+ my $po = $env->{target};
+
+ my $provider =
+ ref($po->provider) ?
+ $po->provider :
+ $self->editor->retrieve_acq_provider($po->provider);
+
+ return 1 if
+ $po->state eq 'on-order' and
+ $provider->edi_default and
+ $U->is_true($provider->active);
+
+ return 0;
+}
+
+1;
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0259'); -- Scott McKellar
+INSERT INTO config.upgrade_log (version) VALUES ('0260'); -- berick
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES ('penalty.PATRON_EXCEEDS_OVERDUE_COUNT','ausp','Patron has exceeded allowed overdue count',TRUE);
INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES ('penalty.PATRON_EXCEEDS_CHECKOUT_COUNT','ausp','Patron has exceeded allowed checkout count',TRUE);
INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES ('penalty.PATRON_EXCEEDS_COLLECTIONS_WARNING','ausp','Patron has exceeded maximum fine amount for collections department warning',TRUE);
-INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES ('format.po.jedi','acqpo','Formats a Purchase Order as a JEDI document',TRUE);
+INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES ('acqpo.activated','acqpo','Purchase order was activated',FALSE);
INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES ('format.po.html','acqpo','Formats a Purchase Order as an HTML document',TRUE);
INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES ('format.po.pdf','acqpo','Formats a Purchase Order as a PDF document',TRUE);
INSERT INTO action_trigger.hook (key,core_type,description) VALUES ('damaged','acp','Item marked damaged');
INSERT INTO action_trigger.environment ( event_def, path) VALUES
( 13, 'open_billable_transactions_summary.circulation' );
-INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, cleanup_success, cleanup_failure, delay, delay_field, group_field, template) VALUES (23, true, 1, 'PO JEDI', 'format.po.jedi', 'NOOP_True', 'ProcessTemplate', NULL, NULL, '00:05:00', NULL, NULL,
+
+INSERT INTO action_trigger.validator (module, description)
+ VALUES (
+ 'Acq::PurchaseOrderEDIRequired',
+ oils_i18n_gettext(
+ 'Acq::PurchaseOrderEDIRequired',
+ 'Purchase order is delivered via EDI',
+ 'atval',
+ 'description'
+ )
+ );
+
+INSERT INTO action_trigger.reactor (module, description)
+ VALUES (
+ 'GeneratePurchaseOrderJEDI',
+ oils_i18n_gettext(
+ 'GeneratePurchaseOrderJEDI',
+ 'Creates purchase order JEDI (JSON EDI) for subsequent EDI processing',
+ 'atreact',
+ 'description'
+ )
+ );
+
+
+INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, cleanup_success, cleanup_failure, delay, delay_field, group_field, template)
+ VALUES (23, true, 1, 'PO JEDI', 'acqpo.activated', 'Acq::PurchaseOrderEDIRequired', 'GeneratePurchaseOrderJEDI', NULL, NULL, '00:05:00', NULL, NULL,
$$[%- USE date -%]
[%# start JEDI document -%]
[%- BLOCK big_block -%]
--- /dev/null
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0260');
+
+INSERT INTO action_trigger.validator (module, description)
+ VALUES (
+ 'Acq::PurchaseOrderEDIRequired',
+ oils_i18n_gettext(
+ 'Acq::PurchaseOrderEDIRequired',
+ 'Purchase order is delivered via EDI',
+ 'atval',
+ 'description'
+ )
+ );
+
+INSERT INTO action_trigger.reactor (module, description)
+ VALUES (
+ 'GeneratePurchaseOrderJEDI',
+ oils_i18n_gettext(
+ 'GeneratePurchaseOrderJEDI',
+ 'Creates purchase order JEDI (JSON EDI) for subsequent EDI processing',
+ 'atreact',
+ 'description'
+ )
+ );
+
+UPDATE action_trigger.hook
+ SET
+ key = 'acqpo.activated',
+ passive = FALSE,
+ description = oils_i18n_gettext(
+ 'acqpo.activated',
+ 'Purchase order was activated',
+ 'ath',
+ 'description'
+ )
+ WHERE key = 'format.po.jedi';
+
+UPDATE action_trigger.event_definition
+ SET
+ hook = 'acqpo.activated',
+ validator = 'Acq::PurchaseOrderEDIRequired',
+ reactor = 'GeneratePurchaseOrderJEDI'
+ WHERE id = 23;
+
+COMMIT;
+
my %opts = (
'quiet' => 0,
+ 'max-batch-size=i' => -1
);
-OpenILS::Utils::Cronscript->new()->session('open-ils.acq') or die "No session created";
+my $cs = OpenILS::Utils::Cronscript->new(\%opts);
+$cs->session('open-ils.acq') or die "No session created";
+
OpenILS::Utils::CStoreEditor::init();
sub editor {
}
my $e = editor();
-my $hook = 'format.po.jedi';
-my $defs = $e->search_action_trigger_event_definition({hook => $hook});
+my $hook = 'acqpo.activated';
+my $defs = $e->search_action_trigger_event_definition({
+ hook => $hook,
+ reactor => 'GeneratePurchaseOrderJEDI',
+ active => 't'
+});
+
# print Dumper($defs);
print "\nHook '$hook' is used in ", scalar(@$defs), " event definition(s):\n";
$Data::Dumper::Indent = 1;
+my $remaining = $cs->first_defined('max-batch-size');
foreach my $def (@$defs) {
+ last if $remaining == 0;
printf "%3s - '%s'\n", $def->id, $def->name;
- my $events = $e->search_action_trigger_event([
- {event_def => $def->id},
- {flesh => 1, flesh_fields => { atev => ['template_output'] }}
- ]);
+
+ # give me all completed JEDI events that link to purchase_orders
+ # that have not already been delivered to the vendor
+ my $query = {
+ select => {atev => ['id']},
+ from => 'atev',
+ where => {
+ event_def => $def->id,
+ state => 'complete',
+ target => {
+ in => {
+ select => {acqpo => ['id']},
+ from => 'acqpo',
+ where => {
+ id => {
+ 'not in' => {
+ select => {acqedim => ['purchase_order']},
+ from => 'acqedim',
+ where => {purchase_order => {'!=' => undef}}
+ }
+ }
+ }
+ }
+ }
+ },
+ order_by => {atev => 'add_time'}
+ };
+
+ $query->{limit} = $remaining if $remaining > 0;
+
+ my $events = $e->json_query($query);
+ $remaining -= scalar(@$events);
+
print "Event definition ", $def->id, " has ", scalar(@$events), " event(s)\n";
foreach (@$events) {
+ my $event = $e->retrieve_action_trigger_event($_);
my $message = Fieldmapper::acq::edi_message->new;
$message->create_time('NOW'); # will need this later when we try to update from the object
- print "Event ", $_->id, " targets PO ", $_->target, ":\n"; # target is an opaque identifier, so we cannot flesh it
- print Dumper($_), "\n";
+ print "Event ", $event->id, " targets PO ", $event->target, ":\n"; # target is an opaque identifier, so we cannot flesh it
+ print Dumper($event), "\n";
my $target = $e->retrieve_acq_purchase_order([ # instead we retrieve it separately
- $_->target, {
+ $event->target, {
flesh => 2,
flesh_fields => {
acqpo => ['provider'],
}
]);
+ $message->purchase_order($target->id);
+
$debug and print "Target: ", Dumper($target), "\n";
my $logstr = sprintf "provider %s (%s)", $target->provider->id, $target->provider->name;
unless ($target->provider->edi_default and $message->account($target->provider->edi_default->id)) {
printf STDERR "ERROR: No edi_default account found for $logstr. File will not be sent!\n";
}
- $message->jedi($_->template_output()->data);
+ $message->jedi($event->template_output()->data);
print "\ntarget->provider->edi_default->id: ", $target->provider->edi_default->id, "\n";
print "\nNow calling attempt_translation\n\n";
unless (OpenILS::Application::Acq::EDI->attempt_translation($message, 1)) {