From 43b6644818f71c2d3c4bf09c6c40b36f5c0522c2 Mon Sep 17 00:00:00 2001 From: Jon Knight Date: Mon, 14 May 2018 15:30:55 +0000 Subject: [PATCH] Bug 16739: Show note instead of 500 error for 'Generate EDIFACT' when no EDI account is configured 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 Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens (cherry picked from commit 121b8105bcb00909b1e8081442148c1939c101a6) Signed-off-by: Martin Renvoize --- acqui/basketgroup.pl | 30 ++++++++++++++++--- .../prog/en/modules/acqui/basketgroup.tt | 27 ++++++++++------- 2 files changed, 43 insertions(+), 14 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 dab44d89b6..aa2853bee3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt @@ -143,10 +143,12 @@ function submitForm(form) { [% IF ( grouping ) %] [% IF (closedbg) %] [% END %] [% IF (name && closedbg) %] @@ -290,7 +292,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
  • @@ -365,11 +368,15 @@ function submitForm(form) { [% IF (basketgroup.freedeliveryplace) %]Free delivery place[% ELSE %][% Branches.GetName( basketgroup.deliveryplace ) %][% END %] [% basketgroup.basketsqty %] -
    -
    -
    -
    -
    +
    +
    +
    +
    + [% IF (ediaccount) %] +
    + [% ELSE %] +
    No EDIFACT configuration for [% booksellername | html %]
    + [% END %] [% END %] -- 2.39.5