From 85405a2143c4dda5fb5c078a6ee78c5ab6d1b6d8 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 31 Aug 2020 13:02:05 -0400 Subject: [PATCH] Bug 23682: Dedup plugin calls my moving to a single call in process_invoice() Signed-off-by: Jonathan Druart --- Koha/EDI.pm | 24 +++++++++++++++++++++--- acqui/edifactmsgs.pl | 17 +---------------- misc/cronjobs/edi_cron.pl | 20 +------------------- 3 files changed, 23 insertions(+), 38 deletions(-) diff --git a/Koha/EDI.pm b/Koha/EDI.pm index 3b89d4e5f4..ad2691e936 100644 --- a/Koha/EDI.pm +++ b/Koha/EDI.pm @@ -211,12 +211,30 @@ sub process_invoice { my $logger = Log::Log4perl->get_logger(); my $vendor_acct; - my $plugin = $invoice_message->edi_acct()->plugin(); + my $plugin_class = $invoice_message->edi_acct()->plugin(); + + # Plugin has its own invoice processor, only run it and not the standard invoice processor below + if ( $plugin_class ) { + my $plugin = $plugin_class->new(); + if ( $plugin->can('edifact_process_invoice') ) { + Koha::Plugins::Handler->run( + { + class => $plugin_class, + method => 'edifact_process_invoice', + params => { + invoice => $invoice_message, + } + } + ); + return; + } + } + my $edi_plugin; - if ( $plugin ) { + if ( $plugin_class ) { $edi_plugin = Koha::Plugins::Handler->run( { - class => $plugin, + class => $plugin_class, method => 'edifact', params => { invoice_message => $invoice_message, diff --git a/acqui/edifactmsgs.pl b/acqui/edifactmsgs.pl index 3d72404ca6..5aa677072a 100755 --- a/acqui/edifactmsgs.pl +++ b/acqui/edifactmsgs.pl @@ -50,22 +50,7 @@ if ( $cmd && $cmd eq 'delete' ) { if ( $cmd && $cmd eq 'import' ) { my $id = $q->param('message_id'); my $invoice = $schema->resultset('EdifactMessage')->find($id); - - my $plugin_used = 0; - if ( my $plugin_class = $invoice->edi_acct->plugin ) { - $plugin_used = 1; - Koha::Plugins::Handler->run( - { - class => $plugin_class, - method => 'edifact_process_invoice', - params => { - invoice => $invoice, - } - } - ); - } - - process_invoice($invoice) unless $plugin_used; + process_invoice($invoice); } my @msgs = $schema->resultset('EdifactMessage')->search( diff --git a/misc/cronjobs/edi_cron.pl b/misc/cronjobs/edi_cron.pl index b5123d448c..2a3b08f13b 100755 --- a/misc/cronjobs/edi_cron.pl +++ b/misc/cronjobs/edi_cron.pl @@ -132,25 +132,7 @@ if ( C4::Context->preference('EdifactInvoiceImport') eq 'automatic' ) { foreach my $invoice (@downloaded_invoices) { my $filename = $invoice->filename(); $logger->trace("Processing invoice $filename"); - - my $plugin_used = 0; - if ( my $plugin_class = $invoice->edi_acct->plugin ) { - my $plugin = $plugin_class->new(); - if ( $plugin->can('edifact_process_invoice') ) { - $plugin_used = 1; - Koha::Plugins::Handler->run( - { - class => $plugin_class, - method => 'edifact_process_invoice', - params => { - invoice => $invoice, - } - } - ); - } - } - - process_invoice($invoice) unless $plugin_used; + process_invoice($invoice); } } -- 2.11.4.GIT