X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_Common.pm;h=355c38342ba6c4f91a71bbe732a46c8f026ea8d8;hb=292ef074d01bb925e9a466ed771bf2ac418bb44f;hp=e4591720d98cea07202358eab7c625aef7443e7a;hpb=a21bd79010b9a3a5e1f9e19dca673dcb38f35334;p=freeside.git diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm index e4591720d..355c38342 100644 --- a/FS/FS/svc_Common.pm +++ b/FS/FS/svc_Common.pm @@ -152,13 +152,48 @@ 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 : {}; + if ($tinfo->{'manual_require'}) { + 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 (length($self->get($field)) > 0) { + my $name = $labels->{$field} || $field; + return "$name is required\n" + } + } + } + $self->SUPER::check; } @@ -247,7 +282,7 @@ sub insert { $self->svcpart($cust_svc->svcpart); } - my $error = $self->preinsert_hook_first + my $error = $self->preinsert_hook_first(%options) || $self->set_auto_inventory || $self->check || $self->_check_duplicate @@ -362,7 +397,8 @@ sub delete { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - my $error = $self->predelete_hook_first + my $error = $self->cust_svc->check_part_svc_link_unprovision + || $self->predelete_hook_first || $self->SUPER::delete || $self->export('delete', @$export_args) || $self->return_inventory @@ -1384,7 +1420,7 @@ sub search { #custnum if ( $params->{'custnum'} =~ /^(\d+)$/ && $1 ) { - push @where, "custnum = $1"; + push @where, "cust_pkg.custnum = $1"; } #customer status