X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_refund.pm;fp=FS%2FFS%2Fcust_refund.pm;h=74728a60e1521e2effc5544907eff4dee6112cb9;hp=15335a421214f576c07d8b857da7514b9284aa7e;hb=fdc589c5d08623f437df749c5e43360248ccce11;hpb=159e3b1170a3011738e0937ea1b155488ee5a83c diff --git a/FS/FS/cust_refund.pm b/FS/FS/cust_refund.pm index 15335a421..74728a60e 100644 --- a/FS/FS/cust_refund.pm +++ b/FS/FS/cust_refund.pm @@ -145,19 +145,21 @@ sub insert { my $dbh = dbh; unless ($self->reasonnum) { - my $result = $self->reason( $self->getfield('reason'), - exists($options{ 'reason_type' }) - ? ('reason_type' => $options{ 'reason_type' }) - : (), - ); - unless($result) { - $dbh->rollback if $oldAutoCommit; - return "failed to set reason for $me"; #: ". $dbh->errstr; + local $@; + if ( $self->get('reason') ) { + my $reason = FS::reason->new_or_existing( + reason => $self->get('reason'), + class => 'F', + type => 'Refund reason', + ); + if ($@) { + return "failed to add refund reason: $@"; + } + $self->set('reasonnum', $reason->get('reasonnum')); + $self->set('reason', ''); } } - $self->setfield('reason', ''); - if ( $self->crednum ) { my $cust_credit = qsearchs('cust_credit', { 'crednum' => $self->crednum } ) or do {