From f2a5482f492925331b429f198dc28f7f83b7ed24 Mon Sep 17 00:00:00 2001 From: Jon Knight Date: Mon, 14 May 2018 15:30:55 +0000 Subject: [PATCH] Bug 16739: generate edifact showing on basket groups When a book seller (vendor) does not have EDI account information configured the basketgroup display still shows a button to generate EDIFACT output which results in 500 error when clicked. This patch fixes two aspects of this: a) it stops the button being displayed in the first place, replacing it with a message that explains there is not EDIFACT configuration for the vendor. b) if, somehow, an edifact print operation is passed to the basketgroup script it detects the lack of an EAN and redirects back to the basket group display page with a warning message. To test: 1) Create a vendor with no EDI details. 2) Create a basket with some items in, then close it and add it to a basket group for this vendor. 3) Go to that vendor's basket groups, click on the "Closed" tab and then click on the 'generate edifact order' button. You should get a 500 error. 4) Apply this patch. 5) Repeat 3, except this time you should find that the 'generate edifact order' button has been replaced with a note that there is "No EDIFACT configuration for ". Signed-off-by: Martin Renvoize --- acqui/basketgroup.pl | 30 ++++++++++++++++--- .../prog/en/modules/acqui/basketgroup.tt | 17 +++++++---- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index 78514ba2ac..05c505ad54 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -220,8 +220,15 @@ sub generate_edifact_orders { my $baskets = GetBasketsByBasketgroup($basketgroupid); my $ean = get_edifact_ean(); - for my $basket ( @{$baskets} ) { - create_edi_order( { ean => $ean, basketno => $basket->{basketno}, } ); + if($ean) { + for my $basket ( @{$baskets} ) { + create_edi_order( { ean => $ean, basketno => $basket->{basketno}, } ); + } + } else { + my $booksellerid = $input->param('booksellerid') || 0; + print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . + $booksellerid . + '&message=No%20EDIFACT%20Setup'); } return; } @@ -240,6 +247,12 @@ my $op = $input->param('op') || 'display'; # - display : display the list of all basketgroups for a vendor my $booksellerid = $input->param('booksellerid'); $template->param(booksellerid => $booksellerid); +my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); + +my $schema = Koha::Database->new()->schema(); +my $rs = $schema->resultset('VendorEdiAccount')->search( + { vendor_id => $booksellerid, } ); +$template->param( ediaccount => ($rs->count > 0)); if ( $op eq "add" ) { # @@ -391,8 +404,17 @@ if ( $op eq "add" ) { } elsif ( $op eq 'ediprint') { my $basketgroupid = $input->param('basketgroupid'); - generate_edifact_orders( $basketgroupid ); - exit; + if ($template->param( 'ediaccount' )) { + generate_edifact_orders( $basketgroupid ); + exit; + } else { + $template->param('NoEDIMessage' => 1); + my $basketgroups = &GetBasketgroups($booksellerid); + my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); + my $baskets = &GetBasketsByBookseller($booksellerid); + + displaybasketgroups($basketgroups, $bookseller, $baskets); + } }else{ # no param : display the list of all basketgroups for a given vendor my $basketgroups = &GetBasketgroups($booksellerid); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt index 7847ff49c9..6f4ac6d745 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt @@ -144,10 +144,12 @@ function submitForm(form) { [% IF ( grouping ) %] [% IF (closedbg) %] [% END %] [% IF (name && closedbg) %] @@ -295,7 +297,8 @@ function submitForm(form) { -

Basket grouping for [% booksellername | html %]

+

Basket grouping for [% booksellername | html %]

+ [% IF (NoEDIMessage) %]
No EDIFACT configuration for [% booksellername | html %]
[% END %]
    [% UNLESS ( listclosed) %]
  • Open
  • @@ -374,7 +377,11 @@ function submitForm(form) {
    + [% IF (ediaccount) %]
    + [% ELSE %] +
    No EDIFACT configuration for [% booksellername | html %]
    + [% END %] [% END %] -- 2.18.0