disable auto-billing of specific customer packages, RT#6378
[freeside.git] / FS / FS / part_pkg.pm
index 70dcd49..08c9b87 100644 (file)
@@ -205,7 +205,11 @@ sub insert {
   warn "  inserting part_pkg_taxoverride records" if $DEBUG;
   my %overrides = %{ $options{'tax_overrides'} || {} };
   foreach my $usage_class ( keys %overrides ) {
-    my @overrides = (grep "$_", split (',', $overrides{$usage_class}) );
+    my $override =
+      ( exists($overrides{$usage_class}) && defined($overrides{$usage_class}) )
+        ? $overrides{$usage_class}
+        : '';
+    my @overrides = (grep "$_", split(',', $override) );
     my $error = $self->process_m2m (
                   'link_table'   => 'part_pkg_taxoverride',
                   'target_table' => 'tax_class',
@@ -458,6 +462,7 @@ sub check {
     || $self->ut_textn('taxclass')
     || $self->ut_enum('disabled', [ '', 'Y' ] )
     || $self->ut_enum('custom', [ '', 'Y' ] )
+    || $self->ut_enum('no_auto', [ '', 'Y' ])
     #|| $self->ut_moneyn('setup_cost')
     #|| $self->ut_moneyn('recur_cost')
     || $self->ut_floatn('setup_cost')
@@ -763,6 +768,7 @@ sub is_free {
   }
 }
 
+sub can_discount { 0; }
 
 sub freqs_href {
   #method, class method or sub? #my $self = shift;
@@ -903,9 +909,11 @@ sub options {
   map { $_->optionname => $_->optionvalue } $self->part_pkg_option;
 }
 
-=item option OPTIONNAME
+=item option OPTIONNAME [ QUIET ]
 
-Returns the option value for the given name, or the empty string.
+Returns the option value for the given name, or the empty string.  If a true
+value is passed as the second argument, warnings about missing the option
+will be suppressed.
 
 =cut
 
@@ -1374,15 +1382,16 @@ sub _pkgs_sql {
 
   "
     (
-      agentnum IS NOT NULL
-      OR
-      0 < ( SELECT COUNT(*)
-              FROM type_pkgs
-                LEFT JOIN agent_type USING ( typenum )
-                LEFT JOIN agent AS typeagent USING ( typenum )
-              WHERE type_pkgs.pkgpart = part_pkg.pkgpart
-                AND typeagent.agentnum IN ($agentnums)
-          )
+      ( agentnum IS NOT NULL AND agentnum IN ($agentnums) )
+      OR ( agentnum IS NULL
+           AND EXISTS ( SELECT 1
+                          FROM type_pkgs
+                            LEFT JOIN agent_type USING ( typenum )
+                            LEFT JOIN agent AS typeagent USING ( typenum )
+                          WHERE type_pkgs.pkgpart = part_pkg.pkgpart
+                            AND typeagent.agentnum IN ($agentnums)
+                      )
+         )
     )
   ";