X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_Common.pm;h=b1f9d146f3415524c53c8ca58f011521cc627654;hb=3ef3c5061e6de2dd885987e844ea3122aafc4df6;hp=4a2d6178651e22be57959003997caa3ae5815abe;hpb=32072dbf59a054529f5304574c0f56f9567d14d0;p=freeside.git diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm index 4a2d61786..b1f9d146f 100644 --- a/FS/FS/svc_Common.pm +++ b/FS/FS/svc_Common.pm @@ -152,13 +152,46 @@ sub cust_linked { Checks the validity of fields in this record. -At present, this does nothing but call FS::Record::check (which, in turn, -does nothing but run virtual field checks). +Only checks fields marked as required in table_info or +part_svc_column definition. Should be invoked by service-specific +check using SUPER. Invokes FS::Record::check using SUPER. =cut sub check { my $self = shift; + + ## Checking required fields + + # get fields marked as required in table_info + my $required = {}; + my $labels = {}; + my $tinfo = $self->can('table_info') ? $self->table_info : {}; + my $fields = $tinfo->{'fields'} || {}; + foreach my $field (keys %$fields) { + if (ref($fields->{$field}) && $fields->{$field}->{'required'}) { + $required->{$field} = 1; + $labels->{$field} = $fields->{$field}->{'label'}; + } + } + # add fields marked as required in database + foreach my $column ( + qsearch('part_svc_column',{ + 'svcpart' => $self->svcpart, + 'required' => 'Y' + }) + ) { + $required->{$column->columnname} = 1; + $labels->{$column->columnname} = $column->columnlabel; + } + # do the actual checking + foreach my $field (keys %$required) { + unless ($self->$field) { + my $name = $labels->{$field} || $field; + return "Field $name is required\n" + } + } + $self->SUPER::check; } @@ -804,6 +837,9 @@ If there is an error, returns the error, otherwise returns false. =cut sub set_auto_inventory { + # don't try to do this during an upgrade + return '' if $FS::CurrentUser::upgrade_hack; + my $self = shift; my $old = @_ ? shift : ''; @@ -1381,7 +1417,7 @@ sub search { #custnum if ( $params->{'custnum'} =~ /^(\d+)$/ && $1 ) { - push @where, "custnum = $1"; + push @where, "cust_pkg.custnum = $1"; } #customer status