Bug 8307: Set a value for subfields when receiving
authorJonathan Druart <jonathan.druart@biblibre.com>
Fri, 18 May 2012 11:42:36 +0000 (13:42 +0200)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 31 Oct 2013 23:36:59 +0000 (23:36 +0000)
If items are created when ordering, this patch allows to add a value for
some items subfields.

Test plan:
Define status for items.notforloan (mapping 995$o in unimarc), for
example 4:On order, 5:On treatment

Set the Syspref AcqCreateItem on "ordering".

ACQ framework : set default value = 4 for 995$o (in unimarc)

Syspref AcqItemSetSubfieldsWhenReceived : set "o=5|b='foo bar'"

When ordering the item, default status will be 4 ; when receiving the
item, status will be changed from 4 to 5. The subfield b have to contain
'foo bar'

Signed-off-by: Frederic Durand <frederic.durand@unilim.fr>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
acqui/finishreceive.pl
installer/data/mysql/sysprefs.sql
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref

index 4196b52..0c62f24 100755 (executable)
@@ -62,6 +62,21 @@ if ($quantityrec > $origquantityrec ) {
     my @received_items = ();
     if(C4::Context->preference('AcqCreateItem') eq 'ordering') {
         @received_items = $input->param('items_to_receive');
     my @received_items = ();
     if(C4::Context->preference('AcqCreateItem') eq 'ordering') {
         @received_items = $input->param('items_to_receive');
+        my @affects = split q{\|}, C4::Context->preference("AcqItemSetSubfieldsWhenReceived");
+        if ( @affects ) {
+            my $frameworkcode = GetFrameworkCode($biblionumber);
+            my ( $itemfield ) = GetMarcFromKohaField( 'items.itemnumber', $frameworkcode );
+            for my $in ( @received_items ) {
+                my $item = C4::Items::GetMarcItem( $biblionumber, $in );
+                for my $affect ( @affects ) {
+                    my ( $sf, $v ) = split q{=}, $affect;
+                    foreach ( $item->field($itemfield) ) {
+                        $_->update( $sf => $v );
+                    }
+                }
+                C4::Items::ModItemFromMarc( $item, $biblionumber, $in );
+            }
+        }
     }
 
     $order->{rrp} = $rrp;
     }
 
     $order->{rrp} = $rrp;
@@ -136,7 +151,6 @@ if ($quantityrec > $origquantityrec ) {
             NewOrderItem($itemnumber, $new_ordernumber);
         }
     }
             NewOrderItem($itemnumber, $new_ordernumber);
         }
     }
-
 }
 
 update_item( $_ ) foreach GetItemnumbersFromOrder( $ordernumber );
 }
 
 update_item( $_ ) foreach GetItemnumbersFromOrder( $ordernumber );
index 07e9c0a..dac2595 100644 (file)
@@ -1,5 +1,6 @@
 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
 ('AcqCreateItem','ordering','ordering|receiving|cataloguing','Define when the item is created : when ordering, when receiving, or in cataloguing module','Choice'),
 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
 ('AcqCreateItem','ordering','ordering|receiving|cataloguing','Define when the item is created : when ordering, when receiving, or in cataloguing module','Choice'),
+('AcqItemStatusWhenReceived','0','','This syspref set a status for item when items are created when receiving (e.g. 995\$o=5)','Free'),
 ('AcqViewBaskets','user','user|branch|all','Define which baskets a user is allowed to view: his own only, any within his branch or all','Choice'),
 ('AcqWarnOnDuplicateInvoice','0','','Warn librarians when they try to create a duplicate invoice','YesNo'),
 ('AddPatronLists','categorycode','categorycode|category_type','Allow user to choose what list to pick up from when adding patrons','Choice'),
 ('AcqViewBaskets','user','user|branch|all','Define which baskets a user is allowed to view: his own only, any within his branch or all','Choice'),
 ('AcqWarnOnDuplicateInvoice','0','','Warn librarians when they try to create a duplicate invoice','YesNo'),
 ('AddPatronLists','categorycode','categorycode|category_type','Allow user to choose what list to pick up from when adding patrons','Choice'),
index c511773..e8acfb8 100755 (executable)
@@ -7728,6 +7728,15 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion($DBversion);
 }
 
     SetVersion($DBversion);
 }
 
+$DBversion = "3.13.00.XXX";
+if(CheckVersion($DBversion)) {
+    $dbh->do(q{
+        INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AcqItemSetSubfieldsWhenReceived','','Set subfields for item when items are created when receiving (e.g. o=5|a="foo bar")','','Free');
+    });
+    print "Upgrade to $DBversion done (Added AcqItemSetSubfieldsWhenReceived syspref)\n";
+    SetVersion($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
index 3e64d10..5eba790 100644 (file)
@@ -42,6 +42,9 @@ Acquisitions:
                   yes: Warn
                   no: "Do not warn"
             - when the librarian tries to create an invoice with a duplicate number.
                   yes: Warn
                   no: "Do not warn"
             - when the librarian tries to create an invoice with a duplicate number.
+        -
+            - pref: AcqItemSetSubfieldsWhenReceived
+            - Set subfields for item when items are created when receiving (e.g. o=5|a="foo bar")
 
     Printing:
         -
 
     Printing:
         -