diff options
author | Ivan Kohler <ivan@freeside.biz> | 2015-06-13 15:18:37 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2015-06-13 15:18:37 -0700 |
commit | 7beec7068e00be5ae1b2599fdf2b494bc19e31d0 (patch) | |
tree | 055e1d25694ccfdac3a2d5aca79441cf7a3d89b5 /FS/FS/svc_Common.pm | |
parent | 9e8d2a5bafb21c42f54cdd9b3703e2f88a36e0a8 (diff) | |
parent | eb6536b41456955fc425dba2e156a996e8fe2837 (diff) |
Merge branch 'FREESIDE_3_BRANCH' of git.freeside.biz:/home/git/freeside into FREESIDE_3_BRANCH
Diffstat (limited to 'FS/FS/svc_Common.pm')
-rw-r--r-- | FS/FS/svc_Common.pm | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm index 61a5f6aa8..d70209aef 100644 --- a/FS/FS/svc_Common.pm +++ b/FS/FS/svc_Common.pm @@ -155,13 +155,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; } |