RT# 77917 - Updated event option Agent to allow for selection of multiple agents.
authorChristopher Burger <burgerc@freeside.biz>
Tue, 5 Jun 2018 00:10:15 +0000 (20:10 -0400)
committerChristopher Burger <burgerc@freeside.biz>
Tue, 5 Jun 2018 00:10:15 +0000 (20:10 -0400)
FS/FS/Upgrade.pm
FS/FS/part_event/Condition/agent.pm
FS/FS/part_event_condition_option.pm

index 0069e20..5be33fa 100644 (file)
@@ -501,6 +501,9 @@ sub upgrade_data {
     #'compliance solutions' -> 'compliance_solutions'
     'tax_rate' => [],
     'tax_rate_location' => [],
+
+    #upgrade part_event_condition_option agentnum to a multiple hash value
+    'part_event_condition_option' =>[],
   ;
 
   \%hash;
index bdd4e12..917cf46 100644 (file)
@@ -13,7 +13,7 @@ sub description {
 
 sub option_fields {
   (
-    'agentnum'   => { label=>'Agent', type=>'select-agent', },
+    'agentnum'   => { label=>'Agent', type=>'select-agent', multiple => '1' },
   );
 }
 
@@ -22,16 +22,15 @@ sub condition {
 
   my $cust_main = $self->cust_main($object);
 
-  my $agentnum = $self->option('agentnum');
-
-  $cust_main->agentnum == $agentnum;
+  my $hashref = $self->option('agentnum') || {};
+  grep $hashref->{ $_->agentnum }, $cust_main->agent;
 
 }
 
 sub condition_sql {
   my( $class, $table, %opt ) = @_;
 
-  "cust_main.agentnum = " . $class->condition_sql_option_integer('agentnum', $opt{'driver_name'});
+  "cust_main.agentnum IN " . $class->condition_sql_option_option_integer('agentnum', $opt{'driver_name'});
 }
 
 1;
index 3256dc0..15a6a55 100644 (file)
@@ -138,6 +138,30 @@ sub optionvalue {
   }
 }
 
+use FS::upgrade_journal;
+sub _upgrade_data { #class method
+  my ($class, %opts) = @_;
+
+  # migrate part_event_condition_option agentnum to part_event_condition_option_option agentnum
+  unless ( FS::upgrade_journal->is_done('agentnum_to_hash') ) {
+
+    foreach my $condition_option (qsearch('part_event_condition_option', { optionname => 'agentnum', })) {
+      my $optionvalue = $condition_option->get("optionvalue");
+      if ($optionvalue eq 'HASH' ) { next; }
+      else {
+        my $options = {"$optionvalue" => '1',};
+        $condition_option->optionvalue(ref($options));
+        my $error = $condition_option->replace($options);
+        die $error if $error;
+      }
+    }
+
+    FS::upgrade_journal->set_done('agentnum_to_hash');
+
+  }
+
+}
+
 =back
 
 =head1 SEE ALSO