Bugzilla – Attachment 128785 Details for
Bug 20817
Add ability to retain 9xx fields when adding on order item to existing record
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20817: Add ability to retain 9xx fields when adding on order item to existing record
Bug-20817-Add-ability-to-retain-9xx-fields-when-ad.patch (text/plain), 16.67 KB, created by
Andrew Fuerste-Henry
on 2021-12-20 18:47:52 UTC
(
hide
)
Description:
Bug 20817: Add ability to retain 9xx fields when adding on order item to existing record
Filename:
MIME Type:
Creator:
Andrew Fuerste-Henry
Created:
2021-12-20 18:47:52 UTC
Size:
16.67 KB
patch
obsolete
>From 168bfd821d55fbcf87bee68bf035f9fb1224327a Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Nazl=C4=B1=20=C3=87etin?= <nazli@devinim.com.tr> >Date: Mon, 18 Mar 2019 08:17:08 +0000 >Subject: [PATCH] Bug 20817: Add ability to retain 9xx fields when adding on > order item to existing record > >Signed-off-by: Liz Rea <wizzyrea@gmail.com> > >https://bugs.koha-community.org/show_bug.cgi?id=20187 > >Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> >--- > C4/Items.pm | 2 + > acqui/neworderempty.pl | 198 ++++++++++++++++++ > .../prog/en/modules/acqui/neworderempty.tt | 69 +++++- > .../modules/acqui/neworderempty_duplicate.tt | 3 +- > koha-tmpl/intranet-tmpl/prog/js/additem.js | 2 +- > 5 files changed, 270 insertions(+), 4 deletions(-) > >diff --git a/C4/Items.pm b/C4/Items.pm >index ce285577bd..fda2906f96 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -1559,6 +1559,8 @@ sub PrepareItemrecordDisplay { > my $itemrecord; > if ($itemnum) { > $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum ); >+ }elsif ($defaultvalues && $defaultvalues->{'itemrecord'} ) { >+ $itemrecord = $defaultvalues->{'itemrecord'}; > } > my @loop_data; > >diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl >index 22c7c3c04f..7a4ca41e00 100755 >--- a/acqui/neworderempty.pl >+++ b/acqui/neworderempty.pl >@@ -321,6 +321,19 @@ if ( not $ordernumber or $biblionumber ) { > } > } > >+my $usebreedingid = $input->param('use_breedingid'); >+if ( $usebreedingid ) { >+ my $item_list = staged_items_field( $usebreedingid ); >+ $listprice = $item_list->{'price'}; >+ $budget_id = $item_list->{'budget_id'}; >+ $data->{replacementprice} = $item_list->{'replacementprice'}; >+ $data->{'sort1'} = $item_list->{'sort1'}; >+ $data->{'sort2'} = $item_list->{'sort2'}; >+ $data->{'discount'} = $item_list->{'discount'}; >+ $data->{quantity} = $item_list->{quantity}; >+ $template->param( item_list => $item_list->{'iteminfos'} ); >+} >+ > $template->param( catalog_details => \@catalog_details, ); > > my $suggestion; >@@ -610,3 +623,188 @@ sub Load_Duplicate { > > output_html_with_http_headers $input, $cookie, $template->output; > } >+ >+sub staged_items_field { >+ my ($breedingid) = @_; >+ my %cellrecord = (); >+ >+ my ($marcrecord, $encoding) = MARCfindbreeding($breedingid); >+ die("Could not find the selected record in the reservoir, bailing") unless $marcrecord; >+ >+ my $infos = get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2', 'replacementprice']); >+ my $price = $infos->{price}; >+ my $replacementprice = $infos->{replacementprice}; >+ my $quantity = $infos->{quantity}; >+ my $budget_code = $infos->{budget_code}; >+ my $discount = $infos->{discount}; >+ my $sort1 = $infos->{sort1}; >+ my $sort2 = $infos->{sort2}; >+ my $budget_id; >+ if($budget_code) { >+ my $biblio_budget = GetBudgetByCode($budget_code); >+ if($biblio_budget) { >+ $budget_id = $biblio_budget->{budget_id}; >+ } >+ } >+ # Items >+ my @itemlist = (); >+ my $all_items_quantity = 0; >+ my $alliteminfos = get_infos_syspref_on_item('MarcItemFieldsToOrder', $marcrecord, ['homebranch', 'holdingbranch', 'itype', 'nonpublic_note', 'public_note', 'loc', 'ccode', 'notforloan', 'uri', 'copyno', 'price', 'replacementprice', 'itemcallnumber', 'quantity', 'budget_code']); >+ if ($alliteminfos != -1) { >+ foreach my $iteminfos (@$alliteminfos) { >+ my %itemrecord=( >+ 'homebranch' => _trim( $iteminfos->{homebranch} ), >+ 'holdingbranch' => _trim( $iteminfos->{holdingbranch} ), >+ 'itype' => _trim( $iteminfos->{itype} ), >+ 'itemnotes_nonpublic' => $iteminfos->{nonpublic_note}, >+ 'itemnotes' => $iteminfos->{public_note}, >+ 'location' => _trim( $iteminfos->{loc} ), >+ 'ccode' => _trim( $iteminfos->{ccode} ), >+ 'notforloan' => _trim( $iteminfos->{notforloan} ), >+ 'uri' => $iteminfos->{uri}, >+ 'copynumber' => $iteminfos->{copyno}, >+ 'price' => $iteminfos->{price}, >+ 'replacementprice' => $iteminfos->{replacementprice}, >+ 'itemcallnumber' => $iteminfos->{itemcallnumber}, >+ ); >+ >+ my $item_quantity = $iteminfos->{quantity} || 1; >+ >+ for (my $i = 0; $i < $item_quantity; $i++) { >+ my %defaultvalues=( >+ 'itemrecord'=> C4::Items::Item2Marc( \%itemrecord), >+ 'branchcode'=>_trim($iteminfos->{homebranch}) >+ ); >+ $all_items_quantity++; >+ my $itemprocessed = PrepareItemrecordDisplay('', '', \%defaultvalues , 'ACQ'); >+ push @itemlist, $itemprocessed->{'iteminformation'}; >+ } >+ } >+ $cellrecord{'iteminfos'} = \@itemlist; >+ } else { >+ $cellrecord{'item_error'} = 1; >+ } >+ $cellrecord{price} = $price || ''; >+ $cellrecord{replacementprice} = $replacementprice || ''; >+ $cellrecord{quantity} = $quantity || ''; >+ $cellrecord{budget_id} = $budget_id || ''; >+ $cellrecord{discount} = $discount || ''; >+ $cellrecord{sort1} = $sort1 || ''; >+ $cellrecord{sort2} = $sort2 || ''; >+ unless ($alliteminfos == -1 && scalar(@$alliteminfos) == 0) { >+ $cellrecord{quantity} = $all_items_quantity; >+ } >+ >+ return (\%cellrecord); >+} >+ >+sub get_infos_syspref { >+ my ($syspref_name, $record, $field_list) = @_; >+ my $syspref = C4::Context->preference($syspref_name); >+ $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt >+ my $yaml = eval { >+ YAML::Load($syspref); >+ }; >+ if ( $@ ) { >+ warn "Unable to parse $syspref syspref : $@"; >+ return (); >+ } >+ my $r; >+ for my $field_name ( @$field_list ) { >+ next unless exists $yaml->{$field_name}; >+ my @fields = split /\|/, $yaml->{$field_name}; >+ for my $field ( @fields ) { >+ my ( $f, $sf ) = split /\$/, $field; >+ next unless $f and $sf; >+ if ( my $v = $record->subfield( $f, $sf ) ) { >+ $r->{$field_name} = $v; >+ } >+ last if $yaml->{$field}; >+ } >+ } >+ return $r; >+} >+ >+sub equal_number_of_fields { >+ my ($tags_list, $record) = @_; >+ my $tag_fields_count; >+ for my $tag (@$tags_list) { >+ my @fields = $record->field($tag); >+ $tag_fields_count->{$tag} = scalar @fields; >+ } >+ >+ my $tags_count; >+ foreach my $key ( keys %$tag_fields_count ) { >+ if ( $tag_fields_count->{$key} > 0 ) { # Having 0 of a field is ok >+ $tags_count //= $tag_fields_count->{$key}; # Start with the count from the first occurrence >+ return -1 if $tag_fields_count->{$key} != $tags_count; # All counts of various fields should be equal if they exist >+ } >+ } >+ >+ return $tags_count; >+} >+ >+sub get_infos_syspref_on_item { >+ my ($syspref_name, $record, $field_list) = @_; >+ my $syspref = C4::Context->preference($syspref_name); >+ $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt >+ my $yaml = eval { >+ YAML::Load($syspref); >+ }; >+ if ( $@ ) { >+ warn "Unable to parse $syspref syspref : $@"; >+ return (); >+ } >+ my @result; >+ my @tags_list; >+ >+ # Check tags in syspref definition >+ for my $field_name ( @$field_list ) { >+ next unless exists $yaml->{$field_name}; >+ my @fields = split /\|/, $yaml->{$field_name}; >+ for my $field ( @fields ) { >+ my ( $f, $sf ) = split /\$/, $field; >+ next unless $f and $sf; >+ push @tags_list, $f; >+ } >+ } >+ @tags_list = List::MoreUtils::uniq(@tags_list); >+ >+ my $tags_count = equal_number_of_fields(\@tags_list, $record); >+ # Return if the number of these fields in the record is not the same. >+ return -1 if $tags_count == -1; >+ >+ # Gather the fields >+ my $fields_hash; >+ foreach my $tag (@tags_list) { >+ my @tmp_fields; >+ foreach my $field ($record->field($tag)) { >+ push @tmp_fields, $field; >+ } >+ $fields_hash->{$tag} = \@tmp_fields; >+ } >+ >+ for (my $i = 0; $i < $tags_count; $i++) { >+ my $r; >+ for my $field_name ( @$field_list ) { >+ next unless exists $yaml->{$field_name}; >+ my @fields = split /\|/, $yaml->{$field_name}; >+ for my $field ( @fields ) { >+ my ( $f, $sf ) = split /\$/, $field; >+ next unless $f and $sf; >+ my $v = $fields_hash->{$f}[$i] ? $fields_hash->{$f}[$i]->subfield( $sf ) : undef; >+ $r->{$field_name} = $v if (defined $v); >+ last if $yaml->{$field}; >+ } >+ } >+ push @result, $r; >+ } >+ return \@result; >+} >+ >+sub _trim { >+ return $_[0] unless $_[0]; >+ $_[0] =~ s/^\s+//; >+ $_[0] =~ s/\s+$//; >+ $_[0]; >+} >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt >index 288b2f5f43..52d4b1334e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt >@@ -5,6 +5,11 @@ > [% USE Price %] > [% USE ItemTypes %] > [% SET footerjs = 1 %] >+ >+[% IF item_list %] >+ [% SET footerjs = 0 %] >+[% END %] >+ > [% INCLUDE 'doc-head-open.inc' %] > <title>[% IF ( ordernumber ) %]Modify order details (line #[% ordernumber | html %])[% ELSE %]New order[% END %] › Basket [% basketno | html %] › Acquisitions › Koha</title> > [% INCLUDE 'doc-head-close.inc' %] >@@ -319,7 +324,59 @@ > <div class="dialog message">The autoBarcode system preference is set to [% Koha.Preference('autoBarcode') | html %] and items with blank barcodes will have barcodes generated upon save to database</div> > [% END %] > >- <div id="outeritemblock"></div> >+ <div id="outeritemblock"> >+ [% FOREACH item IN item_list %] >+ [% SET itemID = loop.count %] >+ <div id="itemblock[% itemID | html %]" > >+ <ol> >+ [% FOREACH iteminfo IN item %] >+ [% IF ( iteminfo.hidden ) %] >+ <li style="[% iteminfo.hidden | html %];"> >+ [% ELSE %] >+ <li> >+ [% END %] >+ <div class="subfield_line" id="subfield[% iteminfo.serialid | html %][% iteminfo.countitems | html %][% iteminfo.subfield | html %][% iteminfo.random | html %]"> >+ [% IF (iteminfo.mandatory) %] >+ <label class="required">[% iteminfo.subfield | html %] - [% iteminfo.marc_lib | $raw %]</label> >+ [% ELSE %] >+ <label>[% iteminfo.subfield | html %] - [% iteminfo.marc_lib | $raw %]</label> >+ [% END %] >+ [% IF ( iteminfo.marc_value.type == 'select' ) %] >+ <select name="field_value" size="1"> >+ [% FOREACH value IN iteminfo.marc_value.values %] >+ [% IF ( value == iteminfo.marc_value.default ) %] >+ <option value="[% value | html %]" selected="selected">[% iteminfo.marc_value.labels.$value | html %]</option> >+ [% ELSE %] >+ <option value="[% value | html %]">[% iteminfo.marc_value.labels.$value | html %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ [% ELSE %] >+ [% iteminfo.marc_value | $raw %] >+ [% END %] >+ <input type="hidden" name="itemid" value="[% itemID | html %]" /> >+ <input type="hidden" name="kohafield" value="[% iteminfo.kohafield | html %]" /> >+ <input type="hidden" name="tag" value="[% iteminfo.tag | html %]" /> >+ <input type="hidden" name="subfield" value="[% iteminfo.subfield | html %]" /> >+ <input type="hidden" name="mandatory" value="[% iteminfo.mandatory | html %]" /> >+ [% IF (iteminfo.mandatory) %] <span class="required">Required</span>[% END %] >+ </div> >+ </li> >+ [% END %] >+ </ol> >+ <fieldset class="action"> >+ <input class="addItemControl" name="buttonPlus" style="cursor:pointer; margin:0 1em;" onclick="addItem(this,'[% UniqueItemFields | html %]')" value="Add item" type="button"> >+ <input class="addItemControl cancel" name="buttonClear" style="cursor:pointer;" onclick="clearItemBlock(this)" value="Clear" type="button"> >+ <input class="addItemControl" name="buttonPlusMulti" onclick="javascript:this.nextElementSibling.style.display='inline'; return false;" style="cursor:pointer; margin:0 1em;" value="Add multiple items" type="button"> >+ <span id="add_multiple_copies" style="display:none"> >+ <input class="addItemControl" id="multiValue" name="multiValue" placeholder="Number of items to add" type="number"> >+ <input class="addItemControl" name="buttonAddMulti"" style="cursor:pointer; margin:0 1em;" onclick="checkCount( this ,'[% UniqueItemFields | html %]')" value="Add" type="button"> >+ <div class="dialog message">NOTE: Fields listed in the 'UniqueItemsFields' system preference will not be copied</div> >+ </span> >+ </fieldset> >+ </div> >+ [% END %] >+ </div> > > </fieldset> > [% END %][%# | html UNLESS subscriptionid %] >@@ -617,7 +674,12 @@ > } > > $(document).ready(function(){ >- [% IF AcqCreateItemOrdering and not basket.is_standing %] >+ var events = $('#outeritemblock > div').filter(function () { >+ var el = BindPluginEvents(this.innerHTML); >+ return el; >+ }); >+ >+ [% IF AcqCreateItemOrdering and not basket.is_standing and not item_list %] > cloneItemBlock(0, '[% UniqueItemFields | html %]'); > [% END %] > >@@ -714,6 +776,9 @@ > </script> > [% END %] > >+[% UNLESS ( footerjs ) %] >+ [% jsinclude | $raw # Parse the page template's JavaScript block if necessary %] >+[% END %] > [% INCLUDE 'intranet-bottom.inc' %] > > [% BLOCK display_subfield %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty_duplicate.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty_duplicate.tt >index cd2beae0ce..4091cc898e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty_duplicate.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty_duplicate.tt >@@ -50,6 +50,7 @@ > <input type="hidden" name="basketno" value="[% basketno | html %]" /> > <input type="hidden" name="biblionumber" value="[% biblionumber | html %]" /> > <input type="submit" value="Use existing" /> >+<input type="hidden" name="use_breedingid" value="[% breedingid | html %]" /> > </form> > </div> > </div> >@@ -74,7 +75,7 @@ > <input type="hidden" name="basketno" value="[% basketno | html %]" /> > <input type="hidden" name="breedingid" value="[% breedingid | html %]" /> > <input type="hidden" name="use_external_source" value="1" /> >-<input type="submit" value="Create new" /> >+<input type="hidden" name="use_breedingid" value="[% breedingid | html%]" /> > </form> > </div> > </div> >diff --git a/koha-tmpl/intranet-tmpl/prog/js/additem.js b/koha-tmpl/intranet-tmpl/prog/js/additem.js >index 7d80ca8a77..1876902895 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/additem.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/additem.js >@@ -11,7 +11,7 @@ function addItem( node, unique_item_fields ) { > } > if ( $("#items_list table").find('tr[idblock="' + index + '"]').length == 0 ) { > if ( current_qty < max_qty ) { >- if ( current_qty < max_qty - 1 ) >+ if ( current_qty < max_qty - 1 && $('#outeritemblock > div:visible').length == 1 ) > cloneItemBlock(index, unique_item_fields); > addItemInList(index, unique_item_fields); > $("#" + index).find("input[name='buttonPlus']").val( __("Update item") ); >-- >2.20.1
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 20817
:
79867
|
80537
|
86711
|
86746
|
105214
|
105215
|
105216
|
105217
|
105218
|
105219
|
115343
|
118371
|
118372
|
118373
|
118374
|
118375
|
118376
|
118377
|
118378
|
122692
|
122834
|
122841
|
122858
|
122861
|
128766
|
128767
|
128768
|
128769
|
128770
|
128771
|
128772
|
128773
|
128774
|
128775
|
128776
|
128777
|
128782
|
128783
|
128785
|
128786
|
128787
|
128788
|
128789
|
128790
|
128791
|
128792
|
128793
|
128794
|
128795
|
128796
|
128797
|
128798
|
131732
|
131733
|
131734
|
131735
|
131736
|
131737
|
131738
|
131739
|
131740
|
131741
|
131742
|
131743
|
131744
|
131745
|
131746
|
131747
|
131748
|
131749
|
142630
|
142631
|
142632
|
142633
|
142634
|
142635
|
142636
|
142637
|
142638
|
142639
|
142640
|
142641
|
142642
|
142643
|
142644
|
142645
|
142646
|
142647
|
142648
|
142649
|
142650
|
142651
|
142829