]> wagnertech.de Git - mfinanz.git/blobdiff - SL/DB/CustomVariable.pm
Merge branch 'master' of http://wagnertech.de/git/mfinanz
[mfinanz.git] / SL / DB / CustomVariable.pm
index a34640518eb2dabcf8991203a6266db44f5dc682..75dc26ebd5d380ad574351c170235f5a48cf54e0 100644 (file)
@@ -40,7 +40,7 @@ sub parse_value {
 
   if ($type =~ m{^(?:customer|vendor|part|number)}) {
     return $self->number_value(!defined($unparsed) ? undef
-                               : (any { ref($unparsed) eq $_ } qw(SL::DB::Customer SL::DB::Vendor SL::DB::Part)) ? $unparsed->id * 1
+                               : (any { ref($unparsed) eq $_ } qw(SL::DB::Customer SL::DB::Vendor SL::DB::Part)) ? $unparsed->id
                                : $unparsed * 1);
   }
 
@@ -52,7 +52,7 @@ sub parse_value {
     return $self->timestamp_value(!defined($unparsed) ? undef : ref($unparsed) eq 'DateTime' ? $unparsed->clone : DateTime->from_kivitendo($unparsed));
   }
 
-  # text, textfield, select
+  # text, textfield, htmlfield and select
   $self->text_value($unparsed);
 }
 
@@ -76,23 +76,23 @@ sub value {
   if ( $type eq 'customer' ) {
     require SL::DB::Customer;
 
-    my $id = int($self->number_value);
+    my $id = defined($self->number_value) ? int($self->number_value) : undef;
     return $id ? SL::DB::Customer->new(id => $id)->load() : undef;
   } elsif ( $type eq 'vendor' ) {
     require SL::DB::Vendor;
 
-    my $id = int($self->number_value);
+    my $id = defined($self->number_value) ? int($self->number_value) : undef;
     return $id ? SL::DB::Vendor->new(id => $id)->load() : undef;
   } elsif ( $type eq 'part' ) {
     require SL::DB::Part;
 
-    my $id = int($self->number_value);
+    my $id = defined($self->number_value) ? int($self->number_value) : undef;
     return $id ? SL::DB::Part->new(id => $id)->load() : undef;
   } elsif ( $type eq 'date' ) {
     return $self->timestamp_value ? $self->timestamp_value->clone->truncate(to => 'day') : undef;
   }
 
-  goto &text_value; # text, textfield and select
+  goto &text_value; # text, textfield, htmlfield and select
 }
 
 sub value_as_text {
@@ -116,7 +116,7 @@ sub value_as_text {
     return $object ? $object->displayable_name : '';
   }
 
-  goto &text_value; # text, textfield and select
+  goto &text_value; # text, textfield, htmlfield and select
 }
 
 sub is_valid {
@@ -125,7 +125,7 @@ sub is_valid {
   require SL::DB::CustomVariableValidity;
 
   # only base level custom variables can be invalid. ovverloaded ones could potentially clash on trans_id, so disallow them
-  return 1 if $_->sub_module;
+  return 1 if $self->sub_module;
 
   $self->{is_valid} //= do {
     my $query = [config_id => $self->config_id, trans_id => $self->trans_id];