Bug 11744: Cancel a receipt does not delete items created on receiving

If items is created on receiving, cancel a receipt should delete them.
The code only manage the case if the order is a child of another order
(partial).

To reproduce:
1/ Set AcqCreateItem to receiving
2/ Order one or more item(s)
3/ Receive the order and verify the item is created
4/ Cancel the receipt
5/ The item is not deleted

Test plan:
1/ Apply this patch and do again previous steps. The item should not be
deleted at step 5.
2/ Set AcqCreateItem to ordering and verify the item is not deleted.

Signed-off-by: marjorie barry-vila <marjorie.barry-vila@ccsr.qc.ca>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
Jonathan Druart 2014-02-19 13:39:39 +01:00 committed by Tomas Cohen Arazi
parent 10689f2a9b
commit 6803dc6bf5
1 changed files with 27 additions and 19 deletions

View File

@ -1615,6 +1615,7 @@ sub CancelReceipt {
};
$sth = $dbh->prepare($query);
$sth->execute(0, undef, undef, $ordernumber);
_cancel_items_receipt( $ordernumber );
} else {
# The order line has a parent, increase parent quantity and delete
# the order line.
@ -1651,25 +1652,7 @@ sub CancelReceipt {
" receipt";
return;
}
if(C4::Context->preference('AcqCreateItem') eq 'receiving') {
# Remove items that were created at receipt
$query = qq{
DELETE FROM items, aqorders_items
USING items, aqorders_items
WHERE items.itemnumber = ? AND aqorders_items.itemnumber = ?
};
$sth = $dbh->prepare($query);
my @itemnumbers = GetItemnumbersFromOrder($ordernumber);
foreach my $itemnumber (@itemnumbers) {
$sth->execute($itemnumber, $itemnumber);
}
} else {
# Update items
my @itemnumbers = GetItemnumbersFromOrder($ordernumber);
foreach my $itemnumber (@itemnumbers) {
ModItemOrder($itemnumber, $parent_ordernumber);
}
}
_cancel_items_receipt( $ordernumber, $parent_ordernumber );
# Delete order line
$query = qq{
DELETE FROM aqorders
@ -1683,6 +1666,31 @@ sub CancelReceipt {
return $parent_ordernumber;
}
sub _cancel_items_receipt {
my ( $ordernumber, $parent_ordernumber ) = @_;
$parent_ordernumber ||= $ordernumber;
my @itemnumbers = GetItemnumbersFromOrder($ordernumber);
if(C4::Context->preference('AcqCreateItem') eq 'receiving') {
# Remove items that were created at receipt
my $query = qq{
DELETE FROM items, aqorders_items
USING items, aqorders_items
WHERE items.itemnumber = ? AND aqorders_items.itemnumber = ?
};
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare($query);
foreach my $itemnumber (@itemnumbers) {
$sth->execute($itemnumber, $itemnumber);
}
} else {
# Update items
foreach my $itemnumber (@itemnumbers) {
ModItemOrder($itemnumber, $parent_ordernumber);
}
}
}
#------------------------------------------------------------#
=head3 SearchOrders