Bugzilla – Attachment 35945 Details for
Bug 13707
Adding a new column datereceived for items and biblioitems
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13707 - 2. Adding a new column datereceived for items and biblioitems. Value accessors.
Bug-13707---2-Adding-a-new-column-datereceived-for.patch (text/plain), 11.38 KB, created by
Olli-Antti Kivilahti
on 2015-02-16 15:30:58 UTC
(
hide
)
Description:
Bug 13707 - 2. Adding a new column datereceived for items and biblioitems. Value accessors.
Filename:
MIME Type:
Creator:
Olli-Antti Kivilahti
Created:
2015-02-16 15:30:58 UTC
Size:
11.38 KB
patch
obsolete
>From 1f869ec7c0a358d46e844b1c888d0e4ef0579c98 Mon Sep 17 00:00:00 2001 >From: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> >Date: Fri, 13 Feb 2015 17:02:22 +0200 >Subject: [PATCH] Bug 13707 - 2. Adding a new column datereceived for items > and biblioitems. Value accessors. > >This makes sure that the datereceived-columns are populated, eg the Item and >biblio get the date of receival. >This happens when an Item is added using the cataloguin/additem.pl or the >acqui/finishreceive.pl > >TEST PLAN: (cataloguing) > >1. Add a new Biblio, either via Z39.50 or cataloguing/addbiblio.pl >2. Add an Item for the new Biblio using the cataloguing/additem.pl. This is > the default view you get after saving the Biblio. >3. Observe that the new Item has a datereceived-field with current time as the > timestamp. >4. Observe that the new Biblio has datereceived populated in the field where > you have it mapped to. This defaults to 942$1. > >TEST PLAN: (acquisitions) > >1. Add a new Biblio, either via Z39.50 or cataloguing/addbiblio.pl >2. Add an Item for the new Biblio using the acquisitions workflow. Close the > basketgroup. >3. Receive the Item using the acqui/finishreceive.pl. >4. Observe that the new Item has a datereceived-field with current time as the > timestamp. >5. Observe that the new Biblio has datereceived populated in the field where > you have it mapped to. This defaults to 942$1. > >TEST PLAN: (break it, after any test path) > >10. Receive new Items using both the acquisitions module and the cataloguin > module. >11. Observe that Biblio's datereceived-field (942$1) doesn't change, but > remains as the value set when receiving the first Item. >12. Observe that each Item gets the original timestamp when it has been received. >--- > C4/Biblio.pm | 93 +++++++++++++++++++++++++++++++++++++++++++++++- > C4/Items.pm | 2 ++ > acqui/finishreceive.pl | 2 ++ > cataloguing/additem.pl | 19 ++++++++++ > 4 files changed, 115 insertions(+), 1 deletion(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index d25f311..a357759 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -97,6 +97,7 @@ BEGIN { > &TransformKohaToMarc > &PrepHostMarcField > >+ &UpdateDatereceived > &CountItemsIssued > &CountBiblioInOrders > &GetSubscriptionsId >@@ -2210,6 +2211,95 @@ sub GetFrameworkCode { > return $frameworkcode; > } > >+=head UpdateDatereceived >+ >+ my $error = C4::Biblio::UpdateDatereceived($bibliodataOrBiblionumber, $datereceived, $record); >+ my $error = C4::Biblio::UpdateDatereceived({biblionumber => 1213, datereceived => '2014-12-10 10:12:33', ...}, DateTime, MARC::Record); >+ >+Updates the biblioitems.datereceived and the corresponding MARC-Subfield if the datereceived >+hasn't been set for this Biblio yet. Datereceived for the Biblio is the first moment >+the Biblio became available for the library and shouldn't be updated for subsequent receivals. >+ >+@PARAM1 MANDATORY >+ Integer, koha.biblio.biblionumber >+ OR >+ Hash, Like returned by C4::Biblio::GetBiblioData(). >+ biblionumber must be a hash key! >+ datereceived must be present as well, otherwise the koha.biblioitems.datereceived >+ will be overwritten, unless this is intended. >+@PARAM2 OPTIONAL >+ DateTime-object, of the moment of receival. >+ Defaults to Now() if not given. >+@PARAM3 OPTIONAL >+ MARC::Record, of the biblio to be updated. >+ By default is fetched using the supplied biblionumber. >+@RETURNS String, error code: >+ 'NO_BIBLIODATA', couldn't find the koha.biblioitems-row >+ 'NO_BIBLIONUMBER', no biblionumber given as parameter or couldn't >+ find it from the Hash >+ 'NOT_DATETIME', $datereceived is not a DateTime-object >+ 'NO_RECORD', The given MARC::Record is invalid, or no MARC Record >+ could be found using the supplied biblionumber. >+ 'MODBIBLIO_ERROR', C4::Biblio::ModBiblio() failed. >+ >+=cut >+sub UpdateDatereceived { >+ my ($biblionumberOrBibliodata, $datereceived, $record) = @_; >+ >+ my $bibdata; >+ unless (ref $biblionumberOrBibliodata) { #We have a SCALAR, eg. a biblionumber. >+ my @biblioitems = C4::Biblio::GetBiblioItemByBiblioNumber($biblionumberOrBibliodata); >+ $bibdata = $biblioitems[0]; >+ } >+ else { >+ $bibdata = $biblionumberOrBibliodata; >+ } >+ return 'NO_BIBLIODATA' if (not($bibdata)); >+ return 'NO_BIBLIONUMBER' if (not($bibdata->{biblionumber})); >+ >+ if ($datereceived && ref $datereceived ne 'DateTime') { >+ return 'NOT_DATETIME'; >+ } >+ #Use the given DateTime or Use Now() >+ $datereceived = ($datereceived) ? $datereceived->iso8601() : DateTime->now( time_zone => C4::Context->tz() )->iso8601(); >+ >+ #Make sure to only update the datereceived for the Biblio if it hasn't been set yet. >+ if ($bibdata->{datereceived}) { >+ return undef; #All is OK and we will preserve the first moment of datereceived. >+ } >+ >+ if (not($record)) { >+ $record = C4::Biblio::GetMarcBiblio($bibdata->{biblionumber}); >+ } >+ elsif (ref($record) ne 'MARC::Record') { >+ return 'NO_RECORD'; >+ } >+ return 'NO_RECORD' unless $record; >+ >+ my $frameworkcode = ($bibdata->{frameworkcode}) ? $bibdata->{frameworkcode} : C4::Biblio::GetFrameworkCode($bibdata->{biblionumber}); >+ >+ #Get the mapped MARC-fields for items.datereceived >+ my ( $datereceivedFieldCode, $datereceivedSubfieldCode ) = >+ C4::Biblio::GetMarcFromKohaField( "biblioitems.datereceived", $frameworkcode ); >+ ( $datereceivedFieldCode, $datereceivedSubfieldCode ) = >+ C4::Biblio::GetMarcFromKohaField( "biblioitems.datereceived", '' ) unless ($datereceivedFieldCode); >+ >+ #UPSERT the datereceived DB column to MARC >+ my @existingFields = $record->field($datereceivedFieldCode); >+ if ($existingFields[0]) { >+ $existingFields[0]->update($datereceivedSubfieldCode => $datereceived); >+ } >+ else { >+ my $newField = MARC::Field->new($datereceivedFieldCode, '', '', $datereceivedSubfieldCode => $datereceived); >+ $record->insert_fields_ordered($newField); >+ } >+ >+ my $ok = C4::Biblio::ModBiblio($record, $bibdata->{biblionumber}, $frameworkcode); >+ return 'MODBIBLIO_ERROR' unless $ok; >+ return undef; #All is OK! >+} >+ >+ > =head2 TransformKohaToMarc > > $record = TransformKohaToMarc( $hash ) >@@ -3255,6 +3345,7 @@ sub _koha_modify_biblioitem_nonmarc { > issn = ?, > publicationyear = ?, > publishercode = ?, >+ datereceived = ?, > volumedate = ?, > volumedesc = ?, > collectiontitle = ?, >@@ -3282,7 +3373,7 @@ sub _koha_modify_biblioitem_nonmarc { > my $sth = $dbh->prepare($query); > $sth->execute( > $biblioitem->{'biblionumber'}, $biblioitem->{'volume'}, $biblioitem->{'number'}, $biblioitem->{'itemtype'}, >- $biblioitem->{'isbn'}, $biblioitem->{'issn'}, $biblioitem->{'publicationyear'}, $biblioitem->{'publishercode'}, >+ $biblioitem->{'isbn'}, $biblioitem->{'issn'}, $biblioitem->{'publicationyear'}, $biblioitem->{'publishercode'}, $biblioitem->{datereceived}, > $biblioitem->{'volumedate'}, $biblioitem->{'volumedesc'}, $biblioitem->{'collectiontitle'}, $biblioitem->{'collectionissn'}, > $biblioitem->{'collectionvolume'}, $biblioitem->{'editionstatement'}, $biblioitem->{'editionresponsibility'}, $biblioitem->{'illus'}, > $biblioitem->{'pages'}, $biblioitem->{'bnotes'}, $biblioitem->{'size'}, $biblioitem->{'place'}, >diff --git a/C4/Items.pm b/C4/Items.pm >index a225b49..c2c27f8 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -2131,6 +2131,7 @@ sub _koha_new_item { > biblioitemnumber = ?, > barcode = ?, > dateaccessioned = ?, >+ datereceived = ?, > booksellerid = ?, > homebranch = ?, > price = ?, >@@ -2173,6 +2174,7 @@ sub _koha_new_item { > $item->{'biblioitemnumber'}, > $barcode, > $item->{'dateaccessioned'}, >+ $item->{'datereceived'}, > $item->{'booksellerid'}, > $item->{'homebranch'}, > $item->{'price'}, >diff --git a/acqui/finishreceive.pl b/acqui/finishreceive.pl >index 286474f..ab89bfa 100755 >--- a/acqui/finishreceive.pl >+++ b/acqui/finishreceive.pl >@@ -165,9 +165,11 @@ ModItem( > price => $unitprice, > replacementprice => $rrp, > replacementpricedate => $datereceived, >+ datereceived => DateTime->now( time_zone => C4::Context->tz() )->iso8601(), > }, > $biblionumber, > $_ > ) foreach GetItemnumbersFromOrder($new_ordernumber); >+C4::Biblio::UpdateDatereceived($biblionumber); > > print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid&sticky_filters=1"); >diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl >index 9c7fb3f..8ec6193 100755 >--- a/cataloguing/additem.pl >+++ b/cataloguing/additem.pl >@@ -451,6 +451,8 @@ if ($op eq "additem") { > unless ($exist_itemnumber) { > my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber ); > set_item_default_location($oldbibitemnum); >+ my $err = C4::Biblio::UpdateDatereceived($biblionumber); >+ push @errors, $err if $err; > > # Pushing the last created item cookie back > if ($prefillitem && defined $record) { >@@ -824,6 +826,13 @@ if($itemrecord){ > } > # and now we add fields that are empty > >+##Populate datereceived for new Items present in our library. >+#Get the mapped MARC-fields for items.datereceived >+my ( $datereceivedFieldCode, $datereceivedSubfieldCode ) = >+ C4::Biblio::GetMarcFromKohaField( "items.datereceived", $frameworkcode ); >+( $datereceivedFieldCode, $datereceivedSubfieldCode ) = >+ C4::Biblio::GetMarcFromKohaField( "items.datereceived", '' ) unless ($datereceivedFieldCode); >+ > # Using last created item if it exists > > $itemrecord = $cookieitemrecord if ($prefillitem and not $justaddeditem and $op ne "edititem"); >@@ -838,6 +847,7 @@ foreach my $tag ( keys %{$tagslib}){ > my @values = (undef); > @values = $itemrecord->field($tag)->subfield($subtag) if ($itemrecord && defined($itemrecord->field($tag)) && defined($itemrecord->field($tag)->subfield($subtag))); > for my $value (@values){ >+ $value = enforceDatereceived($tag, $subtag, $value); > my $subfield_data = generate_subfield_form($tag, $subtag, $value, $tagslib, $tagslib->{$tag}->{$subtag}, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i, $restrictededition); > push (@loop_data, $subfield_data); > $i++; >@@ -881,3 +891,12 @@ foreach my $error (@errors) { > $template->param($error => 1); > } > output_html_with_http_headers $input, $cookie, $template->output; >+ >+sub enforceDatereceived { >+ my ($tag, $subtag, $value) = @_; >+ #Set the datereceived as now() if it is not defined, or it's not a timestamp. >+ if ($tag eq $datereceivedFieldCode && $subtag eq $datereceivedSubfieldCode && (not($value) || not($value =~ /^\d\d\d\d-\d\d-\d\d/))) { >+ $value = DateTime->now( time_zone => C4::Context->tz() )->iso8601(); >+ } >+ return $value; >+} >\ No newline at end of file >-- >1.7.9.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 13707
:
35908
|
35909
|
35910
|
35917
|
35933
|
35944
|
35945
|
35946
|
35966
|
35967
|
35968
|
35970
|
42391
|
42394
|
64343
|
64344