Bug 23682: Dedup plugin calls my moving to a single call in process_invoice()
authorKyle M Hall <kyle@bywatersolutions.com>
Mon, 31 Aug 2020 17:02:05 +0000 (13:02 -0400)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 3 Sep 2020 13:00:48 +0000 (15:00 +0200)
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/EDI.pm
acqui/edifactmsgs.pl
misc/cronjobs/edi_cron.pl

index 3b89d4e..ad2691e 100644 (file)
@@ -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,
index 3d72404..5aa6770 100755 (executable)
@@ -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(
index b5123d4..2a3b08f 100755 (executable)
@@ -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);
     }
 }