Bugzilla – Attachment 45915 Details for
Bug 11844
Additional fields for order lines
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11844: Use additional fields for order lines
Bug-11844-Use-additional-fields-for-order-lines.patch (text/plain), 20.13 KB, created by
Biblibre Sandboxes
on 2015-12-22 17:44:54 UTC
(
hide
)
Description:
Bug 11844: Use additional fields for order lines
Filename:
MIME Type:
Creator:
Biblibre Sandboxes
Created:
2015-12-22 17:44:54 UTC
Size:
20.13 KB
patch
obsolete
>From ff4cc059efb173be1e4e9bdbbb90a1a4dcc99980 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Wed, 5 Feb 2014 11:12:21 +0100 >Subject: [PATCH] Bug 11844: Use additional fields for order lines > >This patch makes use of new module Koha::AdditionalField to provide >additional fields to order lines. >Once created, these fields can be filled during order line creation or >modification. > >If additional field is linked to a MARC field, then >value from biblio record is retrieved at order line creation. When >saving order line (at creation or modification), values in additional >fields are saved into biblio record. >If additional field is linked to an authorised value category, then >authorised values are used. If not directly linked to an authorised >value category, but linked to a MARC field, a search for a AV category >is made on MARC default framework. > >This patch doesn't display additional fields value anywhere (except in >order line creation/modification). Future patches will do that. > >Test plan: >1/ Go to Acquisitions home >2/ In the left menu, click on "Add order line fields" >3/ Click on "New field" button >4/ Give the field a name (unique), no AV category and no MARC field. >5/ Save. >6/ Create 5 other fields: > a/ no AV category, a MARC field not linked to AV category > b/ no AV category, a MARC field linked to AV category > c/ a AV category, no MARC field > d/ a AV category, a MARC field not linked to AV category > e/ a AV category, a MARC field linked to another AV category > In case of (e), the additional AV category should be used, not the AV > category linked to MARC field >7/ Create everything you need to be able to create order lines > (supplier, basket, ...) >8/ Create an order line. At bottom of the page, you should see your > additional fields, with authorised values dropdrown list for fields > (c), (d) and (e) (check this is the right AV category for (e)) >9/ Fill these fields with some data and save order line >10/ check that data was correctly saved into biblio for fields (a), (b), > (d) and (e) >11/ modify the same order line, check that values you've filled is > correctly retrieved. >12/ modify all values, save, and check biblio once again >13/ create a new order line on the same biblio used for previous order > line. check that values are correctly retrieved from biblio > >Signed-off-by: Harold Dramer <harold.dramer@nyls.edu> >--- > Koha/Template/Plugin/AuthorisedValues.pm | 7 + > acqui/add_order_fields.pl | 123 +++++++++++++++ > acqui/addorder.pl | 29 ++++ > acqui/neworderempty.pl | 47 ++++-- > .../prog/en/includes/acquisitions-menu.inc | 1 + > .../prog/en/modules/acqui/add_order_fields.tt | 165 ++++++++++++++++++++ > .../prog/en/modules/acqui/neworderempty.tt | 30 ++++ > 7 files changed, 388 insertions(+), 14 deletions(-) > create mode 100755 acqui/add_order_fields.pl > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_order_fields.tt > >diff --git a/Koha/Template/Plugin/AuthorisedValues.pm b/Koha/Template/Plugin/AuthorisedValues.pm >index 36ddce1..ae66077 100644 >--- a/Koha/Template/Plugin/AuthorisedValues.pm >+++ b/Koha/Template/Plugin/AuthorisedValues.pm >@@ -38,6 +38,11 @@ sub GetAuthValueDropbox { > return C4::Koha::GetAuthvalueDropbox($category, $default); > } > >+sub GetValues { >+ my ( $self, $category ) = @_; >+ return GetAuthorisedValues($category); >+} >+ > 1; > > =head1 NAME >@@ -77,3 +82,5 @@ Kyle M Hall <kyle@bywatersolutions.com> > Jonathan Druart <jonathan.druart@biblibre.com> > > =cut >+ >+1; >diff --git a/acqui/add_order_fields.pl b/acqui/add_order_fields.pl >new file mode 100755 >index 0000000..ef77af6 >--- /dev/null >+++ b/acqui/add_order_fields.pl >@@ -0,0 +1,123 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Copyright 2014 BibLibre >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use CGI; >+use C4::Auth; >+use C4::Koha; >+use C4::Output; >+use Koha::AdditionalField; >+ >+my $input = new CGI; >+ >+my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >+ { >+ template_name => "acqui/add_order_fields.tt", >+ query => $input, >+ type => "intranet", >+ authnotrequired => 0, >+ flagsrequired => { acquisition => '*' }, >+ debug => 1, >+ } >+); >+ >+my $op = $input->param('op') // 'list'; >+my $field_id = $input->param('field_id'); >+my @messages; >+ >+if ( $op eq 'add' ) { >+ my $name = $input->param('name') // q{}; >+ my $authorised_value_category = $input->param('authorised_value_category') // q{}; >+ my $marcfield = $input->param('marcfield') // q{}; >+ if ( $field_id and $name ) { >+ my $updated = 0; >+ eval { >+ my $af = Koha::AdditionalField->new({ >+ id => $field_id, >+ name => $name, >+ authorised_value_category => $authorised_value_category, >+ marcfield => $marcfield, >+ }); >+ $updated = $af->update; >+ }; >+ push @messages, { >+ code => 'update', >+ number => $updated, >+ }; >+ } elsif ( $name ) { >+ my $inserted = 0; >+ eval { >+ my $af = Koha::AdditionalField->new({ >+ tablename => 'aqorders', >+ name => $name, >+ authorised_value_category => $authorised_value_category, >+ marcfield => $marcfield, >+ }); >+ $inserted = $af->insert; >+ }; >+ push @messages, { >+ code => 'insert', >+ number => $inserted, >+ }; >+ } else { >+ push @messages, { >+ code => 'insert', >+ number => 0, >+ }; >+ } >+ $op = 'list'; >+} >+ >+if ( $op eq 'delete' ) { >+ my $deleted = 0; >+ eval { >+ my $af = Koha::AdditionalField->new( { id => $field_id } ); >+ $deleted = $af->delete; >+ $deleted = 0 if $deleted eq '0E0'; >+ }; >+ push @messages, { >+ code => 'delete', >+ number => $deleted, >+ }; >+ $op = 'list'; >+} >+ >+if ( $op eq 'add_form' ) { >+ my $categories = C4::Koha::GetAuthorisedValueCategories(); >+ my $field; >+ if ( $field_id ) { >+ $field = Koha::AdditionalField->new( { id => $field_id } )->fetch; >+ } >+ >+ $template->param( >+ field => $field, >+ categories => $categories, >+ ); >+} >+ >+if ( $op eq 'list' ) { >+ my $fields = Koha::AdditionalField->all( { tablename => 'aqorders' } ); >+ $template->param( fields => $fields ); >+} >+ >+$template->param( >+ op => $op, >+ messages => \@messages, >+); >+ >+output_html_with_http_headers $input, $cookie, $template->output; >diff --git a/acqui/addorder.pl b/acqui/addorder.pl >index f58e58d..5500a21 100755 >--- a/acqui/addorder.pl >+++ b/acqui/addorder.pl >@@ -130,6 +130,8 @@ use C4::Budgets; > use C4::Items; > use C4::Output; > >+use Koha::AdditionalField; >+ > ### "-------------------- addorder.pl ----------" > > # FIXME: This needs to do actual error checking and possibly return user to the same form, >@@ -276,6 +278,33 @@ if ( $orderinfo->{quantity} ne '0' ) { > $order->insert; > } > >+ # Retrieve and save additional fields values >+ my $record = GetMarcBiblio($orderinfo->{biblionumber}); >+ my $record_updated = 0; >+ my $additional_fields = Koha::AdditionalField->all({tablename => 'aqorders'}); >+ foreach my $af (@$additional_fields) { >+ my $id = $af->{id}; >+ my $value = $input->param("additional_field_$id"); >+ $af->{values}->{$orderinfo->{ordernumber}} = $value; >+ $af->insert_values; >+ >+ # Save value in biblio record, if marcfield is set >+ if ($af->{marcfield}) { >+ my ($fieldtag, $subfieldtag) = split /\$/, $af->{marcfield}; >+ my $field = $record->field($fieldtag); >+ if ($field) { >+ $field->update($subfieldtag => $value); >+ } else { >+ $field = new MARC::Field($fieldtag, '', '', $subfieldtag => $value); >+ $record->append_fields($field); >+ } >+ $record_updated = 1; >+ } >+ } >+ if ($record_updated) { >+ ModBiblio($record, $orderinfo->{biblionumber}); >+ } >+ > # now, add items if applicable > if (C4::Context->preference('AcqCreateItem') eq 'ordering') { > >diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl >index 4a37815..3c7e609 100755 >--- a/acqui/neworderempty.pl >+++ b/acqui/neworderempty.pl >@@ -66,29 +66,26 @@ the item's id in the breeding reservoir > > =cut > >-use warnings; >-use strict; >+use Modern::Perl; >+ > use CGI qw ( -utf8 ); >-use C4::Context; > >+use C4::Acquisition; > use C4::Auth; >+use C4::Biblio; # GetBiblioData GetMarcPrice >+use C4::Branch; # GetBranches > use C4::Budgets; >- >-use C4::Acquisition; >+use C4::Context; > use C4::Contract; >-use C4::Suggestions; # GetSuggestion >-use C4::Biblio; # GetBiblioData GetMarcPrice >-use C4::Items; #PrepareItemRecord >-use C4::Output; >+use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/; #needed for z3950 import: >+use C4::Items; #PrepareItemRecord > use C4::Koha; >-use C4::Branch; # GetBranches > use C4::Members; >+use C4::Output; >+use C4::Suggestions; # GetSuggestion > use C4::Search qw/FindDuplicate/; >- >-#needed for z3950 import: >-use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/; >- > use Koha::Acquisition::Bookseller; >+use Koha::AdditionalField; > > our $input = new CGI; > my $booksellerid = $input->param('booksellerid'); # FIXME: else ERROR! >@@ -329,6 +326,28 @@ if ( defined $subscriptionid ) { > # Find the items.barcode subfield for barcode validations > my (undef, $barcode_subfield) = GetMarcFromKohaField('items.barcode', ''); > >+# Get additional fields >+my $record; >+my $additional_fields = Koha::AdditionalField->all({tablename => 'aqorders'}); >+foreach my $af (@$additional_fields) { >+ if (!$af->{authorised_value_category} && $af->{marcfield}) { >+ # Try to retrieve authorised values category from MARC framework >+ my ($field, $subfield) = split /\$/, $af->{marcfield}; >+ my $category = C4::Koha::GetAuthValCodeFromField($field, $subfield); >+ if ($category) { >+ $af->{authorised_value_category} = $category; >+ } >+ } >+ if ($ordernumber) { >+ $af->fetch_values({record_id => $ordernumber}); >+ } elsif ($biblionumber && $af->{marcfield}) { >+ $record //= GetMarcBiblio($biblionumber); >+ my ($field, $subfield) = split /\$/, $af->{marcfield}; >+ $af->{values}->{'new'} = $record->subfield($field, $subfield); >+ } >+} >+$template->param(additional_fields => $additional_fields); >+ > # fill template > $template->param( > close => $close, >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc >index 439118d..364921b 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc >@@ -9,4 +9,5 @@ > [% IF ( CAN_user_parameters ) %] > <li><a href="/cgi-bin/koha/admin/currency.pl">Currencies</a></li> > [% END %] >+ <li><a href="/cgi-bin/koha/acqui/add_order_fields.pl">Add order line fields</a></li> > </ul> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_order_fields.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_order_fields.tt >new file mode 100644 >index 0000000..4fab644 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_order_fields.tt >@@ -0,0 +1,165 @@ >+[% INCLUDE 'doc-head-open.inc' %] >+<title>Koha › Acquisitions › Manage new fields for order lines >+ [% IF op == "list" %] › List of fields >+ [% ELSIF op == "add_form" %] >+ [% IF field %] › Modify field >+ [% ELSE %] › Add field >+ [% END %] >+ [% END %] >+</title> >+[% INCLUDE 'doc-head-close.inc' %] >+<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" /> >+[% INCLUDE "datatables.inc" %] >+<script type="text/javascript"> >+//<![CDATA[ >+ $(document).ready(function(){ >+ >+ $("#fieldst").dataTable($.extend(true, {}, dataTablesDefaults, { >+ 'bAutoWidth': false, >+ 'sDom': 't<"bottom pager"ilpf>', >+ 'sPaginationType': 'four_button', >+ 'aLengthMenu': [[10, 20, 50, 100, -1], [10, 20, 50, 100, "All"]], >+ 'iDisplayLength': 20, >+ 'aaSorting': [[ 0, "asc" ]], >+ })); >+ >+ $(".confirmdelete").click(function(){ >+ return confirm(_("Are you sure you want to delete this field?")); >+ }); >+ >+ $("#add_field").on('submit', function(){ >+ if ( $("#marcfield").val().length > 0 >+ && $("select[name='authorised_value_category']" ).val().length > 0 ) { >+ alert("You cannot select an authorised value category and a marcfield"); >+ return false; >+ } >+ return true; >+ }); >+ }); >+//]]> >+</script> >+</head> >+ >+<body id="acq_add_fields" class="acq"> >+ [% INCLUDE 'header.inc' %] >+ [% INCLUDE 'acquisitions-search.inc' %] >+ >+ <div id="breadcrumbs"> >+ <a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> › Manage new fields for order lines >+ </div> >+ >+ <div id="doc3" class="yui-t2"> >+ <div id="bd"> >+ <div id="yui-main"> >+ <div class="yui-b"> >+ [% IF op == 'list' %] >+ <div id="toolbar" class="btn-toolbar"> >+ <a class="btn btn-small" id="newfields" href="/cgi-bin/koha/acqui/add_order_fields.pl?op=add_form"><i class="icon-plus"></i> New field</a> >+ </div> >+ [% END %] >+ >+ [% IF messages %] >+ [% FOR message IN messages %] >+ [% IF message.code == 'insert' %] >+ [% IF message.number > 0 %] >+ <div class="dialog message">The field has been inserted</div> >+ [% ELSE %] >+ <div class="dialog alert">The field has not been inserted (name still exist?)</div> >+ [% END %] >+ [% ELSIF message.code == 'update' %] >+ [% IF message.number > 0 %] >+ <div class="dialog message">The field has been updated</div> >+ [% ELSE %] >+ <div class="dialog alert">The field has not been updated (name still exist?)</div> >+ [% END %] >+ [% ELSIF message.code == 'delete' %] >+ [% IF message.number > 0 %] >+ <div class="dialog message">The field has been deleted</div> >+ [% ELSE %] >+ <div class="dialog alert">The field has not been deleted</div> >+ [% END %] >+ [% END %] >+ [% END %] >+ [% END %] >+ >+ [% IF op == 'list' %] >+ <h3>Additional fields for order lines</h3> >+ [% IF fields %] >+ <table id="fieldst"> >+ <thead> >+ <tr> >+ <th>Name</th> >+ <th>Authorised value category</th> >+ <th>MARC field</th> >+ <th>Actions</th> >+ </tr> >+ </thead> >+ <tbody> >+ [% FOR field IN fields %] >+ <tr> >+ <td>[% field.name %]</td> >+ <td>[% field.authorised_value_category %]</td> >+ <td>[% field.marcfield %]</td> >+ <td> >+ <a href="/cgi-bin/koha/acqui/add_order_fields.pl?op=add_form&field_id=[% field.id %]" title="Edit this field">Edit</a> >+ <a class="confirmdelete" href="/cgi-bin/koha/acqui/add_order_fields.pl?op=delete&field_id=[% field.id %]" title="Delete this field">Delete</a> >+ </td> >+ </tr> >+ [% END %] >+ </tbody> >+ </table> >+ [% ELSE %] >+ There is no field defined. >+ [% END %] >+ [% ELSIF op == 'add_form' %] >+ [% IF field %] >+ <h3>Modify field</h3> >+ [% ELSE %] >+ <h3>Add field</h3> >+ [% END %] >+ <form action="/cgi-bin/koha/acqui/add_order_fields.pl" name="add_form" id="add_field" method="post"> >+ <fieldset class="rows"> >+ <ol> >+ <li> >+ <label for="name" class="required">Name: </label> >+ <input type="text" name="name" id="name" value="[% field.name | html %]" /> >+ </li> >+ <li> >+ <label for="av">Authorised value category: </label> >+ <select name="authorised_value_category"> >+ <option value="">None</option> >+ [% FOR category IN categories %] >+ [% IF field.authorised_value_category == category %] >+ <option value="[% category %]" selected="selected">[% category %]</option> >+ [% ELSE %] >+ <option value="[% category %]">[% category %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ </li> >+ <li> >+ <label for="marcfield">MARC field: </label> >+ <input type="text" name="marcfield" id="marcfield" value="[% field.marcfield| html %]" /> >+ <span class="hint">Use this syntax: XXX$y</span> >+ </li> >+ </ol> >+ </fieldset> >+ <fieldset class="action"> >+ [% IF field %] >+ <input type="hidden" name="field_id" value="[% field.id %]" /> >+ [% END %] >+ <input type="hidden" name="op" value="add" /> >+ <input type="submit" value="Save" /> >+ <a href="/cgi-bin/koha/acqui/add_order_fields.pl" class="cancel">Cancel</a> >+ </fieldset> >+ </form> >+ [% END %] >+ >+ </div> >+ </div> >+ >+<div class="yui-b"> >+[% INCLUDE 'acquisitions-menu.inc' %] >+</div> >+</div> >+[% INCLUDE 'intranet-bottom.inc' %] >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 7638f02..1c5db66 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt >@@ -1,4 +1,5 @@ > [% USE KohaDates %] >+[% USE AuthorisedValues %] > [% INCLUDE 'doc-head-open.inc' %] > <title>Koha › Acquisitions › Basket [% basketno %] › [% IF ( ordernumber ) %]Modify order details (line #[% ordernumber %])[% ELSE %]New order[% END %]</title> > [% INCLUDE 'doc-head-close.inc' %] >@@ -625,6 +626,35 @@ $(document).ready(function() > <label for="sort2">Statistic 2: </label> > <input id="sort2" type="text" id="sort2" size="20" name="sort2" value="[% sort2 %]" /> > </li> >+ [% FOREACH af IN additional_fields %] >+ <li> >+ <label for="additional_field_[% af.id %]">[% af.name %]</label> >+ [% value = '' %] >+ [% IF ordernumber %] >+ [% value = af.values.$ordernumber %] >+ [% ELSE %] >+ [% value = af.values.new %] >+ [% END %] >+ [% authorised_values = [] %] >+ [% IF af.authorised_value_category %] >+ [% authorised_values = AuthorisedValues.GetValues(af.authorised_value_category) %] >+ [% END %] >+ [% IF authorised_values.size > 0 %] >+ <select name="additional_field_[% af.id %]" id="additional_field_[% af.id %]"> >+ <option value=""></option> >+ [% FOREACH av IN authorised_values %] >+ [% IF value == av.authorised_value %] >+ <option value="[% av.authorised_value %]" selected="selected">[% av.lib %]</option> >+ [% ELSE %] >+ <option value="[% av.authorised_value %]">[% av.lib %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ [% ELSE %] >+ <input type="text" name="additional_field_[% af.id %]" id="additional_field_[% af.id %]" value="[% value %]" /> >+ [% END %] >+ </li> >+ [% END %] > </ol> > </fieldset> > <fieldset class="action"> >-- >1.7.10.4
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 11844
:
25632
|
25638
|
41859
|
41860
|
45674
|
45675
|
45676
|
45758
|
45915
|
45916
|
45917
|
53614
|
53615
|
53616
|
53618
|
53619
|
55529
|
75332
|
75362
|
141116
|
145517
|
145535
|
145536
|
145540
|
146497
|
146500
|
146501
|
146502
|
146503
|
146504
|
146505
|
146506
|
148889
|
148895
|
148897
|
149081
|
149082
|
149083
|
149084
|
149085
|
149086
|
149087
|
149088
|
149089
|
149090
|
149091
|
149682
|
149683
|
149684
|
149685
|
149686
|
149687
|
149688
|
149689
|
149690
|
149691
|
149692
|
150537
|
150538
|
150539
|
150540
|
150541
|
150542
|
150543
|
150544
|
150545
|
150546
|
150547
|
150548
|
151220
|
151221
|
151222
|
151223
|
151224
|
151225
|
151226
|
151227
|
151228
|
151229
|
151230
|
151366