From e6d23bad4e3ddb7a69a56961c718c17ea8ec6e64 Mon Sep 17 00:00:00 2001 From: af11_sanger Date: Mon, 11 May 2015 10:57:14 +0100 Subject: [PATCH] fixed bug caused by checkout of last well on plate --- lib/LIMS2/Model/Util/BarcodeActions.pm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/LIMS2/Model/Util/BarcodeActions.pm b/lib/LIMS2/Model/Util/BarcodeActions.pm index efae2c429f..eedb3d1ec1 100755 --- a/lib/LIMS2/Model/Util/BarcodeActions.pm +++ b/lib/LIMS2/Model/Util/BarcodeActions.pm @@ -754,6 +754,25 @@ sub create_barcoded_plate_copy{ ] } + # Special case. When the last barcode is removed from a plate this method will create + # an empty plate so we can't get to the previous plate's type and species via the wells + # We need to find the previous plate by name to get type and species. + unless(@wells){ + my $new_plate_name = $validated_params->{new_plate_name}; + + DEBUG "Plate $new_plate_name has no wells. Getting species and type from old plate version."; + + my $previous_plate = $model->schema->resultset('Plate')->search({ + name => $new_plate_name, + })->first; + + die "Cannot find parent wells or parent plate for plate $new_plate_name" + unless $previous_plate; + + $create_params->{species} = $previous_plate->species_id; + $create_params->{type} = $previous_plate->type_id; + } + my $new_plate = $model->create_plate($create_params); # If tubes have been transferred from other (non virtual) plates then