Bug 12557: Add a way to revert the changes made on items on receving

Bug 8307 introduces the AcqItemSetSubfieldsWhenReceived pref.
You can now update an item field on receiving (if you create items on
ordering).
But if the receipt is cancel, there is no way to revert these changes.

This patch adds a new pref AcqItemSetSubfieldsWhenReceiptIsCancelled to
allow to revert changes previously done on receiving

Test plan:
0/ Set the AcqCreateItems to 'ordering'
1/ Fill AcqItemSetSubfieldsWhenReceived with o=1 (UNIMARC) or 7=1
(MARC21).
2/ Fill AcqItemSetSubfieldsWhenReceiptIsCancelled with o=2 (UNIMARC) or
7=2 (MARC21)
3/ Create an order with some items
4/ Receive the order and verify the notforloan value is set to 1
5/ Cancel the receipt and verify the notforloan value is set to 2

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
Jonathan Druart 2014-07-11 12:09:32 +02:00 committed by Tomas Cohen Arazi
parent d036b9a4d1
commit 55ca3c5581
2 changed files with 25 additions and 1 deletions

View File

@ -1665,6 +1665,26 @@ sub CancelReceipt {
}
if(C4::Context->preference('AcqCreateItem') eq 'ordering') {
my @affects = split q{\|}, C4::Context->preference("AcqItemSetSubfieldsWhenReceiptIsCancelled");
if ( @affects ) {
my @itemnumbers = GetItemnumbersFromOrder( $parent_ordernumber );
for my $in ( @itemnumbers ) {
my $biblionumber = C4::Biblio::GetBiblionumberFromItemnumber( $in );
my $frameworkcode = GetFrameworkCode($biblionumber);
my ( $itemfield ) = GetMarcFromKohaField( 'items.itemnumber', $frameworkcode );
my $item = C4::Items::GetMarcItem( $biblionumber, $in );
for my $affect ( @affects ) {
my ( $sf, $v ) = split q{=}, $affect, 2;
foreach ( $item->field($itemfield) ) {
$_->update( $sf => $v );
}
}
C4::Items::ModItemFromMarc( $item, $biblionumber, $in );
}
}
}
return $parent_ordernumber;
}

View File

@ -2,7 +2,7 @@
use Modern::Perl;
use Test::More tests => 2;
use Test::More tests => 3;
use C4::Context;
use C4::Acquisition;
use C4::Biblio;
@ -70,6 +70,7 @@ my $order = GetOrder( $ordernumber );
is(scalar GetItemnumbersFromOrder($order->{ordernumber}), 0, "Create items on receiving: 0 item exist after cancelling a receipt");
t::lib::Mocks::mock_preference('AcqCreateItem', 'ordering');
t::lib::Mocks::mock_preference('AcqItemSetSubfieldsWhenReceiptIsCancelled', '7=9'); # notforloan is mapped with 952$7
( undef, $ordernumber ) = C4::Acquisition::NewOrder(
{
basketno => $basketno1,
@ -95,4 +96,7 @@ CancelReceipt($ordernumber);
$order = GetOrder( $ordernumber );
is(scalar GetItemnumbersFromOrder($order->{ordernumber}), 1, "Create items on ordering: items are not deleted after cancelling a receipt");
my $item = C4::Items::GetItem( $itemnumber );
is( $item->{notforloan}, 9, "The notforloan value has been updated with '9'" );
$dbh->rollback;