added part_pkg.agent_pkgpartid, RT#27214
[freeside.git] / FS / FS / part_pkg.pm
index 3c4c127..8f8287b 100644 (file)
@@ -259,10 +259,20 @@ sub insert {
   my %part_pkg_currency = %{ $options{'part_pkg_currency'} || {} };
   foreach my $key ( keys %part_pkg_currency ) {
     $key =~ /^(.+)_([A-Z]{3})$/ or next;
+    my( $optionname, $currency ) = ( $1, $2 );
+    if ( $part_pkg_currency{$key} =~ /^\s*$/ ) {
+      if ( $self->option($optionname) == 0 ) {
+        $part_pkg_currency{$key} = '0';
+      } else {
+        $dbh->rollback if $oldAutoCommit;
+        ( my $thing = $optionname ) =~ s/_/ /g;
+        return ucfirst($thing). " $currency is required";
+      }
+    }
     my $part_pkg_currency = new FS::part_pkg_currency {
       'pkgpart'     => $self->pkgpart,
-      'optionname'  => $1,
-      'currency'    => $2,
+      'optionname'  => $optionname,
+      'currency'    => $currency,
       'optionvalue' => $part_pkg_currency{$key},
     };
     my $error = $part_pkg_currency->insert;
@@ -693,6 +703,7 @@ sub check {
     || $self->ut_numbern('delay_start')
     || $self->ut_foreign_keyn('successor', 'part_pkg', 'pkgpart')
     || $self->ut_foreign_keyn('family_pkgpart', 'part_pkg', 'pkgpart')
+    || $self->ut_alphan('agent_pkgpartid')
     || $self->SUPER::check
   ;
   return $error if $error;
@@ -837,8 +848,13 @@ sub custom_comment {
   my $price_info = $self->price_info(@_);
   ( $self->custom ? '(CUSTOM) ' : '' ).
     $self->comment.
-    ( ( ($self->custom || $self->comment) && $price_info ) ? ' - ' : '' ).
-    $price_info;
+    ( ($self->custom || $self->comment) ? ' - ' : '' ).
+    ($price_info || 'No charge');
+}
+
+sub pkg_price_info {
+  my $self = shift;
+  $self->pkg. ' - '. ($self->price_info || 'No charge');
 }
 
 =item pkg_class
@@ -1068,6 +1084,10 @@ sub can_discount { 0; }
  
 # whether the plan allows changing the start date
 sub can_start_date { 1; }
+
+# whether the plan supports part_pkg_usageprice add-ons (a specific kind of
+#  pre-selectable usage pricing, there's others this doesn't refer to)
+sub can_usageprice { 0; }
   
 # the delay start date if present
 sub delay_start_date {