fix editing of events that have reasons, from #31702
authorMark Wells <mark@freeside.biz>
Sun, 30 Nov 2014 00:35:31 +0000 (16:35 -0800)
committerMark Wells <mark@freeside.biz>
Sun, 30 Nov 2014 00:36:42 +0000 (16:36 -0800)
httemplate/edit/process/part_event.html
httemplate/elements/tr-select-reason.html

index 481439d..bac6924 100644 (file)
             my $value = join(',', $cgi->param( "$prefix$option" ) );
 
             if ( $option eq 'reasonnum' && $value == -1 ) {
-              $value = {
-                'typenum' => scalar( $cgi->param( "new$prefix${option}T" ) ),
-                'reason'  => scalar( $cgi->param( "new$prefix${option}"  ) ),
-              };
+              my $reason_prefix = $object->action . '_' . $option .  '_new_';
+              my $new_reason = FS::reason->new;
+              foreach ( qw( reason_type reason unsuspend pkgpart 
+                            unsuspend_hold unused_credit ) ) {
+                $new_reason->set($_, $cgi->param("$reason_prefix$_"));
+              }
+              warn Dumper $new_reason;
+              my $error = $new_reason->insert;
+              die "error creating reason: $error" if $error;
+              $value = $new_reason->reasonnum;
             }
-
             ( $option => $value );
           }
           @{ $object->option_fields_listref };
index 9b402b0..ae1884d 100755 (executable)
@@ -159,6 +159,7 @@ if ( $opt{'cgi'} ) {
 }
 
 my $id = $opt{'id'} || $name;
+$id =~ s/\./_/g; # for edit/part_event
 
 my $add_access_right;
 if ($class eq 'C') {