From 33dd62d66110e498236903a65f8aa7f5946a2ee3 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 30 Jun 2021 12:37:59 +0100 Subject: [PATCH] Bug 28640: Expose EDI Status on basket details page This patch adds the edi_order relationship method to Koha::Acquisition::Basket to return the most recently attached edi_message of type 'ORDER' for the basket. NOTE: EDI currently returns raw DBIC results. I have opted to maintain that approach here, but would like to work on upgradeing the Koha::EDIFACT::Order class to be a subclass of Koha::Object at a later date. We then use this new relationship in acqui/basket to display the EDI status for such baskets. Test plan 1/ Setup a vendor with EDI Ordering enabled 2/ Add a new basket for the vendor. 3/ Note the new 'EDI status' field displays and reads 'Not ordered' 4/ Close the basker 5/ The 'EDI status' should continue to display 'Not ordered' 6/ Re-open the basket 7/ Close the basket via 'Create EDIFACT order' 8/ Navigate back to the now closed basket 9/ Note the 'EDI status' field now displays 'Pending' and the transfer date. 10/ Progress the EDI order by running the edi_cron.pl script 11/ The EDI status field should now reflect that the message has been sent. Signed-off-by: Benjamin Veasey Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- Koha/Acquisition/Basket.pm | 24 +++++++++++++++++++ acqui/basket.pl | 4 ++++ .../prog/en/modules/acqui/basket.tt | 14 +++++++++++ 3 files changed, 42 insertions(+) diff --git a/Koha/Acquisition/Basket.pm b/Koha/Acquisition/Basket.pm index 6717f5f9d4..556fa326b0 100644 --- a/Koha/Acquisition/Basket.pm +++ b/Koha/Acquisition/Basket.pm @@ -96,6 +96,30 @@ sub orders { return Koha::Acquisition::Orders->_new_from_dbic( $orders_rs ); } +=head3 edi_order + + my $edi_order = $basket->edi_order; + +Returns the most recently attached EDI order object if one exists for the basket. + +NOTE: This currently returns a bare DBIx::Class result or undefined. This is consistent with the rest of EDI; +However it would be beneficial to convert these to full fledge Koha::Objects in the future. + +=cut + +sub edi_order { + my ($self) = @_; + + my $order_rs = $self->_result->edifact_messages( + { + message_type => 'ORDERS', + deleted => 0 + }, + { order_by => { '-desc' => 'transfer_date' }, rows => 1 } + ); + return $order_rs->single; +} + =head3 effective_create_items Returns C for this basket, falling back to C if unset. diff --git a/acqui/basket.pl b/acqui/basket.pl index fbf730c3dd..ac09913920 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -377,6 +377,9 @@ if ( $op eq 'list' ) { last; } + my $basket_obj = Koha::Acquisition::Baskets->find($basketno); + my $edi_order = $basket_obj->edi_order; + $template->param( basketno => $basketno, basket => $basket, @@ -388,6 +391,7 @@ if ( $op eq 'list' ) { basketcontractname => $contract->{contractname}, branches_loop => \@branches_loop, creationdate => $basket->{creationdate}, + edi_order => $edi_order, authorisedby => $basket->{authorisedby}, authorisedbyname => $basket->{authorisedbyname}, users_ids => join(':', @basketusers_ids), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt index dce2567228..a63dd515e3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt @@ -314,6 +314,20 @@ [% IF ( closedate ) %]
  • Closed on: [% closedate | $KohaDates %]
  • [% END %] + [% IF ( ediaccount ) %] + [%- BLOCK edi_status -%] + [%- SWITCH edi_order.status -%] + [%- CASE 'Pending' -%]Pending + [%- CASE 'Sent' -%]Sent + [%- CASE 'Processed' -%]Processed + [%- END -%] + [%- END -%] + [% IF ( edi_order ) %] +
  • EDI status: [%- PROCESS edi_status edi_order=edi_order -%] ([% edi_order.transfer_date | $KohaDates %])
  • + [% ELSE %] +
  • EDI status: Not ordered
  • + [% END %] + [% END %] [% IF ( estimateddeliverydate ) %]
  • Estimated delivery date: [% estimateddeliverydate | $KohaDates %]
  • [% END %] -- 2.39.5