X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_refund.pm;h=179151009f9546a81d57dda7d807fc816a9128ec;hb=e86b3578afbb298529e773506217cfc10e0257c4;hp=15335a421214f576c07d8b857da7514b9284aa7e;hpb=b3db3e68f602f3ca395a6bc272a4de6fef2d0895;p=freeside.git diff --git a/FS/FS/cust_refund.pm b/FS/FS/cust_refund.pm index 15335a421..179151009 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 { @@ -304,6 +306,7 @@ sub check { || $self->ut_numbern('_date') || $self->ut_textn('paybatch') || $self->ut_enum('closed', [ '', 'Y' ]) + || $self->ut_foreign_keyn('source_paynum', 'cust_pay', 'paynum') ; return $error if $error;