From b212995f7568db0bdcd354a00401597202fc4e67 Mon Sep 17 00:00:00 2001
From: Jonathan Druart
Date: Wed, 10 May 2023 15:18:15 +0200
Subject: [PATCH] Bug 28844: Add link between suggestions and orders
---
Koha/Acquisition/Order.pm | 19 ++++++++
acqui/addorder.pl | 1 +
acqui/basket.pl | 6 ---
acqui/orderreceive.pl | 6 ---
acqui/parcel.pl | 6 +--
api/v1/swagger/definitions/order.yaml | 9 ++++
api/v1/swagger/paths/acquisitions_orders.yaml | 6 ++-
.../prog/en/modules/acqui/basket.tt | 8 ++--
.../prog/en/modules/acqui/orderreceive.tt | 4 +-
.../prog/en/modules/acqui/parcel.tt | 48 +++++++++----------
t/db_dependent/Koha/Acquisition/Order.t | 31 +++++++++++-
11 files changed, 96 insertions(+), 48 deletions(-)
diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm
index a365f3163ab..2bdc0d0b84d 100644
--- a/Koha/Acquisition/Order.pm
+++ b/Koha/Acquisition/Order.pm
@@ -283,6 +283,24 @@ sub subscription {
return Koha::Subscription->_new_from_dbic( $subscription_rs );
}
+=head3 suggestion
+
+ my $suggestion = $order->suggestion
+
+Returns the I object for the suggestion associated
+to the order.
+
+It returns B if no linked suggestion is found.
+
+=cut
+
+sub suggestion {
+ my ( $self ) = @_;
+ my $rs = $self->_result->suggestion;
+ return unless $rs;
+ return Koha::Suggestion->_new_from_dbic( $rs );
+}
+
=head3 current_item_level_holds
my $holds = $order->current_item_level_holds;
@@ -628,6 +646,7 @@ sub to_api_mapping {
sort2 => 'statistics_2',
sort2_authcat => 'statistics_2_authcat',
subscriptionid => 'subscription_id',
+ suggestionid => 'suggestion_id',
suppliers_reference_number => undef, # EDIFACT related
suppliers_reference_qualifier => undef, # EDIFACT related
suppliers_report => undef, # EDIFACT related
diff --git a/acqui/addorder.pl b/acqui/addorder.pl
index 25fd4b3109d..2b40192faeb 100755
--- a/acqui/addorder.pl
+++ b/acqui/addorder.pl
@@ -259,6 +259,7 @@ my $orderinfo = {
sort2 => scalar $input->param('sort2'),
subscriptionid => scalar $input->param('subscriptionid'),
estimated_delivery_date => scalar $input->param('estimated_delivery_date'),
+ suggestionid => scalar $input->param('suggestionid'),
};
$orderinfo->{uncertainprice} ||= 0;
diff --git a/acqui/basket.pl b/acqui/basket.pl
index 80c633cf56a..899b7d4cf28 100755
--- a/acqui/basket.pl
+++ b/acqui/basket.pl
@@ -27,7 +27,6 @@ use CGI qw ( -utf8 );
use C4::Acquisition qw( GetBasket CanUserManageBasket GetBasketAsCSV NewBasket NewBasketgroup ModBasket ReopenBasket ModBasketUsers GetBasketgroup GetBasketgroups GetBasketUsers GetOrders GetOrder get_rounded_price );
use C4::Budgets qw( GetBudgetHierarchy GetBudget CanUserUseBudget );
use C4::Contract qw( GetContract );
-use C4::Suggestions qw( GetSuggestion GetSuggestionInfoFromBiblionumber GetSuggestionInfo );
use Koha::Biblios;
use Koha::Acquisition::Baskets;
use Koha::Acquisition::Booksellers;
@@ -496,11 +495,6 @@ sub get_order_infos {
$line{order_object} = $order;
}
- my $suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber});
- $line{suggestionid} = $$suggestion{suggestionid};
- $line{surnamesuggestedby} = $$suggestion{surnamesuggestedby};
- $line{firstnamesuggestedby} = $$suggestion{firstnamesuggestedby};
-
$line{estimated_delivery_date} = $order->{estimated_delivery_date};
foreach my $key (qw(transferred_from transferred_to)) {
diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl
index 17c7280ea37..c49ff5482b9 100755
--- a/acqui/orderreceive.pl
+++ b/acqui/orderreceive.pl
@@ -68,7 +68,6 @@ use C4::Output qw( output_html_with_http_headers );
use C4::Budgets qw( GetBudget GetBudgetPeriods GetBudgetPeriod GetBudgetHierarchy CanUserUseBudget );
use C4::Members;
use C4::Biblio qw( GetMarcStructure );
-use C4::Suggestions qw( GetSuggestion GetSuggestionInfoFromBiblionumber GetSuggestionInfo );
use Koha::Acquisition::Booksellers;
use Koha::Acquisition::Currencies qw( get_active );
@@ -164,11 +163,6 @@ $template->param(
gst_values => \@gst_values,
);
-my $suggestion = GetSuggestionInfoFromBiblionumber($order->biblionumber);
-if ( $suggestion ) {
- $template->param( suggestion => $suggestion );
-}
-
my $patron = Koha::Patrons->find( $loggedinuser )->unblessed;
my %budget_loops;
my $budgets = GetBudgetHierarchy( undef, undef, undef, 1 );
diff --git a/acqui/parcel.pl b/acqui/parcel.pl
index 06172690f68..ed3ca1a8fee 100755
--- a/acqui/parcel.pl
+++ b/acqui/parcel.pl
@@ -61,7 +61,6 @@ use C4::Acquisition qw( CancelReceipt GetInvoice GetInvoiceDetails get_rounded_p
use C4::Budgets qw( GetBudget GetBudgetByOrderNumber GetBudgetName );
use CGI qw ( -utf8 );
use C4::Output qw( output_html_with_http_headers );
-use C4::Suggestions qw( GetSuggestion GetSuggestionInfoFromBiblionumber GetSuggestionInfo );
use Koha::Acquisition::Baskets;
use Koha::Acquisition::Bookseller;
@@ -149,10 +148,7 @@ for my $order ( @orders ) {
$total_tax_excluded += get_rounded_price($line{unitprice_tax_excluded}) * $line{quantity};
$total_tax_included += get_rounded_price($line{unitprice_tax_included}) * $line{quantity};
- my $suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber});
- $line{suggestionid} = $suggestion->{suggestionid};
- $line{surnamesuggestedby} = $suggestion->{surnamesuggestedby};
- $line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby};
+ $line{order_object} = $order_object;
if ( $line{parent_ordernumber} != $line{ordernumber} ) {
if ( grep { $_->{ordernumber} == $line{parent_ordernumber} }
diff --git a/api/v1/swagger/definitions/order.yaml b/api/v1/swagger/definitions/order.yaml
index 2b53ad12dd8..c91caa529e8 100644
--- a/api/v1/swagger/definitions/order.yaml
+++ b/api/v1/swagger/definitions/order.yaml
@@ -204,6 +204,11 @@ properties:
- integer
- "null"
description: Subscription ID linking the order to a subscription
+ suggestion_id:
+ type:
+ - integer
+ - "null"
+ description: Suggestion ID linking the order to a suggestion
parent_order_id:
type:
- integer
@@ -259,4 +264,8 @@ properties:
type:
- object
- "null"
+ suggestion:
+ type:
+ - object
+ - "null"
additionalProperties: false
diff --git a/api/v1/swagger/paths/acquisitions_orders.yaml b/api/v1/swagger/paths/acquisitions_orders.yaml
index 3f3d5e4a935..27339ef3de7 100644
--- a/api/v1/swagger/paths/acquisitions_orders.yaml
+++ b/api/v1/swagger/paths/acquisitions_orders.yaml
@@ -58,13 +58,14 @@
- biblio.active_orders+count
- biblio.holds+count
- biblio.items+count
- - biblio.suggestions.suggester
- fund
- current_item_level_holds+count
- invoice
- items
- items+strings
- subscription
+ - suggestion
+ - suggestion.suggester
collectionFormat: csv
responses:
"200":
@@ -175,12 +176,13 @@
- biblio.active_orders+count
- biblio.holds+count
- biblio.items+count
- - biblio.suggestions.suggester
- fund
- current_item_level_holds+count
- invoice
- items
- subscription
+ - suggestion
+ - suggestion.suggester
collectionFormat: csv
produces:
- application/json
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 e7d4cbfaa03..17713c1c1ea 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
@@ -566,10 +566,12 @@
[%- IF ( books_loo.publicationyear ) %], [% books_loo.publicationyear | html -%]
[%- ELSIF ( books_loo.copyrightdate ) %] [% books_loo.copyrightdate | html %][% END -%]
[%- IF ( books_loo.editionstatement ) %], [% books_loo.editionstatement | html %][% END -%]
- [%- IF ( books_loo.suggestionid ) %]
+ [% SET suggestion = books_loo.order_object.suggestion %]
+ [% IF suggestion %]
- Suggested by: [% books_loo.surnamesuggestedby | html %][% IF ( books_loo.firstnamesuggestedby ) %], [% books_loo.firstnamesuggestedby | html %] [% END %]
- (suggestion #[% books_loo.suggestionid | html %])
+ [% SET suggester = suggestion.suggester %]
+ Suggested by: [% suggester.surname | html %][% IF suggester.firstname %] %], [% suggester.firstname | html %] [% END %]
+ (suggestion #[% suggestion.suggestionid | html %])
[% END %]
[% IF ( books_loo.order_internalnote ) %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt
index 05dd6915205..f2aa80de62b 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt
@@ -67,13 +67,15 @@
+ [% SET suggestion = order.suggestion %]
[% IF suggestion %]