From 6a1d16817dd7f8a976cbcd48129fedc0a0a4ed07 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. --- Koha/Acquisition/Basket.pm | 17 +++++++++++++++++ acqui/basket.pl | 4 ++++ .../prog/en/modules/acqui/basket.tt | 7 +++++++ 3 files changed, 28 insertions(+) diff --git a/Koha/Acquisition/Basket.pm b/Koha/Acquisition/Basket.pm index 4f10557901..cd9b3359d2 100644 --- a/Koha/Acquisition/Basket.pm +++ b/Koha/Acquisition/Basket.pm @@ -96,6 +96,23 @@ 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. + +=cut + +sub edi_order { + my ($self) = @_; + + my $order_rs = + $self->_result->edifact_messages( { message_type => 'ORDERS' }, + { 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 09545ee3cc..f82050677f 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -380,6 +380,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, @@ -391,6 +394,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..b905f4e303 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,13 @@ [% IF ( closedate ) %]
  • Closed on: [% closedate | $KohaDates %]
  • [% END %] + [% IF ( ediaccount ) %] + [% IF ( edi_order && !edi_order.deleted ) %] +
  • EDI status: [% edi_order.status | html %] ([% edi_order.transfer_date | $KohaDates %])
  • + [% ELSE %] +
  • EDI status: Not ordered
  • + [% END %] + [% END %] [% IF ( estimateddeliverydate ) %]
  • Estimated delivery date: [% estimateddeliverydate | $KohaDates %]
  • [% END %] -- 2.20.1