Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[kivitendo-erp.git] / SL / DB / CustomVariable.pm
index 26ff748..eeae39a 100644 (file)
@@ -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);
 }
 
@@ -92,7 +92,7 @@ sub value {
     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 {
@@ -124,8 +124,13 @@ sub is_valid {
 
   require SL::DB::CustomVariableValidity;
 
-  my $query = [config_id => $self->config_id, trans_id => $self->trans_id];
-  return (SL::DB::Manager::CustomVariableValidity->get_all_count(query => $query) == 0) ? 1 : 0;
+  # only base level custom variables can be invalid. ovverloaded ones could potentially clash on trans_id, so disallow them
+  return 1 if $self->sub_module;
+
+  $self->{is_valid} //= do {
+    my $query = [config_id => $self->config_id, trans_id => $self->trans_id];
+    (SL::DB::Manager::CustomVariableValidity->get_all_count(query => $query) == 0) ? 1 : 0;
+  }
 }
 
 1;