+sub check_warehouse_and_bin {
+ my ($self, $entry) = @_;
+
+ my $object = $entry->{object};
+
+ # Check whether or not warehouse id is valid.
+ if ($object->warehouse_id && !$self->warehouses_by->{id}->{ $object->warehouse_id }) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid warehouse id');
+ return 0;
+ }
+ # Map name to ID if given.
+ if (!$object->warehouse_id && $entry->{raw_data}->{warehouse}) {
+ my $wh = $self->warehouses_by->{description}->{ $entry->{raw_data}->{warehouse} };
+
+ if (!$wh) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid warehouse name #1',$entry->{raw_data}->{warehouse});
+ return 0;
+ }
+
+ $object->warehouse_id($wh->id);
+ }
+ $self->clone_methods->{warehouse_id} = 1;
+
+ # Check whether or not bin id is valid.
+ if ($object->bin_id && !$self->bins_by->{id}->{ $object->bin_id }) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid bin id');
+ return 0;
+ }
+ # Map name to ID if given.
+ if ($object->warehouse_id && !$object->bin_id && $entry->{raw_data}->{bin}) {
+ my $bin = $self->bins_by->{description}->{ $entry->{raw_data}->{bin} };
+
+ if (!$bin) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid bin name #1',$entry->{raw_data}->{bin});
+ return 0;
+ }
+
+ $object->bin_id($bin->id);
+ }
+ $self->clone_methods->{bin_id} = 1;
+
+ if ($object->warehouse_id && $object->bin_id ) {
+ my $bin = $self->bins_by->{id}->{ $object->bin_id };
+ if ( $bin->warehouse_id != $object->warehouse_id ) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Bin #1 is not from warehouse #2',
+ $self->bins_by->{id}->{$object->bin_id}->description,
+ $self->warehouses_by->{id}->{ $object->warehouse_id }->description);
+ return 0;
+ }
+ }
+ return 1;
+}
+