+ #Check target against package
+ #UI doesn't currently prevent these from happing,
+ #so keep error messages informative
+ my $part_pkg = $self->part_pkg;
+ my $target = $self->target;
+ my $label = $self->target_info->{'label'};
+ my ($needs_svcdb, $needs_plan);
+ if ( $target =~ /^svc_acct.(\w+)$/ ) {
+ $needs_svcdb = 'svc_acct';
+ } elsif ( $target eq 'svc_conferencing.participants' ) {
+ $needs_svcdb = 'svc_conferencing';
+ } elsif ( $target =~ /^sqlradacct_hour.(\w+)$/ ) {
+ $needs_plan = 'sqlradacct_hour';
+ }
+ if ($needs_svcdb) {
+ my $has_svcdb = 0;
+ foreach my $pkg_svc ($part_pkg->pkg_svc) {
+ next unless $pkg_svc->quantity;
+ my $svcdb = $pkg_svc->part_svc->svcdb;
+ $has_svcdb = 1
+ if $svcdb eq $needs_svcdb;
+ last if $has_svcdb;
+ }
+ return "Usage pricing add-on \'$label\' can only be used on packages with at least one $needs_svcdb service.\n"
+ unless $has_svcdb;
+ }
+ if ($needs_plan) {
+ return "Usage pricing add-on \'$label\' can only be used on packages with pricing plan \'" .
+ FS::part_pkg->plan_info->{$needs_plan}->{'shortname'} . "\'\n"
+ unless ref($part_pkg) eq 'FS::part_pkg::' . $needs_plan;
+ }
+