X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FCustomVariable.pm;h=cb6c83158bcba5d96720f0f5b794f4c52b26d936;hb=f24cf1f5ab8428ced545a382d0f0179ae6f40a81;hp=0971e6466c946c33708774b400fe611d6cacb35d;hpb=4247547d2a925ddad7006cae89e5f9f1fda7d469;p=kivitendo-erp.git diff --git a/SL/DB/CustomVariable.pm b/SL/DB/CustomVariable.pm index 0971e6466..cb6c83158 100644 --- a/SL/DB/CustomVariable.pm +++ b/SL/DB/CustomVariable.pm @@ -4,6 +4,9 @@ package SL::DB::CustomVariable; use strict; + +use List::MoreUtils qw(any); + use SL::DB::MetaSetup::CustomVariable; __PACKAGE__->meta->initialize; @@ -36,7 +39,9 @@ sub parse_value { my $unparsed = delete $self->{__unparsed_value}; if ($type =~ m{^(?:customer|vendor|part|number)}) { - return $self->number_value(defined($unparsed) ? $unparsed * 1 : undef); + return $self->number_value(!defined($unparsed) ? undef + : (any { ref($unparsed) eq $_ } qw(SL::DB::Customer SL::DB::Vendor SL::DB::Part)) ? $unparsed->id * 1 + : $unparsed * 1); } if ($type =~ m{^(?:bool)}) { @@ -44,7 +49,7 @@ sub parse_value { } if ($type =~ m{^(?:date|timestamp)}) { - return $self->timestamp_value(defined($unparsed) ? DateTime->from_kivitendo($unparsed) : undef); + return $self->timestamp_value(!defined($unparsed) ? undef : ref($unparsed) eq 'DateTime' ? $unparsed->clone : DateTime->from_kivitendo($unparsed)); } # text, textfield, select @@ -119,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;