From 7df4d627bee453d7c68fd504a88fbd3fa0f2e3fe Mon Sep 17 00:00:00 2001 From: Lyon3 Team Date: Thu, 10 Apr 2014 17:52:37 +0200 Subject: [PATCH] Bug 12074 Filter duplicates when adding a batch from a staged file When adding a batch of records to a basket, duplicates are skipped and an alert is displayed with a link to them so as they could be treated individually. --- acqui/addorderiso2709.pl | 13 +++++++++++-- acqui/basket.pl | 3 ++- .../prog/en/modules/acqui/addorderiso2709.tt | 8 +++++++- .../intranet-tmpl/prog/en/modules/acqui/basket.tt | 4 ++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index e56bd06..ca34923 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -58,6 +58,7 @@ my ($template, $loggedinuser, $cookie, $userflags) = get_template_and_user({ my $cgiparams = $input->Vars; my $op = $cgiparams->{'op'}; my $booksellerid = $input->param('booksellerid'); +my $allmatch = $input->param('allmatch'); my $bookseller = GetBookSellerFromId($booksellerid); my $data; @@ -122,6 +123,7 @@ if ($op eq ""){ $template->param("batch_details" => 1, "basketno" => $cgiparams->{'basketno'}, loop_currencies => \@loop_currency, + "allmatch" => $allmatch, ); import_biblios_list($template, $cgiparams->{'import_batch_id'}); if ( C4::Context->preference('AcqCreateItem') eq 'ordering' && !$ordernumber ) { @@ -157,14 +159,16 @@ if ($op eq ""){ # retrieve the file you want to import my $import_batch_id = $cgiparams->{'import_batch_id'}; my $biblios = GetImportRecordsRange($import_batch_id); + my $duplinbatch; + my $imported = 0; for my $biblio (@$biblios){ # 1st insert the biblio, or find it through matcher my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} ); my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information"; my $match = GetImportRecordMatches( $biblio->{'import_record_id'}, 1 ); my $biblionumber=$#$match > -1?$match->[0]->{'biblionumber'}:0; - unless ( $biblionumber ) { + $duplinbatch=$import_batch_id and next if FindDuplicate($marcrecord); # add the biblio my $bibitemnum; @@ -261,9 +265,14 @@ if ($op eq ""){ } else { SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' ); } + $imported++; } # go to basket page - print $input->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=".$cgiparams->{'basketno'}); + if ( $imported ) { + print $input->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=".$cgiparams->{'basketno'}."&duplinbatch=$duplinbatch"); + } else { + print $input->redirect("/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=$import_batch_id&basketno=".$cgiparams->{'basketno'}."&booksellerid=$booksellerid&allmatch=1"); + } exit; } diff --git a/acqui/basket.pl b/acqui/basket.pl index 047ae84..64f6125 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -68,7 +68,7 @@ the supplier this script have to display the basket. my $query = new CGI; our $basketno = $query->param('basketno'); my $booksellerid = $query->param('booksellerid'); - +my $duplinbatch = $query->param('duplinbatch'); my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( { template_name => "acqui/basket.tmpl", @@ -429,6 +429,7 @@ if ( $op eq 'delete_confirm' ) { grouped => $basket->{basketgroupid}, unclosable => @orders ? 0 : 1, has_budgets => $has_budgets, + duplinbatch => $duplinbatch, ); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt index 44d2bb8..caf921d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt @@ -52,6 +52,12 @@
+ [% IF ( allmatch ) %]
+

No records imported

+ No record have been imported because they all match an existing record in the database.
You'll have to treat them individually. +
+ [% END %] + [% IF ( batch_details ) %]

Add orders from [% comments %] ([% file_name %] staged on [% upload_timestamp | $KohaDates with_hours => 1 %]) @@ -149,7 +155,7 @@

[% END %]
- [% IF ( import_batch_id ) %] + [% IF ( import_batch_id && ! allmatch ) %]

Import all

Import all the lines in the basket with the following parameters:

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 cd31176..ca26c9b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt @@ -393,6 +393,10 @@
[% END %] + [% IF ( duplinbatch ) %]
+

Duplicate warning

+

Some records have not been automatically added because they match an existing record in your catalog:

+
[% END %] [% UNLESS ( delete_confirm ) %]
-- 1.7.2.5